Skip to content

Instantly share code, notes, and snippets.

@makuk66
Last active August 29, 2015 14:12
Show Gist options
  • Save makuk66/20b04e4a8e4ff682714f to your computer and use it in GitHub Desktop.
Save makuk66/20b04e4a8e4ff682714f to your computer and use it in GitHub Desktop.
fix solrResourceLoader for https://issues.apache.org/jira/browse/SOLR-6887. This patch is placed in the public domain.
diff --git a/solr/core/src/java/org/apache/solr/core/SolrResourceLoader.java b/solr/core/src/java/org/apache/solr/core/SolrResourceLoader.java
index 9cbd048..86902c4 100644
--- a/solr/core/src/java/org/apache/solr/core/SolrResourceLoader.java
+++ b/solr/core/src/java/org/apache/solr/core/SolrResourceLoader.java
@@ -175,21 +175,41 @@ public class SolrResourceLoader implements ResourceLoader,Closeable
*/
void addToClassLoader(final String baseDir, final FileFilter filter, boolean quiet) {
File base = FileUtils.resolvePath(new File(getInstanceDir()), baseDir);
- if (base != null && base.exists() && base.isDirectory()) {
- File[] files = base.listFiles(filter);
- if (files == null || files.length == 0) {
- if (!quiet) {
- log.warn("No files added to classloader from lib: "
- + baseDir + " (resolved as: " + base.getAbsolutePath() + ").");
- }
- } else {
- this.classLoader = replaceClassLoader(classLoader, base, filter);
+ if (base == null) {
+ if (!quiet) {
+ log.warn("Can not add \"" + baseDir + "\"; resolvePath relative to \"" + getInstanceDir() + "\" returned null");
}
- } else {
+ return;
+ }
+ File canonical;
+ try {
+ canonical = base.getCanonicalFile();
+ }
+ catch(IOException ioe) {
+ log.warn("Can not add \"" + baseDir + "\"; cannot obtain canonical file");
+ return;
+ }
+ base = canonical;
+ if (!base.exists()) {
if (!quiet) {
- log.warn("Can't find (or read) directory to add to classloader: "
- + baseDir + " (resolved as: " + base.getAbsolutePath() + ").");
+ log.warn("Can not add \"" + baseDir + "\": \"" + base.getAbsolutePath() + "\" does not exist");
}
+ return;
+ }
+ if (!base.isDirectory()) {
+ if (!quiet) {
+ log.warn("Can not add \"" + baseDir + "\": \"" + base.getAbsolutePath() + "\" is not a directory");
+ }
+ return;
+ }
+ File[] files = base.listFiles(filter);
+ if (files == null || files.length == 0) {
+ if (!quiet) {
+ log.warn("No files added to classloader from lib: "
+ + baseDir + " (resolved as: " + base.getAbsolutePath() + ").");
+ }
+ } else {
+ this.classLoader = replaceClassLoader(classLoader, base, filter);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment