Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NullPointerException when using @CookieValue annotation [SPR-5802] #10472

Closed
spring-projects-issues opened this issue Jun 4, 2009 · 4 comments
Assignees
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) type: bug A general bug
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

Aleš Najmann opened SPR-5802 and commented

When using annotated controller such as:

@RequestMapping(value = "/auth", method = RequestMethod.POST)
public String authentication(@RequestParam("username") String username, @RequestParam("password") String password, @CookieValue(value="X-AUTH") String tokenString) {
...
}

and there is no cookie (X-AUTH) sent by client side browser, than invocation failes while mapping cookie value with NullPointerException. Here goes stacktrace:

java.lang.NullPointerException at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter$ServletHandlerMethodInvoker.resolveCookieValue(AnnotationMethodHandlerAdapter.java:629)
        at org.springframework.web.bind.annotation.support.HandlerMethodInvoker.resolveCookieValue(HandlerMethodInvoker.java:482)
        at org.springframework.web.bind.annotation.support.HandlerMethodInvoker.resolveHandlerArguments(HandlerMethodInvoker.java:259)
        at org.springframework.web.bind.annotation.support.HandlerMethodInvoker.invokeHandlerMethod(HandlerMethodInvoker.java:146)
        at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.invokeHandlerMethod(AnnotationMethodHandlerAdapter.java:354)
        at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.handle(AnnotationMethodHandlerAdapter.java:342)
        at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:763)
        at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:709)
        at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:613)
        at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:536)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
        at org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:71)
        at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)
        at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:845)
        at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
        at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
        at java.lang.Thread.run(Thread.java:619)

It happens even when defaultValue is set. I expect tokenString to be null or defaultValue (if it's set).
Solution to this problem is trivial, after I looked to source code, but let me introduce more advanced idea.
It would be great if anotated @CookieValue argument could be of any user type and should be resolved through registered property editors such as arguments with @RequestParam are.


Affects: 3.0 M3

Referenced from: commits 541aae1, 1dc346a

@spring-projects-issues
Copy link
Collaborator Author

Arjen Poutsma commented

Added formatting.

@spring-projects-issues
Copy link
Collaborator Author

Arjen Poutsma commented

Fixed the NPE bug.

Feel free to open a new issue for the feature request of using PropertyEditors for CookieValue conversion.

@spring-projects-issues
Copy link
Collaborator Author

Mike Bingham commented

The NPE bug still exists in RC2 in the portlet version of AnnotationMethodHandlerAdapter.resolveCookieValue().

@spring-projects-issues
Copy link
Collaborator Author

Arjen Poutsma commented

Fixed in Portlet environment too

@spring-projects-issues spring-projects-issues added type: bug A general bug in: web Issues in web modules (web, webmvc, webflux, websocket) labels Jan 11, 2019
@spring-projects-issues spring-projects-issues added this to the 3.0 RC3 milestone Jan 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) type: bug A general bug
Projects
None yet
Development

No branches or pull requests

2 participants