#fixed code
                                public Map<String, String> getDevices() throws Exception {

        startADB(); // start adb service
        String output = cmd.runCommand("adb devices");
        String[] lines = output.split("\n");

        if (lines.length <= 1) {
            System.out.println("No Android Device Connected");
            stopADB();
            return null;
        } else {
            for (int i = 1; i < lines.length; i++) {
                lines[i] = lines[i].replaceAll("\\s+", "");

                if (lines[i].contains("device")) {
                    lines[i] = lines[i].replaceAll("device", "");
                    String deviceID = lines[i];
                    
                    if (validDeviceIds == null 
                            || (validDeviceIds != null && validDeviceIds.contains(deviceID))) {
                        String model =
                                cmd.runCommand("adb -s " + deviceID 
                                        + " shell getprop ro.product.model")
                                .replaceAll("\\s+", "");
                        String brand =
                                cmd.runCommand("adb -s " + deviceID 
                                        + " shell getprop ro.product.brand")
                                .replaceAll("\\s+", "");
                        String osVersion = cmd.runCommand(
                                "adb -s " + deviceID + " shell getprop ro.build.version.release")
                                .replaceAll("\\s+", "");
                        String deviceName = brand + " " + model;
                        String apiLevel =
                                cmd.runCommand("adb -s " + deviceID 
                                        + " shell getprop ro.build.version.sdk")
                                .replaceAll("\n", "");

                        devices.put("deviceID" + i, deviceID);
                        devices.put("deviceName" + i, deviceName);
                        devices.put("osVersion" + i, osVersion);
                        devices.put(deviceID, apiLevel);        
                        deviceSerial.add(deviceID);
                    }
                } else if (lines[i].contains("unauthorized")) {
                    lines[i] = lines[i].replaceAll("unauthorized", "");
                    String deviceID = lines[i];
                } else if (lines[i].contains("offline")) {
                    lines[i] = lines[i].replaceAll("offline", "");
                    String deviceID = lines[i];
                }
            }
            return devices;
        }
    }
#vulnerable code 
                                public Map<String, String> getDevices() throws Exception {

        startADB(); // start adb service
        String output = cmd.runCommand("adb devices");
        String[] lines = output.split("\n");

        if (lines.length <= 1) {
            System.out.println("No Device Connected");
            stopADB();
            return null;
        } else {
            for (int i = 1; i < lines.length; i++) {
                lines[i] = lines[i].replaceAll("\\s+", "");

                if (lines[i].contains("device")) {
                    lines[i] = lines[i].replaceAll("device", "");
                    String deviceID = lines[i];
                    String model =
                        cmd.runCommand("adb -s " + deviceID + " shell getprop ro.product.model")
                            .replaceAll("\\s+", "");
                    String brand =
                        cmd.runCommand("adb -s " + deviceID + " shell getprop ro.product.brand")
                            .replaceAll("\\s+", "");
                    String osVersion = cmd.runCommand(
                        "adb -s " + deviceID + " shell getprop ro.build.version.release")
                        .replaceAll("\\s+", "");
                    String deviceName = brand + " " + model;
                    String apiLevel =
                        cmd.runCommand("adb -s " + deviceID + " shell getprop ro.build.version.sdk")
                            .replaceAll("\n", "");

                    devices.put("deviceID" + i, deviceID);
                    devices.put("deviceName" + i, deviceName);
                    devices.put("osVersion" + i, osVersion);
                    devices.put(deviceID, apiLevel);
                } else if (lines[i].contains("unauthorized")) {
                    lines[i] = lines[i].replaceAll("unauthorized", "");
                    String deviceID = lines[i];
                } else if (lines[i].contains("offline")) {
                    lines[i] = lines[i].replaceAll("offline", "");
                    String deviceID = lines[i];
                }
            }
            return devices;
        }
    } 
                            #location 22 
                            #vulnerability type RESOURCE_LEAK