title: Null pointer exception while running Spring project
body: <p>I am unable to figure out reason for NullPointer exception in my Spring project. Sometime project works fine but some time its throwing null pointer Exception here is full stacktrace.</p>
  
  <pre><code>org.apache.jasper.JasperException: javax.servlet.ServletException: java.lang.NullPointerException
  org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:585)
  org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:455)
  org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
  org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
  javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
  org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:322)
  org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:116)
  org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:83)
  org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
  org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:113)
  org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
  org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:103)
  org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
  org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.java:113)
  org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
  org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:54)
  org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
  org.springframework.security.web.savedrequest.RequestCacheAwareFilter.doFilter(RequestCacheAwareFilter.java:45)
  org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
  org.springframework.security.web.authentication.www.BasicAuthenticationFilter.doFilter(BasicAuthenticationFilter.java:150)
  org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
  org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:182)
  org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
  org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:105)
  org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
  org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:87)
  org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
  org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.java:184)
  org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:155)
  org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:346)
  org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:259)
  
  root cause
  
  javax.servlet.ServletException: java.lang.NullPointerException
  org.apache.jsp.redirect_jsp._jspService(index_jsp.java:72)
  org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
  javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
  org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
  org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
  org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
  javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
  org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:322)
  org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:116)
  org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:83)
  org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
  org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:113)
  org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
  org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:103)
  org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
  org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.java:113)
  org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
  org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:54)
  org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
  org.springframework.security.web.savedrequest.RequestCacheAwareFilter.doFilter(RequestCacheAwareFilter.java:45)
  org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
  org.springframework.security.web.authentication.www.BasicAuthenticationFilter.doFilter(BasicAuthenticationFilter.java:150)
  org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
  org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:182)
  org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
  org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:105)
  org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
  org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:87)
  org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
  org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.java:184)
  org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:155)
  org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:346)
  org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:259)
  
  root cause
  
   java.lang.NullPointerException
  org.apache.catalina.session.ManagerBase.generateSessionId(ManagerBase.java:807)
  org.apache.catalina.session.ManagerBase.createSession(ManagerBase.java:653)
  org.apache.catalina.connector.Request.doGetSession(Request.java:2892)
  org.apache.catalina.connector.Request.getSession(Request.java:2315)
  org.apache.catalina.connector.RequestFacade.getSession(RequestFacade.java:898)
  org.apache.catalina.connector.RequestFacade.getSession(RequestFacade.java:910)
  javax.servlet.http.HttpServletRequestWrapper.getSession(HttpServletRequestWrapper.java:238)
  javax.servlet.http.HttpServletRequestWrapper.getSession(HttpServletRequestWrapper.java:238)
  org.apache.jasper.runtime.PageContextImpl._initialize(PageContextImpl.java:146)
  org.apache.jasper.runtime.PageContextImpl.initialize(PageContextImpl.java:125)
  org.apache.jasper.runtime.JspFactoryImpl.internalGetPageContext(JspFactoryImpl.java:112)
  org.apache.jasper.runtime.JspFactoryImpl.getPageContext(JspFactoryImpl.java:65)
  org.apache.jsp.redirect_jsp._jspService(redirect_jsp.java:53)
  org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
  javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
  org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
  org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
  org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
  javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
  org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:322)
  org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:116)
  org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:83)
  org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
  org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:113)
  org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
  org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:103)
  org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
  org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.java:113)
  org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
  org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:54)
  org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
  org.springframework.security.web.savedrequest.RequestCacheAwareFilter.doFilter(RequestCacheAwareFilter.java:45)
  org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
  org.springframework.security.web.authentication.www.BasicAuthenticationFilter.doFilter(BasicAuthenticationFilter.java:150)
  org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
  org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:182)
  org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
  org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:105)
  org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
  org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:87)
  org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
  org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.java:184)
  org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:155)
  org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:346)
  org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:259)
  </code></pre>
  
  <p>I am also getting permgenspace error very often. is it related to this?
  I changed my project and tomcat VM option (Using NetBean IDE) to:</p>
  
  <pre><code>-XX:MaxPermSize=512m
  </code></pre>
  
  <p>I am using Netbeans IDE 7.3.1 , Apache Tomcat 7.0.37, Spring 3.1.1, Hibernate 3.</p>
  
  <p>Its showing DelegatingFilterProxy in Exception. May be its because of security setting.</p>
  
  <pre><code>    &lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;beans xmlns="http://www.springframework.org/schema/beans"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xmlns:security="http://www.springframework.org/schema/security"
     xsi:schemaLocation="http://www.springframework.org/schema/beans 
     http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
     http://www.springframework.org/schema/security 
     http://www.springframework.org/schema/security/spring-security-3.1.xsd"&gt;
  
  &lt;!-- This is where we configure Spring-Security  --&gt;
  &lt;security:http auto-config="true" use-expressions="true" access-denied-page="/auth/denied" &gt;
      &lt;security:intercept-url pattern="/admin/**" access="hasRole('ROLE_ADMIN')"/&gt;
      &lt;security:intercept-url pattern="/auth/**" access="hasRole('ROLE_USER')"/&gt;
      &lt;security:form-login
          login-page="/index"
          authentication-failure-url="/index"
          default-target-url="/welcome"
          /&gt;
      &lt;security:logout
          invalidate-session="true"
          logout-success-url="/index" /&gt;
  &lt;/security:http&gt;
  
  
  &lt;!-- A custom service where Spring will retrieve users and their corresponding access levels  --&gt;
  &lt;bean id="loginService" class="com.tcs.ignite.ih.spring.service.LoginService"/&gt;
  
  &lt;!--A service where spring will redirect to proper view after successfull login--&gt;
  &lt;!--&lt;bean id="loginSuccessHandler" class="com.tcs.ignite.ih.spring.controller.LoginSuccessHandler" /&gt;--&gt;
  
  &lt;!-- Declare an authentication-manager to use a custom userDetailsService --&gt;
  &lt;security:authentication-manager&gt;
      &lt;security:authentication-provider user-service-ref="loginService"&gt;
      &lt;/security:authentication-provider&gt;
  &lt;/security:authentication-manager&gt;
  
  &lt;/beans&gt;
  </code></pre>
  
  <p><strong>UPDATE :</strong></p>
  
  <p>When I am trying to access index file,welcome file for application defined in web.xml, with following URL</p>
  
  <pre><code>localhost:8080/xxxx/index
  </code></pre>
  
  <p>I recieve following on browser:</p>
  
  <pre><code>HTTP Status 500 - Could not get RequestDispatcher for [/WEB-INF/jsp/index.jsp]: Check that the corresponding file exists within your web application archive!
  </code></pre>
  
  <p>index.jsp in present in my directory.
  Do i need to define mapping in spring security intercept url tag for /index?</p>