portals-jetspeed-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From woon...@apache.org
Subject svn commit: r1002877 - in /portals/jetspeed-2/portal/trunk/components: jetspeed-page-layout/src/main/java/org/apache/jetspeed/layout/impl/ jetspeed-page-layout/src/main/java/org/apache/jetspeed/om/page/impl/ jetspeed-registry/src/main/java/org/apache/j...
Date Wed, 29 Sep 2010 22:29:12 GMT
Author: woonsan
Date: Wed Sep 29 22:29:12 2010
New Revision: 1002877

URL: http://svn.apache.org/viewvc?rev=1002877&view=rev
Log:
Fixing NPE when there's no value assigned for a preference.
This problem was pointed out by Ruben Carvalho. Thank you so much!
Here's an explanation:

According to the portlet specification, it is possible for a portlet preference to be defined
like this: 
<preference>
  <name>CategoryID</name>
</preference>

And, some codes like the following could NPE:

for (String s : pref.getValues()) { }

because PortletPreference#getValues() can return null instead of empty string array.
(For example, DatabasePreference returns null explicitly when it has empty value collection
internally.)

Therefore, it is necessary to check if getValues() is null or not.

By the way, if you navigate portlet preference tab for a portlet, which has a non-value preference
element, in Portlet Application Manager of j2-admin, then you can find that you cannot update
the value for the preference.
However, you can still remove the preference and create a preference to have a value with
that name again.
This seems a little strange, but anyway it is good enough for now.

Modified:
    portals/jetspeed-2/portal/trunk/components/jetspeed-page-layout/src/main/java/org/apache/jetspeed/layout/impl/PageLayoutComponentImpl.java
    portals/jetspeed-2/portal/trunk/components/jetspeed-page-layout/src/main/java/org/apache/jetspeed/om/page/impl/ContentFragmentImpl.java
    portals/jetspeed-2/portal/trunk/components/jetspeed-page-layout/src/main/java/org/apache/jetspeed/om/page/impl/ContentFragmentPreferenceImpl.java
    portals/jetspeed-2/portal/trunk/components/jetspeed-registry/src/main/java/org/apache/jetspeed/components/portletpreferences/PortletPreferencesServiceImpl.java
    portals/jetspeed-2/portal/trunk/components/jetspeed-registry/src/main/java/org/apache/jetspeed/om/portlet/impl/PortletDefinitionImpl.java

