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

Liferay Portal 6.0 to 6.2 upgrade fails during UpdatePortletPreference process with NPE when portletid is NULL

    Details

      Description

      Overview

      Hello LPS,

      Liferay Portal 6.0 to 6.2 upgrade fails during UpdatePortletPreference process with NPE when portletid is NULL.

      I saw this issue recently (June 2014) while upgrading LP 6.0 EE GA2 to LP 6.2 EE SP5.

      Upgrade Log

      2014-06-16 17:26:54,978 INFO  [localhost-startStop-1][UpgradeProcess:175] Upgrading com.liferay.portal.upgrade.v6_2_0.UpgradePortletPreferences
      2014-06-16 17:26:57,947 ERROR [localhost-startStop-1][MainServlet:212] com.liferay.portal.kernel.events.ActionException: com.liferay.portal.kernel.upgrade.UpgradeException: com.liferay.portal.kernel.upgrade.UpgradeException: java.lang.NullPointerException
      com.liferay.portal.kernel.events.ActionException: com.liferay.portal.kernel.upgrade.UpgradeException: com.liferay.portal.kernel.upgrade.UpgradeException: java.lang.NullPointerException
      	at com.liferay.portal.events.StartupAction.run(StartupAction.java:74)
      	at com.liferay.portal.servlet.MainServlet.processStartupEvents(MainServlet.java:1245)
      	at com.liferay.portal.servlet.MainServlet.init(MainServlet.java:209)
      . . .
      	at java.lang.Thread.run(Unknown Source)
      Caused by: com.liferay.portal.kernel.upgrade.UpgradeException: com.liferay.portal.kernel.upgrade.UpgradeException: java.lang.NullPointerException
      	at com.liferay.portal.kernel.upgrade.UpgradeProcess.upgrade(UpgradeProcess.java:181)
      . . .
      	at com.liferay.portal.events.StartupAction.run(StartupAction.java:68)
      	... 19 more
      Caused by: com.liferay.portal.kernel.upgrade.UpgradeException: java.lang.NullPointerException
      	at com.liferay.portal.kernel.upgrade.UpgradeProcess.upgrade(UpgradeProcess.java:181)
      	at com.liferay.portal.kernel.upgrade.UpgradeProcess.upgrade(UpgradeProcess.java:195)
      	at com.liferay.portal.upgrade.UpgradeProcess_6_2_0.doUpgrade(UpgradeProcess_6_2_0.java:84)
      	at com.liferay.portal.kernel.upgrade.UpgradeProcess.upgrade(UpgradeProcess.java:178)
      	... 28 more
      Caused by: java.lang.NullPointerException
      	at java.lang.String.contains(Unknown Source)
      	at com.liferay.portal.upgrade.v6_2_0.UpgradePortletPreferences.doUpgrade(UpgradePortletPreferences.java:75)
      	at com.liferay.portal.kernel.upgrade.UpgradeProcess.upgrade(UpgradeProcess.java:178)
      	... 31 more
      Stopping the server due to unexpected startup errors
      

      Liferay Portal Environment

      The source Liferay Portal 6.0 environment was:

      • Liferay Portal : Liferay Portal 6.0 EE SP2
      • O/S: MS Windows 2008 Server R2
      • JRE: Sun JRE 1.6.0.20
      • DBS: Oracle Database 10g Release 10.2.0.4.0 - 64bit Production
      • JDBC Driver: Oracle JDBC 10.2.0.5.0

      The target Liferay Portal 6.2 environment was:

      • Liferay Portal : Liferay Portal 6.2 EE SP5
      • O/S: MS Windows 2012 Server R2
      • JRE: Oracle JRE 1.7.0_60
      • DBS: Oracle Database 10g Release 10.2.0.4.0 - 64bit Production
      • JDBC Driver: Oracle JDBC 10.2.0.5.0

      Review

      Method doUpgrade contains a String test with a String value that can be NULL and can result in a NPE.

      // >>>
      // >>> DEFECT - This String test will fail with NPE when portletId is NULL
      // >>>
      if (typeSettings.contains(portletId)) {
         continue;
      }
      

      The cause of the NULL value for column portletid in table portletpreferences remains unknown, but the coding defect still exists in LP 6.2 CE SP5
      and can be see in the source code for UpgradePortletPreferences can be see in GitHub at

      https://github.com/liferay/liferay-portal/blob/b87113b5cfe9217b8327ce60c97579938c7fc6dd/portal-impl/src/com/liferay/portal/upgrade/v6_2_0/UpgradePortletPreferences.java

      with SHA

      b87113b5cfe9217b8327ce60c97579938c7fc6dd

      dated 5 April 2014.

      The defect can be seen in this snippet of code :

      package com.liferay.portal.upgrade.v6_2_0;
      
      public class UpgradePortletPreferences extends UpgradeProcess {
      
      	@Override
      	protected void doUpgrade() throws Exception {
      
      . . .
      
                                      // >>>
                                      // >>> DEFECT - This String test will fail with NPE when portletId is NULL
                                      // >>>
      				if (typeSettings.contains(portletId)) {
      					continue;
      				}
      	}
      . . .
      }
      

      A visual inspection of the above code snippet shows when String portletId has value NULL, the String contains function will throw a NPE that is not caught and results in a failed upgrade.

      The outcome is the portal admin must then restore the DB to the pre-upgrade state and commence the upgrade process again, which is a time consuming process.

      A simple NPE test will prevent this issue.

      Solution

      The issue has been resolved in the source code for UpgradePortletPreferences in GitHub at

      https://github.com/liferay/liferay-portal/blob/4821c1b8abf2a5b721e12c537dcfafdf90eca724/portal-impl/src/com/liferay/portal/upgrade/v6_2_0/UpgradePortletPreferences.java

      with SHA

      4821c1b8abf2a5b721e12c537dcfafdf90eca724

      dated 25 Oct 2013

      This update includes the following NPE check

      if ((typeSettings != null) && typeSettings.contains(portletId)) {
         continue;
      }
      

      Hence, this coding defect was resolved in community on 25 Oct 2013, but has remained in the LP 6.2.x code base and is still an issue now, Tue 15 July 2014, some 9 months later.

      This issue may also be related to the behaviour of different JDBC drivers and how they interpret a NULL column value.

      NOTE: It appears the MySQL JDBC driver translates a NULL portletid column value to an empty String value, while the Oracle JDBC driver translates a NULL portletid column value to a NULL String value.

      Implementing the NULL test for UpgradePortletPreferences from

      https://github.com/liferay/liferay-portal/blob/4821c1b8abf2a5b721e12c537dcfafdf90eca724/portal-impl/src/com/liferay/portal/upgrade/v6_2_0/UpgradePortletPreferences.java

      will resolve this issue across different JDBC drivers.

      Please review and advise when this issue is likely to be resolved in LP 6.2.x master.

      Regards,

      Tim

        Attachments

          Issue Links

            Activity

              People

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

                Dates

                • Created:
                  Updated:
                  Resolved:
                  Days since last comment:
                  5 years, 7 weeks, 6 days ago

                  Packages

                  Version Package
                  6.2.2 CE GA3
                  6.2.X EE
                  7.0.0 M1