Sonarcloud reports a false positive when using getIfNotPresent
from the Guava Cache
class:
com.google.common.cache.Cache<String, Boolean> cache;
...
var allowed = cache.getIfPresent(key);
if (allowed == Boolean.TRUE) {
...
} else if (allowed == Boolean.FALSE) {
...
}
The second condition will raise Remove this expression which always evaluates to “true” which is wrong. allowed
can be null because getIfPresent()
will return null
if the key does not exist.