S3824 "Map.get" and value test should be replaced with single method call - should also check for containsKey()

  • versions used (SonarQube, Scanner, Plugin, and any relevant extension)
    SonarQube 6.7.6
    SonarJava 5.11


This is actually a false-negative. Please let me know if there’s a more appropriate place to post this.

S3824 tries to find places where the developer uses a get(), check for null, and then put() instead of the more efficient computeIfAbsent(). This rule should also detect if the developer used containsKey(), which is effectively the same as the get()/check for null.

void abc(Map<String, Object> map, String key) {
  if (!map.containsKey(key)) {
    map.put(key, new Object());


Thanks for the feedback! The ticket is created to fix this False Negative.

Awesome! Thanks.