Modified: portals/jetspeed-2/portal/trunk/components/jetspeed-page-layout/src/main/java/org/apache/jetspeed/layout/impl/PageLayoutComponentImpl.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/components/jetspeed-page-layout/src/main/java/org/apache/jetspeed/layout/impl/PageLayoutComponentImpl.java?rev=1002877&r1=1002876&r2=1002877&view=diff
==============================================================================
--- portals/jetspeed-2/portal/trunk/components/jetspeed-page-layout/src/main/java/org/apache/jetspeed/layout/impl/PageLayoutComponentImpl.java
(original)
+++ portals/jetspeed-2/portal/trunk/components/jetspeed-page-layout/src/main/java/org/apache/jetspeed/layout/impl/PageLayoutComponentImpl.java
Wed Sep 29 22:29:12 2010
@@ -1705,7 +1705,11 @@ public class PageLayoutComponentImpl imp
                     {
                         PortletPreference portletPreference = (PortletPreference)values;
                         preference.setReadOnly(portletPreference.isReadOnly());
-                        preference.getValueList().addAll(Arrays.asList(portletPreference.getValues()));
+                        String [] prefValues = portletPreference.getValues();
+                        if (prefValues != null)
+                        {
+                            preference.getValueList().addAll(Arrays.asList(prefValues));
+                        }
                     }
                     else
                     {

Modified: portals/jetspeed-2/portal/trunk/components/jetspeed-page-layout/src/main/java/org/apache/jetspeed/om/page/impl/ContentFragmentImpl.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/components/jetspeed-page-layout/src/main/java/org/apache/jetspeed/om/page/impl/ContentFragmentImpl.java?rev=1002877&r1=1002876&r2=1002877&view=diff
==============================================================================
--- portals/jetspeed-2/portal/trunk/components/jetspeed-page-layout/src/main/java/org/apache/jetspeed/om/page/impl/ContentFragmentImpl.java
(original)
+++ portals/jetspeed-2/portal/trunk/components/jetspeed-page-layout/src/main/java/org/apache/jetspeed/om/page/impl/ContentFragmentImpl.java
Wed Sep 29 22:29:12 2010
@@ -1599,7 +1599,13 @@ public class ContentFragmentImpl impleme
                 else if (values instanceof PortletPreference)
                 {
                     PortletPreference portletPreference = (PortletPreference)values;
-                    preference = new ContentFragmentPreferenceImpl(name, portletPreference.isReadOnly(),
Arrays.asList(portletPreference.getValues()));
+                    List<String> prefValueList = null;
+                    String [] prefValues = portletPreference.getValues();
+                    if (prefValues != null)
+                    {
+                        prefValueList = Arrays.asList(prefValues);
+                    }
+                    preference = new ContentFragmentPreferenceImpl(name, portletPreference.isReadOnly(),
prefValueList);
                 }
                 else
                 {

Modified: portals/jetspeed-2/portal/trunk/components/jetspeed-page-layout/src/main/java/org/apache/jetspeed/om/page/impl/ContentFragmentPreferenceImpl.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/components/jetspeed-page-layout/src/main/java/org/apache/jetspeed/om/page/impl/ContentFragmentPreferenceImpl.java?rev=1002877&r1=1002876&r2=1002877&view=diff
==============================================================================
--- portals/jetspeed-2/portal/trunk/components/jetspeed-page-layout/src/main/java/org/apache/jetspeed/om/page/impl/ContentFragmentPreferenceImpl.java
(original)
+++ portals/jetspeed-2/portal/trunk/components/jetspeed-page-layout/src/main/java/org/apache/jetspeed/om/page/impl/ContentFragmentPreferenceImpl.java
Wed Sep 29 22:29:12 2010
@@ -16,6 +16,7 @@
  */
 package org.apache.jetspeed.om.page.impl;
 
+import java.util.ArrayList;
 import java.util.List;
 
 import org.apache.jetspeed.om.preference.FragmentPreference;
@@ -59,7 +60,11 @@ public class ContentFragmentPreferenceIm
      */
     public List getValueList()
     {
-        return valueList;
+        if (this.valueList == null)
+        {
+            this.valueList = new ArrayList();            
+        }
+        return this.valueList;
     }
 
     /* (non-Javadoc)

Modified: portals/jetspeed-2/portal/trunk/components/jetspeed-registry/src/main/java/org/apache/jetspeed/components/portletpreferences/PortletPreferencesServiceImpl.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/components/jetspeed-registry/src/main/java/org/apache/jetspeed/components/portletpreferences/PortletPreferencesServiceImpl.java?rev=1002877&r1=1002876&r2=1002877&view=diff
==============================================================================
--- portals/jetspeed-2/portal/trunk/components/jetspeed-registry/src/main/java/org/apache/jetspeed/components/portletpreferences/PortletPreferencesServiceImpl.java
(original)
+++ portals/jetspeed-2/portal/trunk/components/jetspeed-registry/src/main/java/org/apache/jetspeed/components/portletpreferences/PortletPreferencesServiceImpl.java
Wed Sep 29 22:29:12 2010
@@ -318,13 +318,17 @@ public class PortletPreferencesServiceIm
                 dbPref.setName(preference.getName());
                 dbPref.setReadOnly(preference.isReadOnly());
                 short index = 0;
-                for (String value : preference.getValues())
+                String [] values = preference.getValues();
+                if (values != null)
                 {
-                    DatabasePreferenceValue dbValue = new DatabasePreferenceValue();
-                    dbValue.setIndex(index);
-                    dbValue.setValue(value);
-                    dbPref.getPreferenceValues().add(dbValue);                
-                    index++;
+                    for (String value : values)
+                    {
+                        DatabasePreferenceValue dbValue = new DatabasePreferenceValue();
+                        dbValue.setIndex(index);
+                        dbValue.setValue(value);
+                        dbPref.getPreferenceValues().add(dbValue);                
+                        index++;
+                    }
                 }
                 getPersistenceBrokerTemplate().store(dbPref);
             }
@@ -333,14 +337,18 @@ public class PortletPreferencesServiceIm
                 dbPref.getPreferenceValues().clear();
                 PortletPreference preference = map.get(dbPref.getName());
                 short index = 0;
-                for (String value : preference.getValues())
+                String [] values = preference.getValues();
+                if (values != null)
                 {
-                    DatabasePreferenceValue dbValue = new DatabasePreferenceValue();
-                    dbValue.setIndex(index);
-                    dbValue.setValue(value);
-                    index++;
-                    dbPref.getPreferenceValues().add(dbValue);
-                }            
+                    for (String value : values)
+                    {
+                        DatabasePreferenceValue dbValue = new DatabasePreferenceValue();
+                        dbValue.setIndex(index);
+                        dbValue.setValue(value);
+                        index++;
+                        dbPref.getPreferenceValues().add(dbValue);
+                    }            
+                }
                 getPersistenceBrokerTemplate().store(dbPref);            
             }        
             // remove from cache to send distributed notification
@@ -820,13 +828,17 @@ public class PortletPreferencesServiceIm
             dbPref.setName(preference.getName());
             dbPref.setReadOnly(preference.isReadOnly());
             short index = 0;
-            for (String value : preference.getValues())
+            String [] values = preference.getValues();
+            if (values != null)
             {
-                DatabasePreferenceValue dbValue = new DatabasePreferenceValue();
-                dbValue.setIndex(index);
-                dbValue.setValue(value);
-                dbPref.getPreferenceValues().add(dbValue);
-                index++;
+                for (String value : values)
+                {
+                    DatabasePreferenceValue dbValue = new DatabasePreferenceValue();
+                    dbValue.setIndex(index);
+                    dbValue.setValue(value);
+                    dbPref.getPreferenceValues().add(dbValue);
+                    index++;
+                }
             }
             getPersistenceBrokerTemplate().store(dbPref);
         }

Modified: portals/jetspeed-2/portal/trunk/components/jetspeed-registry/src/main/java/org/apache/jetspeed/om/portlet/impl/PortletDefinitionImpl.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/components/jetspeed-registry/src/main/java/org/apache/jetspeed/om/portlet/impl/PortletDefinitionImpl.java?rev=1002877&r1=1002876&r2=1002877&view=diff
==============================================================================
--- portals/jetspeed-2/portal/trunk/components/jetspeed-registry/src/main/java/org/apache/jetspeed/om/portlet/impl/PortletDefinitionImpl.java
(original)
+++ portals/jetspeed-2/portal/trunk/components/jetspeed-registry/src/main/java/org/apache/jetspeed/om/portlet/impl/PortletDefinitionImpl.java
Wed Sep 29 22:29:12 2010
@@ -153,9 +153,13 @@ public class PortletDefinitionImpl imple
         {
             Preference p = preferences.addPreference(pref.getName());
             p.setReadOnly(pref.isReadOnly());
-            for (String s : pref.getValues())
+            String [] values = pref.getValues();
+            if (values != null) 
             {
-                p.addValue(s);
+                for (String s : values)
+                {
+                    p.addValue(s);
+                }
             }
         }
         return preferences;



---------------------------------------------------------------------
To unsubscribe, e-mail: jetspeed-dev-unsubscribe@portals.apache.org
For additional commands, e-mail: jetspeed-dev-help@portals.apache.org


Mime
View raw message