You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by bu...@apache.org on 2016/12/16 13:48:42 UTC

[Bug 60488] New: NPE in Request.parseCookies()

https://bz.apache.org/bugzilla/show_bug.cgi?id=60488

            Bug ID: 60488
           Summary: NPE in Request.parseCookies()
           Product: Tomcat 9
           Version: unspecified
          Hardware: PC
                OS: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: Catalina
          Assignee: dev@tomcat.apache.org
          Reporter: apache@ben.eflow.org
  Target Milestone: -----

After upgrading to 8.5.9 we have a number of failing tests with this
stacktrace:

java.lang.NullPointerException
        at
org.apache.catalina.connector.Request.parseCookies(Request.java:3056)
        at
org.apache.catalina.connector.Request.convertCookies(Request.java:3076)
        at org.apache.catalina.connector.Request.addCookie(Request.java:1733)

The request is minimally populated so there are no cookies on it, however, the
parseCookies method should not fail.  This was broken by rev 1766675 on Oct 26
2016.

-- 
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


[Bug 60488] NPE in Request.parseCookies()

Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=60488

--- Comment #2 from Remy Maucherat <re...@apache.org> ---
In that kind of situation, we usually fix the mock object (TesterRequest here)
to make it more complete. But it's not failing any Tomcat test, so there's
nothing to fix here.
You should probably add your own mock object rather than rely on Tomcat's mock
objects.

-- 
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


[Bug 60488] NPE in Request.parseCookies()

Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=60488

--- Comment #5 from Ben Wolfe <ap...@ben.eflow.org> ---
Yes, we do set that too, I just neglected to copy it in:
_request.setCoyoteRequest( new org.apache.coyote.Request() );

I did make a mistake, seems its the connector that is null on that line, not
the serverCookies.

Setting a connector on the request in our test does fix this.  Is it possible
to have a null connector at this point during normal operation? If not, then we
can just chalk this up to more setup being required in testing.  

And as a sidenote: just because you don't have any tomcat tests failing does
not mean it's not a bug! :-)

-- 
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


[Bug 60488] NPE in Request.parseCookies()

Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=60488

Mark Thomas <ma...@apache.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |INVALID
             Status|NEW                         |RESOLVED

--- Comment #6 from Mark Thomas <ma...@apache.org> ---
Yes, it is expected that the Connector is non-null.

Looking at the code, we could make the connector field final and requiring it
in the constructor. We might be able to go further and require a non-null
Connector is provided. That would require refactoring a few tests but the
changes to the Tomcat code would be minimal. I'll look at this for trunk
(9.0.x). Whether I actually commit it will depend on what the refactoring ends
up looking like and if there are any side-effects I haven't spotted yet.

-- 
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


[Bug 60488] NPE in Request.parseCookies()

Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=60488

--- Comment #3 from Ben Wolfe <ap...@ben.eflow.org> ---
The test in my code does this, why should I need to generate mock objects?

_request = new Request();
Context context = new StandardContext();
context.setCookieProcessor( new LegacyCookieProcessor() );
_request.getMappingData().context = context;
_request.addCookie( new Cookie( "session_id", "s1" ) ); // NPE happens here


If I add the cookie before setting the context it passes because of null check
in convertCookies().  

If I call _request.clearCookies() before addCookie() it works because the
cookiesConverted boolean is set to true.

-- 
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


[Bug 60488] NPE in Request.parseCookies()

Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=60488

--- Comment #4 from Remy Maucherat <re...@apache.org> ---
Well, if you're using the real org.apache.catalina.connector.Request object, it
needs a non null org.apache.coyote.Request coyoteRequest field to work properly
(which then takes care of the serverCookies instance being there). Otherwise
you have to create a mock object like TesterRequest to have it work right.

-- 
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


[Bug 60488] NPE in Request.parseCookies()

Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=60488

--- Comment #1 from Ben Wolfe <ap...@ben.eflow.org> ---
Created attachment 34529
  --> https://bz.apache.org/bugzilla/attachment.cgi?id=34529&action=edit
Patch to fix NPE

See attached patch to fix this.

-- 
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org