Uploaded image for project: 'Spring Framework'
  1. Spring Framework
  2. SPR-8496

SpringServletContainerInitializer raises NullPointerException when no WebApplicationInitializer implementations are present

    Details

    • Type: Bug
    • Status: Closed
    • Priority: 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.

        Attachments

          Activity

            People

            • Assignee:
              cbeams Chris Beams
              Reporter:
              cbeams 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:
                6 years, 40 weeks, 3 days ago