Source:
private List<String> computeKarafFeatureList() { Set<String> featureSet = new HashSet<>(); File etcDir = new File(new File(System.getProperty("opennms.home")), "etc"); File featuresBootDotDDir = new File(etcDir, "featuresBoot.d"); File featuresCfgFile = new File(etcDir, "org.apache.karaf.features.cfg"); Properties featuresProp = new Properties(); try (FileInputStream fis = new FileInputStream(featuresCfgFile)) { featuresProp.load(fis); String bootProp = featuresProp.getProperty("featuresBoot"); if (bootProp != null) { for (String propName : bootProp.split(",")) { if (propName.startsWith("(") && propName.length() > 1) { propName = propName.substring(1); } if (propName.endsWith(")") && propName.length() > 1) { propName = propName.substring(0, propName.length() - 2); } featureSet.add(propName.trim()); } } } catch (IOException e) { LOG.error("Encountered IOException while loading Karaf features config. Features list will be empty."); } for (File featureDotDFile : featuresBootDotDDir.listFiles()) { if (featureDotDFile.isDirectory() || featureDotDFile.getName().startsWith(".")) { continue; } try (BufferedReader br = new BufferedReader(new FileReader(featureDotDFile))) { String line = br.readLine(); while (line != null) { if (line.matches("^\\s*#.*")) { line = br.readLine(); continue; } String lineBody = line.trim(); if (lineBody.startsWith("!") && lineBody.length() > 1) { String removeFeature = lineBody.substring(1).trim(); featureSet.remove(removeFeature); } else { featureSet.add(lineBody); } line = br.readLine(); } } catch (IOException e) { LOG.error("Encountered IOException while loading Karaf featuresBoot.d directory contents. Feature list may be inaccurate."); } } List<String> featureList = new ArrayList<>(featureSet); Collections.sort(featureList); return featureList; }

Target:
private List<String> computeKarafFeatureList() { Set<String> featureSet = new HashSet<>(); File etcDir = new File(new File(System.getProperty("opennms.home")), "etc"); File featuresBootDotDDir = new File(etcDir, "featuresBoot.d"); File featuresCfgFile = new File(etcDir, "org.apache.karaf.features.cfg"); Properties featuresProp = new Properties(); if (!featuresCfgFile.canRead()) { LOG.error("Features config file does not exist or is not readable. Returning empty feature list.", featuresCfgFile.getAbsolutePath()); return Collections.emptyList(); } try (FileInputStream fis = new FileInputStream(featuresCfgFile)) { featuresProp.load(fis); String bootProp = featuresProp.getProperty("featuresBoot"); if (bootProp != null) { for (String propName : bootProp.split(",")) { if (propName.startsWith("(") && propName.length() > 1) { propName = propName.substring(1); } if (propName.endsWith(")") && propName.length() > 1) { propName = propName.substring(0, propName.length() - 2); } featureSet.add(propName.trim()); } } } catch (IOException e) { LOG.error("Encountered IOException while loading Karaf features. Features list will be empty."); } try { for (Feature feature: m_extender.getFeaturesBoot()) { featureSet.add(feature.getName()); } } catch (IOException e1) { LOG.error("Encountered IOException while loading Karaf featuresBoot.d directory contents. Feature list may be inaccurate."); } List<String> featureList = new ArrayList<>(featureSet); Collections.sort(featureList); return featureList; }