From fa3ccb97113f6fefe0dc6ff083f1d6b48eb7aac2 Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Sat, 27 Dec 2014 14:04:10 -0800 Subject: [PATCH] GUAC-969: Fix possible NPE in GuacamoleClassLoader, if the contents of the lib directory cannot be listed. --- .../guacamole/net/basic/GuacamoleClassLoader.java | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/guacamole/src/main/java/org/glyptodon/guacamole/net/basic/GuacamoleClassLoader.java b/guacamole/src/main/java/org/glyptodon/guacamole/net/basic/GuacamoleClassLoader.java index d499fc1ac..218d01396 100644 --- a/guacamole/src/main/java/org/glyptodon/guacamole/net/basic/GuacamoleClassLoader.java +++ b/guacamole/src/main/java/org/glyptodon/guacamole/net/basic/GuacamoleClassLoader.java @@ -105,7 +105,7 @@ public class GuacamoleClassLoader extends ClassLoader { // Get list of URLs for all .jar's in the lib directory Collection jarURLs = new ArrayList(); - for (File file : libDirectory.listFiles(new FilenameFilter() { + File[] files = libDirectory.listFiles(new FilenameFilter() { @Override public boolean accept(File dir, String name) { @@ -115,13 +115,17 @@ public class GuacamoleClassLoader extends ClassLoader { } - })) { + }); + + // Verify directory was successfully read + if (files == null) + throw new GuacamoleException("Unable to read contents of directory " + libDirectory); + + // Add the URL for each .jar to the jar URL list + for (File file : files) { try { - - // Add URL for the .jar to the jar URL list jarURLs.add(file.toURI().toURL()); - } catch (MalformedURLException e) { throw new GuacamoleException(e);