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

AEM-17 is claiming replace method is not mutable? #237

Open
holdsworthr opened this issue May 5, 2023 · 4 comments
Open

AEM-17 is claiming replace method is not mutable? #237

holdsworthr opened this issue May 5, 2023 · 4 comments
Assignees

Comments

@holdsworthr
Copy link

holdsworthr commented May 5, 2023

Hi

I'm trying to get rid of this code smell but it appears this sonar rule believes the replace method is not mutable

image

image

@toniedzwiedz
Copy link
Collaborator

Hi @holdsworthr, thanks for reporting this. Looking https://github.com/wttech/AEM-Rules-for-SonarQube/blob/master/src/main/java/com/cognifide/aemrules/java/checks/ModifiableValueMapUsageCheck.java#L63, the rule only recognises put, putAll and remove as mutable methods.

I'm guessing that the implementation follows the ModifiableValueMap Javadoc, which says:

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

This is odd, because other methods inherited from java.util.Map have the effect of changing the values of the properties of the ValueMap's underlying resource.

Unless there's something I'm missing, both the AEM-17 Rule, and the Sling Javadoc could need a change. There may be a reason the Javadoc does not recommend using replace or replaceAll. If there's a good reason not to use those, we may be looking at a new rule. Let me search the Apache Sling Jira to find out if this has been discussed.

@toniedzwiedz
Copy link
Collaborator

@toniedzwiedz
Copy link
Collaborator

@holdsworthr it looks like these methods are valid. I think we'll improve AEM-17 to no longer report them. In the meantime, I would suggest resolving these issues as a won't fix or false positive on your Sonar.

@toniedzwiedz
Copy link
Collaborator

toniedzwiedz commented May 16, 2023

apache/sling-org-apache-sling-api#48 has been merged. This means we should update the rule to allow the following methods in addition to the ones it currently supports:

  • #replace(Object, Object)
  • #replace(Object, Object, Object)
  • #replaceAll(java.util.function.BiFunction)
  • #compute(Object, java.util.function.BiFunction)
  • #computeIfAbsent(Object, java.util.function.Function)
  • #computeIfPresent(Object, java.util.function.BiFunction)
  • #merge(Object, Object, java.util.function.BiFunction)

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

No branches or pull requests

2 participants