fb-contrib icon indicating copy to clipboard operation
fb-contrib copied to clipboard

NMCS_NEEDLESS_MEMBER_COLLECTION_SYNCHRONIZATION false positive

Open djelinski opened this issue 4 years ago • 2 comments

computeIfAbsent is not listed as modifyingMethod; as a result the following piece of code generates a false positive:

public abstract class CacheFbBug {

	private final Map<String, String> hashableStringCache;

	public CacheFbBug() {
		hashableStringCache = Collections.synchronizedMap(new HashMap<>());
	}

	public String getHashedString(String val) {
		return hashableStringCache.computeIfAbsent(val, this::hashString);
	}

	public abstract String hashString(String stringToHash);
}

djelinski avatar Jun 22 '20 10:06 djelinski

looking at https://download.java.net/java/early_access/jdk15/docs/api/java.base/java/util/Map.html I see a few more methods missing:

  • compute
  • computeIfAbsent
  • computeIfPresent
  • merge
  • putAll
  • putIfAbsent
  • replace
  • replaceAll

djelinski avatar Jun 22 '20 10:06 djelinski

would be nice to get this fixed 👍

andrei-ivanov avatar Sep 02 '20 10:09 andrei-ivanov