Spring Framework
  1. Spring Framework
  2. SPR-8496

SpringServletContainerInitializer raises NullPointerException when no WebApplicationInitializer implementations are present

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Critical Critical
    • Resolution: Fixed
    • Affects Version/s: 3.1 M2
    • Fix Version/s: 3.1 RC1
    • Component/s: Web
    • Labels:
      None

      Description

      Per the linked forum thread:

      Caused by: java.lang.NullPointerException
      	at org.springframework.web.SpringServletContainerInitializer.onStartup(SpringServletContainerInitializer.java:142)
      	at org.apache.catalina.core.StandardContext.callServletContainerInitializers(StandardContext.java:5352)
      	... 28 more
      

      Initial analysis:

      It appears that on certain platforms e.g. Tomcat, the set of classes coming into onStartup will never be null when @HandlesType(WebApplicationInitializer.class) is specified, because the actual WAI interface is always picked up; i.e. there will always be at least one class in the set. My own testing on GlassFish suggested the same behavior, but obviously the reporter here is seeing the opposite behavior.

      Per the Javadoc for ServletContainerInitializer, the set will be null if no classes matching @HandlesType are found, and that's what we're seeing here.

      Solution:

      In any case, a null guard within SpringServletContainerInitializer doesn't hurt and certainly solves this issue.

        Activity

        Hide
        Chris Beams added a comment -

        Introduced null check to prevent NPE.

        Show
        Chris Beams added a comment - Introduced null check to prevent NPE.
        Hide
        Lars Høidahl added a comment -

        This fixed the problem. Great work!

        Show
        Lars Høidahl added a comment - This fixed the problem. Great work!
        Hide
        Qing Ye added a comment -

        Where do we get the fix? I am using 3.1.0 M2 and are seeing the same NPE on WebSphere 8.0

        Show
        Qing Ye added a comment - Where do we get the fix? I am using 3.1.0 M2 and are seeing the same NPE on WebSphere 8.0
        Hide
        Chris Beams added a comment - - edited

        Snapshot builds are available via maven.springframework.org/snapshot. For example (and assuming you use Maven):

        <repositories>
            <repository>
                <id>repository.springsource.maven.snapshot</id>
                <name>SpringSource Maven Snapshot Repository</name>
                <url>http://maven.springframework.org/snapshot</url>
            </repository>
        </repositories>
        <!-- ... -->
        <dependencies>
            <dependency>
                <groupId>org.springframework</groupId>
                <artifactId>spring-context</artifactId>
                <version>3.1.0.BUILD-SNAPSHOT</version>
            </dependency>
        <dependencies>
        
        Show
        Chris Beams added a comment - - edited Snapshot builds are available via maven.springframework.org/snapshot. For example (and assuming you use Maven): <repositories> <repository> <id>repository.springsource.maven.snapshot</id> <name>SpringSource Maven Snapshot Repository</name> <url>http: //maven.springframework.org/snapshot</url> </repository> </repositories> <!-- ... --> <dependencies> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-context</artifactId> <version>3.1.0.BUILD-SNAPSHOT</version> </dependency> <dependencies>

          People

          • Assignee:
            Chris Beams
            Reporter:
            Chris Beams
            Last updater:
            Trevor Marshall
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:
              Days since last comment:
              2 years, 34 weeks, 6 days ago