Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NullPointerException in Spring Framework (or what?)

I have run into a very weird problem, and I have simply no idea, where to start. In our working application, one of our pages seems to fail kinda arbitrarily - that is, sometimes it works, and sometimes it doesn't.

The web application is running Java 6, Spring 2.5.6 and Hibernate 3.2.6. Furthermore, we are using Javax.servlet version 3.0 (might be relavant).

The problem becomes hard, because of a very limited stacktrace, which doesn't seem to involve any of our custom code (all our classes start with com.isworld.*).
The error occurs AFTER loading the page, when the form is submitted and the request is beeing processed. See stacktrace below:

org.springframework.web.util.NestedServletException: Request processing failed; nested exception is java.lang.NullPointerException
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:583)
org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:511)
javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
org.acegisecurity.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:265)
org.acegisecurity.intercept.web.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:107)
org.acegisecurity.intercept.web.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:72)
org.acegisecurity.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:275)
org.acegisecurity.ui.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:124)
org.acegisecurity.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:275)
org.acegisecurity.providers.anonymous.AnonymousProcessingFilter.doFilter(AnonymousProcessingFilter.java:125)
org.acegisecurity.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:275)
org.acegisecurity.wrapper.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:81)
org.acegisecurity.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:275)
org.acegisecurity.ui.rememberme.RememberMeProcessingFilter.doFilter(RememberMeProcessingFilter.java:142)
org.acegisecurity.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:275)
org.acegisecurity.ui.AbstractProcessingFilter.doFilter(AbstractProcessingFilter.java:271)
org.acegisecurity.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:275)
org.acegisecurity.ui.logout.LogoutFilter.doFilter(LogoutFilter.java:110)
org.acegisecurity.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:275)
org.acegisecurity.context.HttpSessionContextIntegrationFilter.doFilter(HttpSessionContextIntegrationFilter.java:249)
org.acegisecurity.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:275)
org.acegisecurity.util.FilterChainProxy.doFilter(FilterChainProxy.java:149)
org.acegisecurity.util.FilterToBeanProxy.doFilter(FilterToBeanProxy.java:98)
org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:96)
org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)

root cause

java.lang.NullPointerException

This is all there is to the stacktrace.

I do not expect any of you to come up with a solution to this problem, but hopefully, you can point me in some direction - I have no more ideas...

like image 244
Hoof Avatar asked May 31 '11 08:05

Hoof


2 Answers

Spring Framework is open source, right? So lets have a look what is there at 583 line of FrameworkServlet...

What we can find there is following:

try {
    doService(request, response);
//omit a few catches...
} catch (Throwable ex) {
    failureCause = ex;
throw new NestedServletException("Request processing failed", ex); //line 583
}

So the exception comes from FrameworkServlet.doService method and it properly handled by Spring Framework. So lets have a look at the troublesome doService method...

FrameworkServlet.doService is abstract, but is implemented in DispatcherServlet that you most likely use in your project. Further it calls 'doDispatch' that dispatches handling of the request to the controller.

And my gut feeling tels me that the nasty NPE that we've been hunting here so persistently is hidden in your controller code...

like image 111
Tomasz Błachowicz Avatar answered Oct 02 '22 15:10

Tomasz Błachowicz


Set a breakpoint in your IDE to 'stop on throw' of NullPointerException (attach remote debugger if necessary)

like image 35
krosenvold Avatar answered Oct 02 '22 14:10

krosenvold