title: Spring mvc Controller Null Pointer Exception
body: <p>I'm trying to test my controller with this url mapping:</p>
  
  <pre><code>controller Code:  
          HttpSession sessionHttp;
          @Controller
              public class LoginController {
                 @RequestMapping(value="/logout")
                   public String logout(ModelMap model) {
                    sessioneHttp.invalidate();
                    return "login-credential";  
      }}  
  </code></pre>
  
  <hr>
  
  <pre><code>@RunWith(SpringJUnit4ClassRunner.class)
  @WebAppConfiguration
  @ContextConfiguration(locations="classpath*:/META-INF/spring/applicationContext.xml")
  
  public class MainControllerTest {
   @Autowired  
     private WebApplicationContext wac;  
     private MockMvc mockMvc;  
          @InjectMocks
          private LoginController loginController= new LoginController();
  
       @Before public void setUp() {
       MockitoAnnotations.initMocks(this);
          mockMvc = MockMvcBuilders.standaloneSetup(loginController).build();
          }
  
          @Test
             public void LogoutTest() throws Exception {
               this.mockMvc.perform(MockMvcRequestBuilders.get("/logout"))  
                  .andExpect(MockMvcResultMatchers.status().isOk())  
                  .andExpect(MockMvcResultMatchers.view().name("login-credential"))
                 .andDo(print());       
              }
  
              }
  </code></pre>
  
  <hr>
  
  <pre><code>    And this is the stackTrace:
  
  
  
  org.springframework.web.util.NestedServletException: Request processing failed; nested exception     is java.lang.NullPointerException
      at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:973)
      at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:852)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:687)
      at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:837)
      at org.springframework.test.web.servlet.TestDispatcherServlet.service(TestDispatcherServlet.java:62)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
      at org.springframework.mock.web.MockFilterChain$ServletFilterProxy.doFilter(MockFilterChain.java:170)
      at org.springframework.mock.web.MockFilterChain.doFilter(MockFilterChain.java:137)
      at org.springframework.test.web.servlet.MockMvc.perform(MockMvc.java:141)
      at org.controllers.MainControllerTest.LogoutTest(MainControllerTest.java:136)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
      at java.lang.reflect.Method.invoke(Unknown Source)
      at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
      at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
      at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
      at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
      at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
      at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:74)
      at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:83)
      at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:72)
      at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:233)
      at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:87)
      at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
      at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
      at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
      at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
      at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
      at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
      at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:71)
      at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
      at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:176)
      at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
      at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
      at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
      at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
      at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
      at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
  Caused by: java.lang.NullPointerException
      at it.sydema.laweb.controllers.LoginController.logout(LoginController.java:251)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
      at java.lang.reflect.Method.invoke(Unknown Source)
      at org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:215)
      at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:132)
      at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:104)
      at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:749)
      at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:689)
      at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:83)
      at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:938)
      at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:870)
      at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:961)
      ... 38 more
  </code></pre>
  
  <p><em>I don't know why i'm getting the null pointer exception.
  Appreciate any help.</em></p>