Skip to content

Commit

Permalink
fix #715 prevent NullPointerException with bootstrap classloader
Browse files Browse the repository at this point in the history
  • Loading branch information
Nowheresly committed Nov 5, 2023
1 parent c428711 commit 65619bb
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,10 @@ public void autoConfig(ClassLoader classLoader) throws JoranException {
}

private Configurator instantiateConfiguratorByClassName(String configuratorClassName, ClassLoader classLoader) {
if (classLoader == null) {
contextAware.addInfo("Instantiation failure: null ClassLoader");
return null;
}
try {
Class<?> classObj = classLoader.loadClass(configuratorClassName);
return (Configurator) classObj.getConstructor().newInstance();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,13 @@ public void autoConfigFromServiceLoaderJDK6andAbove() throws Exception {
assertSame(loggerContext, MockConfigurator.context);
}

@Test
public void autoConfigFromBootstrapClassLoader() throws Exception {
assertNull(MockConfigurator.context);
new ContextInitializer(loggerContext).autoConfig(null);
assertNull(MockConfigurator.context);
}

@Test
public void autoConfigFromServiceLoaderJDK5() throws Exception {
assumeTrue(isJDK5());
Expand Down

0 comments on commit 65619bb

Please sign in to comment.