Tidied up load() method to remove several static 05/97305/1
authorOleksandr Moliavko <o.moliavko@samsung.com>
Fri, 18 Oct 2019 11:13:51 +0000 (14:13 +0300)
committerOleksandr Moliavko <o.moliavko@samsung.com>
Fri, 18 Oct 2019 11:13:51 +0000 (14:13 +0300)
analyzer warnings

Issue-ID: AAF-837
Signed-off-by: Oleksandr Moliavko <o.moliavko@samsung.com>
Change-Id: I3f0f997839b5ad4ac516961be73b53d56fc1452f

auth/auth-batch/src/main/java/org/onap/aaf/auth/batch/reports/bodies/NotifyBody.java

index 04814e0..b002dd8 100644 (file)
@@ -80,7 +80,6 @@ public abstract class NotifyBody {
                 if(row.size()>3) {
                     escalation = Integer.parseInt(row.get(3));
                 }
-                return;
             } else if(type.equals(row.get(0))) {
                 String user = user(row);
                 if(user!=null) {
@@ -180,42 +179,46 @@ public abstract class NotifyBody {
         String path = pkg.getName().replace('.', '/');
         URL url = cl.getResource(path);
         List<String> classNames = new ArrayList<>();
-        String urlString = url.toString();
-        if(urlString.startsWith("jar:file:")) {
-            int exclam = urlString.lastIndexOf('!');
-            JarFile jf = new JarFile(urlString.substring(9,exclam));
-            try {
-                Enumeration<JarEntry> jfe = jf.entries();
-                while(jfe.hasMoreElements()) {
-                    String name = jfe.nextElement().getName();
-                    if(name.startsWith(path) && name.endsWith(".class")) {
-                        classNames.add(name.substring(0,name.length()-6).replace('/', '.'));
+        String urlString;
+        if (url != null) {
+            urlString = url.toString();
+            if (urlString.startsWith("jar:file:")) {
+                int exclam = urlString.lastIndexOf('!');
+                JarFile jf = new JarFile(urlString.substring(9, exclam));
+                try {
+                    Enumeration<JarEntry> jfe = jf.entries();
+                    while (jfe.hasMoreElements()) {
+                        String name = jfe.nextElement().getName();
+                        if (name.startsWith(path) && name.endsWith(".class")) {
+                            classNames.add(name.substring(0, name.length() - 6).replace('/', '.'));
+                        }
                     }
+                } finally {
+                    jf.close();
                 }
-            } finally {
-                jf.close();
-            }
-        } else {
-            File dir = new File(url.getFile());
-            for( String f : dir.list()) {
-                if(f.endsWith(".class")) {
-                    classNames.add(pkg.getName() + '.' + f.substring(0,f.length() - 6));
+            } else {
+                File dir = new File(url.getFile());
+                String[] dirs = dir.list();
+                if (dirs != null) {
+                    for (String f : dirs) {
+                        if (f.endsWith(".class")) {
+                            classNames.add(pkg.getName() + '.' + f.substring(0, f.length() - 6));
+                        }
+                    }
                 }
             }
-        }
-        for(String cls : classNames) {
-            try {
-                Class<?> c = cl.loadClass(cls);
-                if((c!=null)&&(!Modifier.isAbstract(c.getModifiers()))) {
-                       Constructor<?> cst = c.getConstructor(Access.class);
-                        NotifyBody nb = (NotifyBody)cst.newInstance(access);
-                        if(nb!=null) {
-                            bodyMap.put("info|" + nb.name, nb);
-                            bodyMap.put(nb.type+'|' + nb.name, nb);
-                          }
+            for (String cls : classNames) {
+                try {
+                    Class<?> c = cl.loadClass(cls);
+                    if ((c != null) && (!Modifier.isAbstract(c.getModifiers()))) {
+                        Constructor<?> cst = c.getConstructor(Access.class);
+                        NotifyBody nb = (NotifyBody) cst.newInstance(access);
+                        bodyMap.put("info|" + nb.name, nb);
+                        bodyMap.put(nb.type + '|' + nb.name, nb);
+                    }
+                } catch (ClassNotFoundException | NoSuchMethodException | SecurityException | InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
+                    e.printStackTrace();
                 }
-            } catch (ClassNotFoundException | NoSuchMethodException | SecurityException | InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
-                e.printStackTrace();
             }
         }
     }