diff --git a/framework/base/src/main/java/org/apache/ofbiz/base/container/ComponentContainer.java b/framework/base/src/main/java/org/apache/ofbiz/base/container/ComponentContainer.java index b533c3de9a..0f95381c79 100644 --- a/framework/base/src/main/java/org/apache/ofbiz/base/container/ComponentContainer.java +++ b/framework/base/src/main/java/org/apache/ofbiz/base/container/ComponentContainer.java @@ -53,7 +53,7 @@ public class ComponentContainer implements Container { private String name; private final AtomicBoolean loaded = new AtomicBoolean(false); - private final List componentsClassPath = new ArrayList(); + private final List componentsClassPath = new ArrayList<>(); @Override public void init(List ofbizCommands, String name, String configFile) throws ContainerException { @@ -89,7 +89,7 @@ public class ComponentContainer implements Container { * @throws ContainerException */ private void loadClassPathForAllComponents(List componentsClassPath) throws ContainerException { - List allComponentUrls = new ArrayList(); + List allComponentUrls = new ArrayList<>(); for(Classpath classPath : componentsClassPath) { try { allComponentUrls.addAll(Arrays.asList(classPath.getUrls())); @@ -137,7 +137,7 @@ public class ComponentContainer implements Container { File directoryPath = FileUtil.getFile(directoryName); if (directoryPath.exists() && directoryPath.isDirectory()) { File componentLoadFile = new File(directoryPath, ComponentLoaderConfig.COMPONENT_LOAD_XML_FILENAME); - if (componentLoadFile != null && componentLoadFile.exists()) { + if (componentLoadFile.exists()) { loadComponentsInDirectoryUsingLoadFile(directoryPath, componentLoadFile); } else { loadComponentsInDirectory(directoryPath); @@ -162,10 +162,8 @@ public class ComponentContainer implements Container { try { configUrl = componentLoadFile.toURI().toURL(); List componentsToLoad = ComponentLoaderConfig.getComponentsFromConfig(configUrl); - if (componentsToLoad != null) { - for (ComponentLoaderConfig.ComponentDef def: componentsToLoad) { - loadComponentFromConfig(directoryPath.toString(), def); - } + for (ComponentLoaderConfig.ComponentDef def: componentsToLoad) { + loadComponentFromConfig(directoryPath.toString(), def); } } catch (MalformedURLException e) { Debug.logError(e, "Unable to locate URL for component loading file: " + componentLoadFile.getAbsolutePath(), module); @@ -184,6 +182,9 @@ public class ComponentContainer implements Container { */ private void loadComponentsInDirectory(File directoryPath) throws IOException { String[] sortedComponentNames = directoryPath.list(); + if (sortedComponentNames == null) { + throw new IllegalArgumentException("sortedComponentNames is null, directory path is invalid " + directoryPath.getPath()); + } Arrays.sort(sortedComponentNames); for (String componentName: sortedComponentNames) { diff --git a/framework/base/src/main/java/org/apache/ofbiz/base/container/ContainerConfig.java b/framework/base/src/main/java/org/apache/ofbiz/base/container/ContainerConfig.java index 9c08452fa3..349536bc85 100644 --- a/framework/base/src/main/java/org/apache/ofbiz/base/container/ContainerConfig.java +++ b/framework/base/src/main/java/org/apache/ofbiz/base/container/ContainerConfig.java @@ -47,7 +47,7 @@ public class ContainerConfig { public static final String module = ContainerConfig.class.getName(); - private static Map configurations = new LinkedHashMap(); + private static Map configurations = new LinkedHashMap<>(); public static Configuration getConfiguration(String containerName, String configFile) throws ContainerException { Configuration configuration = configurations.get(containerName); @@ -89,23 +89,19 @@ public class ContainerConfig { ContainerConfig.Configuration.Property prop = parentProp.getProperty(name); if (prop == null || UtilValidate.isEmpty(prop.value)) { return defaultValue; - } else { - return prop.value; } + return prop.value; } public static int getPropertyValue(ContainerConfig.Configuration parentProp, String name, int defaultValue) { ContainerConfig.Configuration.Property prop = parentProp.getProperty(name); if (prop == null || UtilValidate.isEmpty(prop.value)) { return defaultValue; - } else { - int num = defaultValue; - try { - num = Integer.parseInt(prop.value); - } catch (Exception e) { - return defaultValue; - } - return num; + } + try { + return Integer.parseInt(prop.value); + } catch (Exception e) { + return defaultValue; } } @@ -113,32 +109,27 @@ public class ContainerConfig { ContainerConfig.Configuration.Property prop = parentProp.getProperty(name); if (prop == null || UtilValidate.isEmpty(prop.value)) { return defaultValue; - } else { - return "true".equalsIgnoreCase(prop.value); } + return "true".equalsIgnoreCase(prop.value); } public static String getPropertyValue(ContainerConfig.Configuration.Property parentProp, String name, String defaultValue) { ContainerConfig.Configuration.Property prop = parentProp.getProperty(name); if (prop == null || UtilValidate.isEmpty(prop.value)) { return defaultValue; - } else { - return prop.value; } + return prop.value; } public static int getPropertyValue(ContainerConfig.Configuration.Property parentProp, String name, int defaultValue) { ContainerConfig.Configuration.Property prop = parentProp.getProperty(name); if (prop == null || UtilValidate.isEmpty(prop.value)) { return defaultValue; - } else { - int num = defaultValue; - try { - num = Integer.parseInt(prop.value); - } catch (Exception e) { - return defaultValue; - } - return num; + } + try { + return Integer.parseInt(prop.value); + } catch (Exception e) { + return defaultValue; } } @@ -146,9 +137,8 @@ public class ContainerConfig { ContainerConfig.Configuration.Property prop = parentProp.getProperty(name); if (prop == null || UtilValidate.isEmpty(prop.value)) { return defaultValue; - } else { - return "true".equalsIgnoreCase(prop.value); } + return "true".equalsIgnoreCase(prop.value); } private static Collection getConfigurationPropsFromXml(URL xmlUrl) throws ContainerException { @@ -159,7 +149,7 @@ public class ContainerConfig { throw new ContainerException("Error reading the container config file: " + xmlUrl, e); } Element root = containerDocument.getDocumentElement(); - List result = new ArrayList(); + List result = new ArrayList<>(); for (Element curElement: UtilXml.childElementList(root, "container")) { result.add(new Configuration(curElement)); } @@ -177,7 +167,7 @@ public class ContainerConfig { this.className = element.getAttribute("class"); this.loaders = StringUtil.split(element.getAttribute("loaders"), ","); - properties = new LinkedHashMap(); + properties = new LinkedHashMap<>(); for (Element curElement: UtilXml.childElementList(element, "property")) { Property property = new Property(curElement); properties.put(property.name, property); @@ -189,7 +179,7 @@ public class ContainerConfig { } public List getPropertiesWithValue(String value) { - List props = new LinkedList(); + List props = new LinkedList<>(); if (UtilValidate.isNotEmpty(properties)) { for (Property p: properties.values()) { if (p != null && value.equals(p.value)) { @@ -212,7 +202,7 @@ public class ContainerConfig { this.value = UtilXml.childElementValue(element, "property-value"); } - properties = new LinkedHashMap(); + properties = new LinkedHashMap<>(); for (Element curElement: UtilXml.childElementList(element, "property")) { Property property = new Property(curElement); properties.put(property.name, property); @@ -224,7 +214,7 @@ public class ContainerConfig { } public List getPropertiesWithValue(String value) { - List props = new LinkedList(); + List props = new LinkedList<>(); if (UtilValidate.isNotEmpty(properties)) { for (Property p: properties.values()) { if (p != null && value.equals(p.value)) {