oracle.jbo.Session User Data Hashtable Not Saved Across Passivation and Activation (Doc ID 947799.1)

Last updated on MARCH 08, 2017

Applies to:

Oracle JDeveloper - Version: 10.1.3.5.0
This problem can occur on any platform.

Symptoms


You have developed an ADF BC application.
In this application, you created a java class called "UserInfo" that keeps information about the
user who logged in.

...
...
import java.util.Hashtable;
...
import oracle.jbo.Session;
...
public class UserInfo {
...
  public static void setUserInfoObj(Row loggedInUserRow, Session session) {
    try {
  
      UserInfo userInfo = new UserInfo(loggedInUserRow);
      session.getUserData().put(UserInfo.CURRENT_USERNAME_KEY_ID, userInfo);
    }
    catch (Exception ex) {
      ex.printStackTrace();
    }
  }

  public static UserInfo getUserInfoObj(Session session) {
    try {

      Hashtable userdata = session.getUserData();
      UserInfo userInfo = (UserInfo)userdata.get(UserInfo.CURRENT_USERNAME_KEY_ID);
          
      return userInfo;
    }
    catch (Exception ex) {
      ex.printStackTrace();
      return null;
    }
  }
...
}

This code works fine in your development environment.
However, in the production environment, you get intermittent NullPointerExceptions caused by the
fact the variable userInfo is null:

userInfo.getUsername() -> NullPointerException


Cause

Sign In with your My Oracle Support account

Don't have a My Oracle Support account? Click to get started

My Oracle Support provides customers with access to over a
Million Knowledge Articles and hundreds of Community platforms