java - servletactioncontext null in struts2.3.12 -


for (cookie cookie : servletactioncontext.getrequest().getcookies()) { 

the above line giving me

java.lang.nullpointerexception         @ interceptors.remembermeinterceptor.intercept(remembermeinterceptor.java:35)         @ com.opensymphony.xwork2.defaultactioninvocation.invoke(defaultactioninvocation.java:246) 

it used work fine in struts2.1.8 upgraded struts2 version in pom.xml 2.3.12 , stopped working giving me above error.

there 2 things cause nullpointerexception in line:

for (cookie cookie : servletactioncontext.getrequest().getcookies()) { 
  1. servletactioncontext.getrequest() return null if called outside of http request. since calling line interceptor, doesn't seem likely.

  2. servletactioncontext.getrequest().getcookies() return null if there no cookies sent request. attempting iterate on null collection or array produce npe.

try changing code follows:

cookie[] cookies = servletactioncontext.getrequest().getcookies(); if (cookies != null) {   (cookie cookie : cookies) {     //   } } 

Comments

Popular posts from this blog

php - Why I am getting the Error "Commands out of sync; you can't run this command now" -

ruby - Nesting modules inside of a Rails eninge gem -

Eclipse formatter for java ending braces -