Uploaded image for project: 'Sling'
  1. Sling
  2. SLING-11878

Clarify Javadoc on which methods allow a ModifiableValueMap to be changed

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • API 2.27.2
    • API 2.27.6
    • API
    • None

    Description

      Hi, one of the users of AEM Rules for SonarQube has asked a question about the ModifiableValueMap interface and the methods through which the map is changeable. Here's the original GitHub issue.

      Whether the Sonar rule is valid or should be changed depends on the intended way the MVM API should be used. I believe the current implementation of the Sonar rule is based on a piece of Sling API Javadoc that I think could use some clarification.

      Looking at the latest available version of the Javadoc, here's what it says about changing resources through ModifiableValueMap instances:

      The ModifiableValueMap is an extension of the ValueMap which allows to modify and persist properties. All changes to this map are stored in the transient layer of the resource resolver or more precisely in the transient layer of the resource provider managing this resource.

      Once ResourceResolver.commit() is called, the changes are finally persisted.

      The modifiable value map is only changeable through one of these methods

      • Map.put(Object, Object)
      • Map.putAll(java.util.Map)
      • Map.remove(Object)

      The map is not modifiable through the collections provided by

      • Map.entrySet()
      • Map.keySet()
      • Map.values()

      And it can't be modified by these methods:

      • Map.clear()

      Since the ModifiableValueMap interface implements java.util.Map, it also comes with the following methods:

      • replace
      • replaceAll

      I've done a quick test in AEM 6.5, by means of the Groovy console, and these methods have the effect of modifying the map's underlying resource once the session is saved/RR is committed.

      Should these methods also be documented as valid? Or is there a reason they shouldn't be called?

      Attachments

        Activity

          People

            sseifert Stefan Seifert
            tomasz.k.niedzwiedz@gmail.com Tomasz Niedźwiedź
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: