diff --git a/sonar-java-plugin/src/main/resources/org/sonar/l10n/java/rules/java/S5411.html b/sonar-java-plugin/src/main/resources/org/sonar/l10n/java/rules/java/S5411.html index 60b88f91231..6e1b7f8ef72 100644 --- a/sonar-java-plugin/src/main/resources/org/sonar/l10n/java/rules/java/S5411.html +++ b/sonar-java-plugin/src/main/resources/org/sonar/l10n/java/rules/java/S5411.html @@ -4,7 +4,7 @@
NullPointerException
if the value is null
(as defined in Java Language Specification §5.1.8 Unboxing Conversion).
It is safer to avoid such conversion altogether and handle the null
value explicitly.
Note, however, that no issues will be raised for Booleans that have already been null-checked.
+Note, however, that no issues will be raised for Booleans that have already been null-checked or are marked @NonNull/@NotNull
.
Boolean b = getBoolean(); @@ -29,6 +29,30 @@+Compliant solution
String test = b ? "test" : ""; }
The issue is not raised if the expression is annotated @NonNull
/ @NotNull
. This is useful if a boxed type is an
+instantiation of a generic type parameter and cannot be avoided.
+List<Boolean> list = new ArrayList<>(); +list.add(true); +list.add(false); +list.forEach((@NonNull Boolean value) -> { + // Compliant + if(value) { + System.out.println("yes"); + } +}); + +@NonNull Boolean someMethod() { /* ... */ } + +// Compliant +if(someMethod()) { /* ... */ } + +@NonNull Boolean boxedNonNull = Boolean.TRUE; + +// Compliant +if(boxedNonNull) { /* ... */ } +