Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SLING-11878 | Update ModifiableValueMap javadoc to cover missing methods inherited from java.util.Map #48

Conversation

toniedzwiedz
Copy link

The original javadoc for ModifiableValueMap was written before the addition of new methods to java.util.Map as of Java 8. This commit updates the javadoc to mention the replace and replaceAll methods that can be used to modify resources underlying a ModifiableValueMap instance.

Refer to https://issues.apache.org/jira/browse/SLING-11878 for context.

@toniedzwiedz
Copy link
Author

@stefanseifert I've got a follow-up question. Should we also cover computeIfAbsent and computeIfPresent? These were added in Java 8 as well but I'm not sure if the Javadoc should recommend for or against using them (or stay neutral)

@stefanseifert
Copy link
Member

@toniedzwiedz yes, i think we can include them as well - please update the PR if possible

@toniedzwiedz toniedzwiedz force-pushed the feature/SLING-11878-update-modifiable-value-map-javadoc branch from 7c5945e to fa2b237 Compare May 15, 2023 14:00
@toniedzwiedz
Copy link
Author

@stefanseifert compute, computeIfPresent and computeIfAbsent have been added to the javadoc.

@stefanseifert
Copy link
Member

stefanseifert commented May 15, 2023

@toniedzwiedz just stumbled over the merge method which was also added in java 8 - i think we should add it as well?

@toniedzwiedz
Copy link
Author

@stefanseifert good spot. Could be, assuming that implementations actually support it correctly. I think this snowballed a little, to a point where I'm not 100% sure I've covered everything in my quick experiments with the Groovy console. Are there any tests we can fall back on, to ensure these recommendations actually hold water between releases?

@stefanseifert
Copy link
Member

i'm quite sure all these method added in 1.8 still use the default JDK implementation and thus should not be affected by Sling module updates (looking e.g. at https://github.com/apache/sling-org-apache-sling-jcr-resource/blob/master/src/main/java/org/apache/sling/jcr/resource/internal/JcrModifiableValueMap.java). so i think it should be safe to rely on the documentation on those methods in the JDK javadocs, and according to them all compute and merge methods may modify the map.

@stefanseifert
Copy link
Member

stefanseifert commented May 15, 2023

and to my knowledge there are no test cases that actually cover this - as they are default JDK methods not implemented directly.

inherited from java.util.Map

The original javadoc for `ModifiableValueMap` was written before the
addition of new methods to `java.util.Map` as of Java 8. This commit
updates the javadoc to mention the following methods that can can be
used to modify resources underlying a `ModifiableValueMap`:

- `replace`
- `replaceAll`
- `compute`
- `computeIfAbsent`
- `computeIfPresent`
- `merge`

Refer to https://issues.apache.org/jira/browse/SLING-11878 for context.
@toniedzwiedz toniedzwiedz force-pushed the feature/SLING-11878-update-modifiable-value-map-javadoc branch from fa2b237 to 7558508 Compare May 15, 2023 14:38
@toniedzwiedz
Copy link
Author

toniedzwiedz commented May 15, 2023

@stefanseifert okay, I'm not familiar with how ModifiableValueMap implementations (or the default one, most notably) translate these map operations to resource modification internally, and the Javadoc explicitly calls out some methods as potentially dangerous, so it felt better to ask.

I guess if all those methods do is eventually call put or some such internally, after evaluating a function passed by the caller, then we should be fine.

Anyway, I've added merge to the list.

@sonarqubecloud
Copy link

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants