From 3a9d138300642c3d09c8dc4bdc3f7413abfd584a Mon Sep 17 00:00:00 2001 From: Oleksandr Moliavko Date: Fri, 18 Oct 2019 14:13:51 +0300 Subject: [PATCH] Tidied up load() method to remove several static analyzer warnings Issue-ID: AAF-837 Signed-off-by: Oleksandr Moliavko Change-Id: I3f0f997839b5ad4ac516961be73b53d56fc1452f --- .../aaf/auth/batch/reports/bodies/NotifyBody.java | 67 +++++++++++----------- 1 file changed, 35 insertions(+), 32 deletions(-) diff --git a/auth/auth-batch/src/main/java/org/onap/aaf/auth/batch/reports/bodies/NotifyBody.java b/auth/auth-batch/src/main/java/org/onap/aaf/auth/batch/reports/bodies/NotifyBody.java index 04814e01..b002dd8b 100644 --- a/auth/auth-batch/src/main/java/org/onap/aaf/auth/batch/reports/bodies/NotifyBody.java +++ b/auth/auth-batch/src/main/java/org/onap/aaf/auth/batch/reports/bodies/NotifyBody.java @@ -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 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 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 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(); } } } -- 2.16.6