From 57608ad74a1f91d05740dc8d06fb16bef742468f Mon Sep 17 00:00:00 2001 From: gered Date: Fri, 14 Apr 2017 17:05:41 -0400 Subject: [PATCH] fix searching of the classpath to not fail on non-existant entries e.g. things like "test" directories that may have been added to the classpath by IDE's / build tools but that may or may not actually exist --- manual-bwapi-src/ResourceList.java | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/manual-bwapi-src/ResourceList.java b/manual-bwapi-src/ResourceList.java index 80b1052..a9bac84 100644 --- a/manual-bwapi-src/ResourceList.java +++ b/manual-bwapi-src/ResourceList.java @@ -43,8 +43,7 @@ public class ResourceList { return retval; } - private static Collection getResources(final String element, - final Pattern pattern) { + private static Collection getResources(final String element, final Pattern pattern) { final ArrayList retval = new ArrayList<>(); final File file = new File(element); if (file.isDirectory()) { @@ -55,8 +54,16 @@ public class ResourceList { throw new java.lang.Error(e); } retval.addAll(getResourcesFromDirectory(file, baseDirectory, pattern)); - } else { + } else if (file.isFile()) { retval.addAll(getResourcesFromJarFile(file, pattern)); + } else { + // if 'element' did not point to an existing file or directory, we don't + // add anything to the list of resources to return + // sometimes, build tools / IDEs that start up a java process will + // specifically add classpath entries that do not point to files/directories + // that exist (e.g. Leiningen adds a 'test' directory to the classpath + // and this will be listed in 'java.class.path', whether it exists or not). + // so it is actually pretty important that we not throw an exception here! } return retval; }