From a19c976f7f2ef9bb295552018e9c1e6f4ef3af65 Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Thu, 16 May 2013 16:09:54 +0200 Subject: [PATCH] Avoid NPE in ContextLoader when dealing with an untyped ApplicationContextInitializer Issue: SPR-10449 --- .../springframework/web/context/ContextLoader.java | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/spring-web/src/main/java/org/springframework/web/context/ContextLoader.java b/spring-web/src/main/java/org/springframework/web/context/ContextLoader.java index 69d812da37..b7dbb399b6 100644 --- a/spring-web/src/main/java/org/springframework/web/context/ContextLoader.java +++ b/spring-web/src/main/java/org/springframework/web/context/ContextLoader.java @@ -470,7 +470,6 @@ public class ContextLoader { protected void customizeContext(ServletContext servletContext, ConfigurableWebApplicationContext applicationContext) { List>> initializerClasses = determineContextInitializerClasses(servletContext); - if (initializerClasses.size() == 0) { // no ApplicationContextInitializers have been declared -> nothing to do return; @@ -483,11 +482,13 @@ public class ContextLoader { for (Class> 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)); }