PDA

View Full Version : @PathVariable Issue -- java.lang.IllegalStateException



dave77
Apr 12th, 2012, 01:11 PM
Thanks in advance for any help. This has me confused as I've used the same technique for defining @PathVariable all over my application with no issues.

I have a controller method with the following signature:


@Controller
@RequestMapping("_n/thingy")
@Transactional
public class MyThingyController {

@RequestMapping(value="/{id:\\d+}", method=RequestMethod.GET)
public String getThingy(@PathVariable("id") Integer thingyId, Model model) {
//DO STUFF
}

}

But, I get the following exception:


java.lang.IllegalStateException: Optional int parameter 'thingId' is not present but cannot be translated into a null value due to being declared as a primitive type. Consider declaring it as object wrapper for the corresponding primitive type.
at org.springframework.web.bind.annotation.support.Ha ndlerMethodInvoker.checkValue(HandlerMethodInvoker .java:742)
at org.springframework.web.bind.annotation.support.Ha ndlerMethodInvoker.resolveRequestParam(HandlerMeth odInvoker.java:511)
at org.springframework.web.bind.annotation.support.Ha ndlerMethodInvoker.resolveHandlerArguments(Handler MethodInvoker.java:348)
at org.springframework.web.bind.annotation.support.Ha ndlerMethodInvoker.invokeHandlerMethod(HandlerMeth odInvoker.java:153)
at org.springframework.web.servlet.mvc.annotation.Ann otationMethodHandlerAdapter.invokeHandlerMethod(An notationMethodHandlerAdapter.java:436)
at org.springframework.web.servlet.mvc.annotation.Ann otationMethodHandlerAdapter.handle(AnnotationMetho dHandlerAdapter.java:424)
at org.springframework.web.servlet.DispatcherServlet. doDispatch(DispatcherServlet.java:923)
at org.springframework.web.servlet.DispatcherServlet. doService(DispatcherServlet.java:852)
at org.springframework.web.servlet.FrameworkServlet.p rocessRequest(FrameworkServlet.java:882)
at org.springframework.web.servlet.FrameworkServlet.d oGet(FrameworkServlet.java:778)
at javax.servlet.http.HttpServlet.service(HttpServlet .java:621)
at javax.servlet.http.HttpServlet.service(HttpServlet .java:722)
at org.apache.catalina.core.ApplicationFilterChain.in ternalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.do Filter(ApplicationFilterChain.java:210)
at org.springframework.security.web.FilterChainProxy$ VirtualFilterChain.doFilter(FilterChainProxy.java: 369)
at org.springframework.security.web.access.intercept. FilterSecurityInterceptor.invoke(FilterSecurityInt erceptor.java:109)
at org.springframework.security.web.access.intercept. FilterSecurityInterceptor.doFilter(FilterSecurityI nterceptor.java:83)
at org.springframework.security.web.FilterChainProxy$ VirtualFilterChain.doFilter(FilterChainProxy.java: 381)
at org.springframework.security.web.access.ExceptionT ranslationFilter.doFilter(ExceptionTranslationFilt er.java:97)
at org.springframework.security.web.FilterChainProxy$ VirtualFilterChain.doFilter(FilterChainProxy.java: 381)
at org.springframework.security.web.session.SessionMa nagementFilter.doFilter(SessionManagementFilter.ja va:100)
at org.springframework.security.web.FilterChainProxy$ VirtualFilterChain.doFilter(FilterChainProxy.java: 381)
at org.springframework.security.web.authentication.An onymousAuthenticationFilter.doFilter(AnonymousAuth enticationFilter.java:78)
at org.springframework.security.web.FilterChainProxy$ VirtualFilterChain.doFilter(FilterChainProxy.java: 381)
at org.springframework.security.web.servletapi.Securi tyContextHolderAwareRequestFilter.doFilter(Securit yContextHolderAwareRequestFilter.java:54)
at org.springframework.security.web.FilterChainProxy$ VirtualFilterChain.doFilter(FilterChainProxy.java: 381)
at org.springframework.security.web.savedrequest.Requ estCacheAwareFilter.doFilter(RequestCacheAwareFilt er.java:35)
at org.springframework.security.web.FilterChainProxy$ VirtualFilterChain.doFilter(FilterChainProxy.java: 381)
at org.springframework.security.web.authentication.ww w.BasicAuthenticationFilter.doFilter(BasicAuthenti cationFilter.java:177)
at org.springframework.security.web.FilterChainProxy$ VirtualFilterChain.doFilter(FilterChainProxy.java: 381)
at org.springframework.security.web.authentication.Ab stractAuthenticationProcessingFilter.doFilter(Abst ractAuthenticationProcessingFilter.java:187)
at org.springframework.security.web.FilterChainProxy$ VirtualFilterChain.doFilter(FilterChainProxy.java: 381)
at org.springframework.security.web.authentication.lo gout.LogoutFilter.doFilter(LogoutFilter.java:105)
at org.springframework.security.web.FilterChainProxy$ VirtualFilterChain.doFilter(FilterChainProxy.java: 381)
at org.springframework.security.web.context.SecurityC ontextPersistenceFilter.doFilter(SecurityContextPe rsistenceFilter.java:79)
at org.springframework.security.web.FilterChainProxy$ VirtualFilterChain.doFilter(FilterChainProxy.java: 381)
at org.springframework.security.web.FilterChainProxy. doFilter(FilterChainProxy.java:168)
at org.springframework.web.filter.DelegatingFilterPro xy.invokeDelegate(DelegatingFilterProxy.java:346)
at org.springframework.web.filter.DelegatingFilterPro xy.doFilter(DelegatingFilterProxy.java:259)
at org.apache.catalina.core.ApplicationFilterChain.in ternalDoFilter(ApplicationFilterChain.java:243)
at org.apache.catalina.core.ApplicationFilterChain.do Filter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invo ke(StandardWrapperValve.java:224)
at org.apache.catalina.core.StandardContextValve.invo ke(StandardContextValve.java:169)
at org.apache.catalina.authenticator.AuthenticatorBas e.invoke(AuthenticatorBase.java:472)
at org.apache.catalina.core.StandardHostValve.invoke( StandardHostValve.java:168)
at org.apache.catalina.valves.ErrorReportValve.invoke (ErrorReportValve.java:98)
at org.apache.catalina.valves.AccessLogValve.invoke(A ccessLogValve.java:927)
at org.apache.catalina.core.StandardEngineValve.invok e(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.servic e(CoyoteAdapter.java:407)
at org.apache.coyote.http11.AbstractHttp11Processor.p rocess(AbstractHttp11Processor.java:987)
at org.apache.coyote.AbstractProtocol$AbstractConnect ionHandler.process(AbstractProtocol.java:579)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProce ssor.run(JIoEndpoint.java:307)
at java.util.concurrent.ThreadPoolExecutor.runWorker( Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run (Unknown Source)
at java.lang.Thread.run(Unknown Source)

Clearly, I'm not declaring "id" as a primitive type, but as an Integer. What gives? Could it be that the "id" value I'm passing is fairly large (for example: 65366)

I can provide more code from the application if it helps. I'm just hoping that someone else can make more sense of the stacktrace.

Thanks!

Marten Deinum
Apr 13th, 2012, 01:16 AM
Well actually you might be using ints and it might be due to the fact that you use regular expressions in your url pattern. Try without the regular expression.

dave77
Apr 13th, 2012, 08:15 AM
Thanks for the suggestion.

Ends up my controller had another method that was annotated with @ModelAttribute . That method did have an int argument named the same as the method I thought was the problem. Looks like I didn't have the issue whittled down to the correct method after all. :rolleyes: (Lesson learned!)

Thanks,
-dave77