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
Remove ClassLoader from Settings #12868
Conversation
Settings currently has a classloader member, which any user (plugin or core ES code) can access to load classes/resources. This is extremely error prone as setting the classloder on the Settings instance is a public method. Furthermore, it is not really necessary. Classes that need resources should load resources using normal means (getClass().getResourceAsStream). Those that need classes should use Class.forName, which will load the class with the same classloader as the calling class. This means, in the few places where classes are loaded by string name, they will use the appropriate loader: either the default classloader which loads core ES code, or a child classloader for each plugin. This change removes the classloader member from Settings, as well as other classloader related uses (except for a handful of cases which must use a classloader, at least for now).
assertTrue(e instanceof SettingsException); | ||
assertThat(e.getMessage(), equalTo("Failed to load settings from [" + invalidResourceName + "]")); | ||
} | ||
} |
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.
did you remove it on purpose?
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.
Yes, this was intentional. This was just checking loadFromClasspath's behavior for a non-existent resource, but loadFromClasspath is gone now.
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.
ok, sorry I got confused because this test was just added yesterday :)
There is one test which I don't understand why it got removed, but otherwise LGTM |
LGTM |
1 similar comment
LGTM |
Remove ClassLoader from Settings
Settings currently has a classloader member, which any user (plugin or core ES code) can access to load classes/resources. This is extremely error prone as setting the classloder on the Settings instance is a public method. Furthermore, it is not really necessary. Classes that need resources should load resources using normal means (getClass().getResourceAsStream). Those that need classes should use Class.forName, which will load the class with the same classloader as the calling class. This means, in the few places where classes are loaded by string name, they will use the appropriate loader: either the default classloader which loads core ES code, or a child classloader for each plugin. This change removes the classloader member from Settings, as well as other classloader related uses (except for a handful of cases which must use a classloader, at least for now). Backport of #12868
Settings currently has a classloader member, which any user (plugin
or core ES code) can access to load classes/resources. This is extremely
error prone as setting the classloder on the Settings instance is a
public method. Furthermore, it is not really necessary. Classes that
need resources should load resources using normal means
(getClass().getResourceAsStream). Those that need classes
should use Class.forName, which will load the class with the
same classloader as the calling class. This means, in the few
places where classes are loaded by string name, they will use
the appropriate loader: either the default classloader which loads
core ES code, or a child classloader for each plugin.
This change removes the classloader member from Settings, as
well as other classloader related uses (except for a handful
of cases which must use a classloader, at least for now).