Uploaded image for project: 'Pluto'
  1. Pluto
  2. PLUTO-167

PortletPreferencesImpl.getMap() breaks the spec: PLT 14.1 (xci)

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 1.1.0-alpha1
    • 1.1.0-alpha1
    • portlet container
    • None

    Description

      The portlet spec (xci, SPEC 91, PLT 14.1) states that:

      The getMap method returns an immutable Map of String keys and String[] values containing all current preference values. Preferences values must not be modified if the values in the Map are altered.

      I added a checkPreferencesValuesNotModified() method in the testsuite class SimplePreferenceTest, to check PLT 14.1. That test failed: In fact, if I changed the values of the string array in the map returned (NOT to put an entry into the map, since that operation is not allowed), the preferences values are changed accordingly.

      The bug resides in the class PortletPreferencesImpl. I updated the method getMap() as the following, and then the spec was respected:

      public Map getMap() {
      Map map = new java.util.HashMap();
      Iterator it = preferences.keySet().iterator();
      while (it.hasNext())

      { PortletPreference pref = (PortletPreference)preferences.get(it.next()); map.put(pref.getName(), pref.getValues().clone()); // <== Here we clone the string array. }

      return Collections.unmodifiableMap(map);
      }

      Attachments

        1. SimplePreferencesTest.svndiff.txt
          3 kB
          @deprecated ZHENG Zhong
        2. PortletPreferencesImpl.svndiff.txt
          1 kB
          @deprecated ZHENG Zhong

        Activity

          People

            Unassigned Unassigned
            heavyz @deprecated ZHENG Zhong
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: