tags:

views:

25

answers:

0

I randomly get this excpetion when I try to reach my session to put a variable.

java.lang.NullPointerException
    com.sun.faces.context.SessionMap.put(SessionMap.java:123)
    com.sun.faces.context.SessionMap.put(SessionMap.java:57)
    com.mycompany.servlet.MyCompanySecurityFilter.getVisitUrlMap(MyCompanySecurityFilter.java:130)

My code is:

public static Boolean getStatus(FacesContext facesContext){
Map<String,Object> sessionMap = facesContext.getExternalContext().getSessionMap();
Boolean myVariable =  (Boolean)sessionMap.get(VISITED);
 if(myVariable == null){
  myVariable = true;
  sessionMap.put( VISITED, myVariable );
  }
  return visitUrlMap;
}

Line 130 where the code falls is the line that starts with sessionMap.put( VISITED, myVariable );

What could cause it? It seems that somehow my session is null (according to SessionMap source code). But why?