[
https://issues.apache.org/jira/browse/SLING-11878?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Joerg Hoh closed SLING-11878.
-----------------------------
> Clarify Javadoc on which methods allow a ModifiableValueMap to be changed
> -------------------------------------------------------------------------
>
> Key: SLING-11878
> URL: https://issues.apache.org/jira/browse/SLING-11878
> Project: Sling
> Issue Type: Improvement
> Components: API
> Affects Versions: API 2.27.2
> Reporter: Tomasz Niedźwiedź
> Assignee: Stefan Seifert
> Priority: Minor
> Fix For: API 2.27.6
>
>
> 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|https://github.com/wttech/AEM-Rules-for-SonarQube/issues/237#issuecomment-1536213675].
> 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|https://sling.apache.org/apidocs/sling12/org/apache/sling/api/resource/ModifiableValueMap.html],
> here's what it says about changing resources through {{ModifiableValueMap}}
> instances:
> {quote}The {{ModifiableValueMap}} is an extension of the
> [{{ValueMap}}|https://sling.apache.org/apidocs/sling12/org/apache/sling/api/resource/ValueMap.html]
> 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()}}|https://sling.apache.org/apidocs/sling12/org/apache/sling/api/resource/ResourceResolver.html#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()}}*{quote}
> 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?
--
This message was sent by Atlassian Jira
(v8.20.10#820010)