rotty3000/liferay-portal — pull request #500 by moltam89 (2014-07-07 09:31:13+00:00)
Title: [TECHNICAL-SUPPORT] LPS-48293  Default values are ignored if a null value is set in preferences

Hi Ray,

this pr is like a question as I'm not sure what is the correct behavior.
My fix changes the preferences handling deeply, which scares me, however I can't see why it's working like this.

Right now when a null value is set to the preferences, the default value is not used.

portletPreferences.setValue(key, null);

portletPreferences.getValue(key, someDefaultValue)) == null

According to the [specification](https://portals.apache.org/pluto/portlet-2.0-apidocs/javax/portlet/PortletPreferences.html#getValue(java.lang.String, java.lang.String)), "A null value is treated as a non-existent value", so I would say that the default value should be used.

When a null value is set, the portal turns it to a String array:

if (values == null) {
return new String[] {_NULL_VALUE};
}

This leads to a really weird behavior:

portletPreferences.setValues(key, new String[] {null});

portletPreferences.getValues(key, defaultValues)) == null
So what happens here is that, we set a specific value, and when we are trying to get it back using some default values, the portal gives back a third (null) value.
When we are setting some key,value pair, the portal doesn't make any difference between a null value and a String array with a single null value.

This behavior causes problems during the import process, when the preferences are copied (PortletImporter ->updatePortletPreferences). When there is no value for a key, a null value is copied to the preferences. Querying this value ignores the default value, and returns null, which leads to NullPointerExceptions.

After my changes, the default values are used when getting some value related to a key would return null.

Could you please review my changes, and tell me what is the desired behavior and why?

Thanks,
Tamás