Uploaded image for project: 'PUBLIC - Liferay Portal Community Edition'
  1. PUBLIC - Liferay Portal Community Edition
  2. LPS-35558

NullPointerException in SharedSessionWrapper.hashCode() when WAR plugin portlets utilize Weld on JBoss AS

    Details

      Description

      Problem Background:

      When deploying the jsf2-cdi-portlet on JBoss AS 7, the first HTTP GET of the portal page will cause a NullPointerException in Liferay Portal's SharedSessionWrapper.hashCode() method:

      public int hashCode() {
          return _portalSession.hashCode() ^ _portletSession.hashCode();
      }
      

      Underlying Reasons

      When a context is deployed in JBoss AS 7, the server's WeldSubsystemAdd.java class creates a new instance of WebIntegrationProcessor.java. Because of this, JBoss AS 7 automatically registers WeldListener.java for webapp contexts that need CDI. The listener is registered as the FIRST of all listeners for the webapp context.

      One of the things that WeldListener does is listen for context initialization events. When it hears that a context is initialized, it calls HttpServletRequest.getSession(boolean create) in order to get a session. However, since it passes false for the create boolean parameter, the _portletSession variable inside of BridgeSessionWrapper is null. This is what causes the NullPointerException when Weld later calls the SharedSessionWrapper.hashCode() method.

      Proposed Fix: (simple null check)

      public int hashCode() {
      	if (_portletSession == null) {
      		return _portalSession.hashCode();
      	}
      	else {
      		return _portalSession.hashCode() ^ _portletSession.hashCode();
      	}
      }
      

      *Steps to Reproduce:*

      1. Build the jsf2-cdi-portlet from the 3.1.x branch (see the Building Liferay Faces From Source wiki article for help)

      2. Deploy the jsf2-cdi-portlet to Liferay+JBoss using the following command:

      mvn -P jboss clean install liferay:deploy

      3. Add the jsf2-cdi-portlet to a portal page

      4. Visit the portal page in the browser

      If the bug still exists, then there will be a stacktrace in the server log and the portlet will show an error message.

      If the bug is fixed, then the portlet will function properly and there will be no stacktrace in the server log.

        Attachments

          Issue Links

            Activity

              People

              • Votes:
                0 Vote for this issue
                Watchers:
                1 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:
                  Days since last comment:
                  5 years, 49 weeks, 3 days ago