Skip to content
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

Closed
wants to merge 9 commits into from
3 changes: 1 addition & 2 deletions src/main/java/org/elasticsearch/plugins/PluginsService.java
Expand Up @@ -342,9 +342,8 @@ private void loadPluginsIntoClassLoader() {
return;
}

File[] pluginsFiles = pluginsFile.listFiles();
if (pluginsFile != null) {
for (File pluginFile : pluginsFiles) {
for (File pluginFile : pluginsFile.listFiles()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the below code still fails with an NPE... so maybe there is another null check for pluginsFIle.listFiles() needed?

        File pluginsFile = new File("/tmp/does-not-existing");
        if (pluginsFile != null) {
            for (File pluginFile : pluginsFile.listFiles()) {
                // NPE happens here, due to trying to iterate over null object
            }
        }

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @spinscale! Nice catch.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

provided tips too fast.. you might want to use file.isDirectory(), file.canRead() etc.. might make more sense than simple null checks :-)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@spinscale Actually, we check exists() and isDirectory() some lines before.
So I guess what you described can not happen.

The more I think about it the more I think the NPE was not what I was thinking about but as you said pluginsFile.listFile() send a NPE if the directory is not readable.

Going to add a simple file.canRead() as you suggested in place of testing for something which can not be null!

if (pluginFile.isDirectory()) {
if (logger.isTraceEnabled()) {
logger.trace("--- adding plugin [" + pluginFile.getAbsolutePath() + "]");
Expand Down