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()) {
servletactioncontext.getrequest()
return null if called outside of http request. since calling line interceptor, doesn't seem likely.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
Post a Comment