ConcurrentMap#values()#remove("item") reported as javabugs:S6322 while it shouldn't be

Language: Java
Rule: javabugs:S6322

This shouldn’t be reported, as the “remove”-method of ConcurrentMap specifically states that a view that is backed by the map is returned, on which all operations (except for add & addAll) can be called, including the remove-method.

SonarQube Developer Edition v9.9.1


ConcurrentMap<String, String> x = new ConcurrentHashMap<>();
x.values().remove("item"); // reported as javabugs:S6322

Hello HenryKuijpers!

thank you for reporting this issue.

You are absolutely right, calling remove on the result of Map::values is permitted.
This issue has been addressed and a fix is already available in newer versions of SonarQube.

Unfortunately, it is not available in the current LTS release (9.9.2), and you would need to update to at least version 10.1.0 to receive the fix.

If there is anything else I can help you with, don’t hesitate to ask!

Best regards,


1 Like