NullPointerException on statrup - possible bug in Tomcat

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

NullPointerException on statrup - possible bug in Tomcat

tomcat-subs
I have a web application which is failing in RestEasy initialization with an NPE. It worked for many years until I added a large number of jar dependencies because of a new development effort. I've debugged the code by stepping through the Tomcat source to the point I've found where it is failing. It seems to be a Tomcat bug but of course I'm not convinced since it is highly more likely it is my problem.

Tomcat version is 9.0.36, though the failure happens in the Tomcat 8 versions I've tried as well.

The NPE is triggered by a single "return null" statement in org.apache.catalina.core.ApplicationContext line 933. Below is a code snippet of where the return statement is. In my failing scenario the wrapper is NOT null and isOverridable is already returning false. So it falls through to return null.

So here is my question: Why in the world in the code below does the return null statement even exist? It seems like the return null at line 933 is the precondition the code is trying to establish.

//code from 'org.apache.catalina.core.ApplicationContext'
        Wrapper wrapper = (Wrapper) context.findChild(servletName);

        // Assume a 'complete' ServletRegistration is one that has a class and
        // a name
        if (wrapper == null) {
            wrapper = context.createWrapper();
            wrapper.setName(servletName);
            context.addChild(wrapper);
        } else {
            if (wrapper.getName() != null &&
                    wrapper.getServletClass() != null) {
                if (wrapper.isOverridable()) {
                    wrapper.setOverridable(false);
                } else {
                    return null; // Line 933
                }
            }
        }

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: NullPointerException on statrup - possible bug in Tomcat

Konstantin Kolinko
ср, 24 июн. 2020 г. в 19:25, <[hidden email]>:
>
> I have a web application which is failing in RestEasy initialization with an NPE. It worked for many years until I added a large number of jar dependencies because of a new development effort. I've debugged the code by stepping through the Tomcat source to the point I've found where it is failing. It seems to be a Tomcat bug but of course I'm not convinced since it is highly more likely it is my problem.
>
> Tomcat version is 9.0.36, though the failure happens in the Tomcat 8 versions I've tried as well.
>
> The NPE is triggered by a single "return null" statement in org.apache.catalina.core.ApplicationContext line 933. Below is a code snippet of where the return statement is. In my failing scenario the wrapper is NOT null and isOverridable is already returning false. So it falls through to return null.
>
> So here is my question: Why in the world in the code below does the return null statement even exist? It seems like the return null at line 933 is the precondition the code is trying to establish.

This method is documented in the specification of Servlet API (in
their javadoc) to return null if such servlet has already been
registered.
See Java EE 8 javadoc
https://javaee.github.io/javaee-spec/javadocs/javax/servlet/ServletContext.html#addServlet-java.lang.String-java.lang.Class-

(Following the links from Specifications page
https://cwiki.apache.org/confluence/display/TOMCAT/Specifications

K.Kolinko

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: NullPointerException on statrup - possible bug in Tomcat

markt
In reply to this post by tomcat-subs
On 24/06/2020 17:25, [hidden email] wrote:
> I have a web application which is failing in RestEasy initialization with an NPE. It worked for many years until I added a large number of jar dependencies because of a new development effort. I've debugged the code by stepping through the Tomcat source to the point I've found where it is failing. It seems to be a Tomcat bug but of course I'm not convinced since it is highly more likely it is my problem.
>
> Tomcat version is 9.0.36, though the failure happens in the Tomcat 8 versions I've tried as well.
>
> The NPE is triggered by a single "return null" statement in org.apache.catalina.core.ApplicationContext line 933. Below is a code snippet of where the return statement is. In my failing scenario the wrapper is NOT null and isOverridable is already returning false. So it falls through to return null.
>
> So here is my question: Why in the world in the code below does the return null statement even exist?

Because the Servlet API methods it supports are documented to return
null if:

<quote>
...this ServletContext already contains a complete ServletRegistration
for the given servletName
</quote>

Mark

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: NullPointerException on statrup - possible bug in Tomcat

tomcat-subs
In reply to this post by Konstantin Kolinko
Problem resolved. Thank you.

On Wed, Jun 24, 2020, at 12:46 PM, Konstantin Kolinko wrote:

> ср, 24 июн. 2020 г. в 19:25, <[hidden email]>:
> >
> > I have a web application which is failing in RestEasy initialization with an NPE. It worked for many years until I added a large number of jar dependencies because of a new development effort. I've debugged the code by stepping through the Tomcat source to the point I've found where it is failing. It seems to be a Tomcat bug but of course I'm not convinced since it is highly more likely it is my problem.
> >
> > Tomcat version is 9.0.36, though the failure happens in the Tomcat 8 versions I've tried as well.
> >
> > The NPE is triggered by a single "return null" statement in org.apache.catalina.core.ApplicationContext line 933. Below is a code snippet of where the return statement is. In my failing scenario the wrapper is NOT null and isOverridable is already returning false. So it falls through to return null.
> >
> > So here is my question: Why in the world in the code below does the return null statement even exist? It seems like the return null at line 933 is the precondition the code is trying to establish.
>
> This method is documented in the specification of Servlet API (in
> their javadoc) to return null if such servlet has already been
> registered.
> See Java EE 8 javadoc
> https://javaee.github.io/javaee-spec/javadocs/javax/servlet/ServletContext.html#addServlet-java.lang.String-java.lang.Class-
>
> (Following the links from Specifications page
> https://cwiki.apache.org/confluence/display/TOMCAT/Specifications
>
> K.Kolinko
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]