-
Notifications
You must be signed in to change notification settings - Fork 704
SONARJAVA-5803 JSpecify @NullUnmarked should be treated as unknown #5327
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,6 @@ | ||
| { | ||
| "ruleKey": "S2638", | ||
| "hasTruePositives": true, | ||
| "falseNegatives": 22, | ||
| "falseNegatives": 20, | ||
| "falsePositives": 0 | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,6 @@ | ||
| { | ||
| "ruleKey": "S2789", | ||
| "hasTruePositives": true, | ||
| "falseNegatives": 43, | ||
| "falseNegatives": 35, | ||
| "falsePositives": 0 | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,6 @@ | ||
| { | ||
| "ruleKey": "S4682", | ||
| "hasTruePositives": true, | ||
| "falseNegatives": 10, | ||
| "falseNegatives": 2, | ||
| "falsePositives": 0 | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -262,7 +262,7 @@ class InnerClassTests { | |
| class InnerNullmarked { | ||
| @NullMarked // Compliant | ||
| class Inner { | ||
| @NonNull Object o; // Noncompliant {{Remove redundant annotation @NonNull as inside scope annotation @NullMarked at class level.}} | ||
| @NonNull Object o; // Compliant | ||
| @Nullable Object o2; // Compliant | ||
| } | ||
| } | ||
|
|
@@ -272,7 +272,7 @@ class InnerNullUnmarked { | |
| @NullUnmarked | ||
| class Inner { | ||
| @NonNull Object o; // Compliant | ||
| public void methodNonNullParamTyped(List<@Nullable Object> o) { // Noncompliant {{Remove redundant annotation @Nullable as inside scope annotation @NullUnmarked at class level.}} | ||
| public void methodNonNullParamTyped(List<@Nullable Object> o) { // Compliant | ||
| // .. | ||
| } | ||
| } | ||
|
|
@@ -282,7 +282,7 @@ public void methodNonNullParamTyped(List<@Nullable Object> o) { // Noncompliant | |
| class InnerRedundantNullMarked { | ||
| @NullMarked // Compliant | ||
| class Inner { | ||
| @NullMarked // Noncompliant {{Remove redundant annotation @NullMarked at class level as inside scope annotation @NullMarked at class level.}} | ||
| @NullMarked // Compliant | ||
|
||
| class InnerInner {} | ||
| } | ||
| } | ||
|
|
@@ -291,19 +291,19 @@ class InnerInner {} | |
| class InnerRedundantNullUnmarked { | ||
| @NullUnmarked // Compliant | ||
| class Inner { | ||
| @NullUnmarked // Noncompliant {{Remove redundant annotation @NullUnmarked at class level as inside scope annotation @NullUnmarked at class level.}} | ||
| @NullUnmarked // Compliant | ||
|
||
| class InnerInner {} | ||
| } | ||
| } | ||
| } | ||
|
|
||
| @NullUnmarked | ||
| class InnerClassTestsTwo { | ||
| @NullUnmarked // Noncompliant {{Remove redundant annotation @NullUnmarked at class level as inside scope annotation @NullUnmarked at class level.}} | ||
| @NullUnmarked // Compliant | ||
| class InnerNullmarked { | ||
| @NullMarked // Compliant | ||
| class Inner { | ||
| @NonNull Object o; // Noncompliant {{Remove redundant annotation @NonNull as inside scope annotation @NullMarked at class level.}} | ||
| @NonNull Object o; // Compliant | ||
| @Nullable Object o2; // Compliant | ||
| } | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,13 +19,10 @@ abstract class PrimitivesMarkedNullableCheckSample { | |
| abstract int getInt2(); | ||
|
|
||
| @NullUnmarked | ||
| protected abstract boolean isBool(); // Noncompliant {{"@NullUnmarked" annotation should not be used on primitive types}} [[quickfixes=qf1]] | ||
| // ^^^^^^^ | ||
| // fix@qf1 {{Remove "@NullUnmarked"}} | ||
| // edit@qf1 [[sl=-1;el=+0;sc=3;ec=3]] {{}} | ||
| protected abstract boolean isBool(); // Compliant - NullUnmarked doesn't add any information about nullability | ||
|
Comment on lines
21
to
+22
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think using
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think the test was there to assert how the check "PrimitivesMarkedNullableCheck" behave in presence of "@NullMarked" / "@NullUnmarked" annotations, so I'm not sure we should replace it with "@nullable" because it's already asserted inside "checks/PrimitivesMarkedNullableCheckSample". So maybe we should just remove this test file
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I eventually decided to let the existing testcase and just replace the Noncompliant -> Compliant, to still verify we don't raise FPs |
||
|
|
||
| @NullUnmarked | ||
| public double getDouble1() { return 0.0; } // Noncompliant {{"@NullUnmarked" annotation should not be used on primitive types}} | ||
| public double getDouble1() { return 0.0; } // Compliant - NullUnmarked doesn't add any information about nullability | ||
|
|
||
| public double getDouble2() { return 0.0; } | ||
|
|
||
|
|
@@ -49,10 +46,7 @@ abstract class PrimitivesMarkedNullableCheckSample { | |
|
|
||
| public Object getObj2() { return null; } | ||
|
|
||
| protected abstract @NullUnmarked boolean isBool2(); // Noncompliant {{"@NullUnmarked" annotation should not be used on primitive types}} [[quickfixes=qf3]] | ||
| // ^^^^^^^ | ||
| // fix@qf3 {{Remove "@NullUnmarked"}} | ||
| // edit@qf3 [[sc=22;ec=36]] {{}} | ||
| protected abstract @NullUnmarked boolean isBool2(); // Compliant - NullUnmarked doesn't add any information about nullability | ||
|
|
||
| @NullUnmarked | ||
| Object containsAnonymousClass() { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I am not mistaken, this is indeed noncompliant.
As the class is annotated with
@NullMarked, everything is assumed to be nonnull except if it is annotated with@Nullable.So
@NonNullis redundant.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed, thanks for catching this!