You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by to...@stiprus.com on 2020/06/24 16:25:07 UTC

NullPointerException on statrup - possible bug in Tomcat

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: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: NullPointerException on statrup - possible bug in Tomcat

Posted by to...@stiprus.com.
Problem resolved. Thank you.

On Wed, Jun 24, 2020, at 12:46 PM, Konstantin Kolinko wrote:
> ср, 24 июн. 2020 г. в 19:25, <to...@stiprus.com>:
> >
> > 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: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
> 
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: NullPointerException on statrup - possible bug in Tomcat

Posted by Konstantin Kolinko <kn...@gmail.com>.
ср, 24 июн. 2020 г. в 19:25, <to...@stiprus.com>:
>
> 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: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: NullPointerException on statrup - possible bug in Tomcat

Posted by Mark Thomas <ma...@apache.org>.
On 24/06/2020 17:25, tomcat-subs@stiprus.com 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: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org