Language: Java
Rule: S2589
Product: SonarQube Community Edition Version 25.2 and SonarQube IDE
Description:
When getting a value from a Map it can never be assumed that the result must be NonNull.
Code Snipet:
import java.util.List;
import java.util.Map;
import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.jdt.annotation.Nullable;
public class S2589Test {
public void test(Map<Long, List<@NonNull String>> testMap) {
List<@NonNull String> list = testMap.get(Long.valueOf(17));
// Remove this expression which always evaluates to "true"
if (list != null) {
System.err.println("[S2589Test] test - " + list.toString());
}
}
}
The analysis seems to be thrown off course by the ‘NonNull String’. If this is removed then SonarQube does not show an error.