New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
NPE in PluginsService when starting elasticsearch with a wrong user #5196
Changes from 5 commits
ff7184f
5564173
7adf99e
6b4edcc
d606bee
00d9a71
10f8514
97bf18b
2850504
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,6 +30,7 @@ | |
import org.elasticsearch.common.component.AbstractComponent; | ||
import org.elasticsearch.common.component.LifecycleComponent; | ||
import org.elasticsearch.common.inject.Module; | ||
import org.elasticsearch.common.io.FileSystemUtils; | ||
import org.elasticsearch.common.settings.ImmutableSettings; | ||
import org.elasticsearch.common.settings.Settings; | ||
import org.elasticsearch.common.unit.TimeValue; | ||
|
@@ -316,11 +317,8 @@ synchronized public PluginsInfo info() { | |
} | ||
|
||
private void loadPluginsIntoClassLoader() { | ||
File pluginsFile = environment.pluginsFile(); | ||
if (!pluginsFile.exists()) { | ||
return; | ||
} | ||
if (!pluginsFile.isDirectory()) { | ||
File pluginsDirectory = environment.pluginsFile(); | ||
if (!FileSystemUtils.isAccessibleDirectory(pluginsDirectory, logger)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. static import? |
||
return; | ||
} | ||
|
||
|
@@ -342,40 +340,39 @@ private void loadPluginsIntoClassLoader() { | |
return; | ||
} | ||
|
||
File[] pluginsFiles = pluginsFile.listFiles(); | ||
if (pluginsFile != null) { | ||
for (File pluginFile : pluginsFiles) { | ||
if (pluginFile.isDirectory()) { | ||
if (logger.isTraceEnabled()) { | ||
logger.trace("--- adding plugin [" + pluginFile.getAbsolutePath() + "]"); | ||
} | ||
try { | ||
// add the root | ||
addURL.invoke(classLoader, pluginFile.toURI().toURL()); | ||
// gather files to add | ||
List<File> libFiles = Lists.newArrayList(); | ||
if (pluginFile.listFiles() != null) { | ||
libFiles.addAll(Arrays.asList(pluginFile.listFiles())); | ||
} | ||
File libLocation = new File(pluginFile, "lib"); | ||
if (libLocation.exists() && libLocation.isDirectory() && libLocation.listFiles() != null) { | ||
libFiles.addAll(Arrays.asList(libLocation.listFiles())); | ||
} | ||
for (File plugin : pluginsDirectory.listFiles()) { | ||
// We check that subdirs are directories and readable | ||
if (!FileSystemUtils.isAccessibleDirectory(plugin, logger)) { | ||
continue; | ||
} | ||
|
||
// if there are jars in it, add it as well | ||
for (File libFile : libFiles) { | ||
if (!(libFile.getName().endsWith(".jar") || libFile.getName().endsWith(".zip"))) { | ||
continue; | ||
} | ||
addURL.invoke(classLoader, libFile.toURI().toURL()); | ||
} | ||
} catch (Throwable e) { | ||
logger.warn("failed to add plugin [" + pluginFile + "]", e); | ||
if (logger.isTraceEnabled()) { | ||
logger.trace("--- adding plugin [{}]", plugin.getAbsolutePath()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think you can remove the if statement now? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why? You don't want to trace that we are actually adding a new plugin? It could help I think. |
||
} | ||
|
||
try { | ||
// add the root | ||
addURL.invoke(classLoader, plugin.toURI().toURL()); | ||
// gather files to add | ||
List<File> libFiles = Lists.newArrayList(); | ||
if (plugin.listFiles() != null) { | ||
libFiles.addAll(Arrays.asList(plugin.listFiles())); | ||
} | ||
File libLocation = new File(plugin, "lib"); | ||
if (libLocation.exists() && libLocation.isDirectory() && libLocation.listFiles() != null) { | ||
libFiles.addAll(Arrays.asList(libLocation.listFiles())); | ||
} | ||
|
||
// if there are jars in it, add it as well | ||
for (File libFile : libFiles) { | ||
if (!(libFile.getName().endsWith(".jar") || libFile.getName().endsWith(".zip"))) { | ||
continue; | ||
} | ||
addURL.invoke(classLoader, libFile.toURI().toURL()); | ||
} | ||
} catch (Throwable e) { | ||
logger.warn("failed to add plugin [" + plugin + "]", e); | ||
} | ||
} else { | ||
logger.debug("failed to list plugins from {}. Check your right access.", pluginsFile.getAbsolutePath()); | ||
} | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is more generic now, not plugins anymore... same for the lines below
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed! :)