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

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -