fb-contrib
fb-contrib copied to clipboard
fb-contrib:PMB_POSSIBLE_MEMORY_BLOAT should not appear where there is no option to mutate the collection
my case has two issues related to this check,
- The docs appears to refer to collection or StringBuffer but not to a Map
- The warning should not appear where there is no option to bloat.
In the following scenario if putUnique
was public there were an option to bloat the Map,
yet since putUnique
is private and roleMapping
is private then roleMapping
field is immutable.
public class Example{
private static final Map<String, String> roleMapping = new HashMap<>();
static {
putUnique("Jhon", "User");
putUnique("Kate", "Manager");
putUnique("Gorge", "Supervisor");
}
public String getRole(String first) {
return roleMapping.get(first);
}
private static void putUnique(String first, String last ) {
String previous = roleMapping.put(first, last);
if (previous != null) {
throw new IllegalArgumentException("Duplicate key");
}
}
}