Browse Source

Avoid NPE in ContextLoader when dealing with an untyped ApplicationContextInitializer

Issue: SPR-10449
pull/292/head
Juergen Hoeller 12 years ago
parent
commit
a19c976f7f
  1. 13
      spring-web/src/main/java/org/springframework/web/context/ContextLoader.java

13
spring-web/src/main/java/org/springframework/web/context/ContextLoader.java

@ -470,7 +470,6 @@ public class ContextLoader { @@ -470,7 +470,6 @@ public class ContextLoader {
protected void customizeContext(ServletContext servletContext, ConfigurableWebApplicationContext applicationContext) {
List<Class<ApplicationContextInitializer<ConfigurableApplicationContext>>> initializerClasses =
determineContextInitializerClasses(servletContext);
if (initializerClasses.size() == 0) {
// no ApplicationContextInitializers have been declared -> nothing to do
return;
@ -483,11 +482,13 @@ public class ContextLoader { @@ -483,11 +482,13 @@ public class ContextLoader {
for (Class<ApplicationContextInitializer<ConfigurableApplicationContext>> initializerClass : initializerClasses) {
Class<?> initializerContextClass =
GenericTypeResolver.resolveTypeArgument(initializerClass, ApplicationContextInitializer.class);
Assert.isAssignable(initializerContextClass, contextClass, String.format(
"Could not add context initializer [%s] as its generic parameter [%s] " +
"is not assignable from the type of application context used by this " +
"context loader [%s]: ", initializerClass.getName(), initializerContextClass.getName(),
contextClass.getName()));
if (initializerContextClass != null) {
Assert.isAssignable(initializerContextClass, contextClass, String.format(
"Could not add context initializer [%s] as its generic parameter [%s] " +
"is not assignable from the type of application context used by this " +
"context loader [%s]: ", initializerClass.getName(), initializerContextClass.getName(),
contextClass.getName()));
}
initializerInstances.add(BeanUtils.instantiateClass(initializerClass));
}

Loading…
Cancel
Save