Skip to content

Commit

Permalink
Fix possible NPE (#414)
Browse files Browse the repository at this point in the history
  • Loading branch information
lukehutch committed Apr 11, 2020
1 parent 7897c3e commit 2ad71a2
Showing 1 changed file with 8 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import java.net.URL;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;

Expand Down Expand Up @@ -109,7 +110,7 @@ public static void findClassLoaderOrder(final ClassLoader classLoader, final Cla
*/
private static Collection<Object> getPaths(final Object containerClassLoader) {
if (containerClassLoader == null) {
return null;
return Collections.<Object> emptyList();
}

// Expecting this to be an instance of
Expand All @@ -123,7 +124,7 @@ private static Collection<Object> getPaths(final Object containerClassLoader) {
// "getContainerURLs" didn't work, try getting the container object...
final Object container = ReflectionUtils.getFieldVal(containerClassLoader, "container", false);
if (container == null) {
return null;
return Collections.<Object> emptyList();
}

// Should be an instance of "com.ibm.wsspi.adaptable.module.Container".
Expand All @@ -136,7 +137,7 @@ private static Collection<Object> getPaths(final Object containerClassLoader) {
// "getURLs" did not work, reverting to previous logic of introspection of the "delegate".
final Object delegate = ReflectionUtils.getFieldVal(container, "delegate", false);
if (delegate == null) {
return null;
return Collections.<Object> emptyList();
}

final String path = (String) ReflectionUtils.getFieldVal(delegate, "path", false);
Expand All @@ -147,15 +148,15 @@ private static Collection<Object> getPaths(final Object containerClassLoader) {
final Object base = ReflectionUtils.getFieldVal(delegate, "base", false);
if (base == null) {
// giving up.
return null;
return Collections.<Object> emptyList();
}

final Object archiveFile = ReflectionUtils.getFieldVal(base, "archiveFile", false);
if (archiveFile != null) {
final File file = (File) archiveFile;
return Arrays.asList((Object) file.getAbsolutePath());
}
return null;
return Collections.<Object> emptyList();
}

/**
Expand Down Expand Up @@ -195,7 +196,7 @@ private static Collection<Object> callGetUrls(final Object container, final Stri
/* ignore */
}
}
return null;
return Collections.<Object> emptyList();
}

/**
Expand Down Expand Up @@ -223,7 +224,7 @@ public static void findClasspathOrder(final ClassLoader classLoader, final Class
// "com.ibm.ws.classloading.internal.ContainerClassLoader$SmartClassPath"
// interface specifies a "getClassPath" to return all urls that makeup its path.
final Collection<Object> paths = callGetUrls(smartClassPath, "getClassPath");
if (paths != null && !paths.isEmpty()) {
if (!paths.isEmpty()) {
for (final Object path : paths) {
classpathOrder.addClasspathEntry(path, classLoader, scanSpec, log);
}
Expand Down

0 comments on commit 2ad71a2

Please sign in to comment.