Skip to content
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

Make @ChecksForNull an alias for @Nullable #397

Merged
merged 3 commits into from
Jun 10, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions nullaway/src/main/java/com/uber/nullaway/Nullness.java
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,8 @@ public static boolean isNullableAnnotation(String annotName, Config config) {
// and will replace `org.checkerframework` with `shadow.checkerframework`. Yes, really...
// I assume it's something to handle reflection.
|| annotName.endsWith(".checkerframework.checker.nullness.compatqual.NullableDecl")
// matches javax.annotation.CheckForNull and edu.umd.cs.findbugs.annotations.CheckForNull
|| annotName.endsWith(".CheckForNull")
|| (config.acknowledgeAndroidRecent()
&& annotName.equals("androidx.annotation.RecentlyNullable"));
}
Expand Down
28 changes: 28 additions & 0 deletions nullaway/src/test/java/com/uber/nullaway/NullAwayTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2492,4 +2492,32 @@ public void defaultLibraryModelsObjectNonNull() {
"}")
.doTest();
}

@Test
public void checkForNullSupport() {
compilationHelper
.addSourceLines(
"Nullable.java",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need this new test for the @Nullable annotation?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wanted to show that the same outputs are created for both SpotBugs annotations. But I can remove this test.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a comment to that effect (e.g. // This is just to check the behavior is the same between @Nullable and CheckForNull) then change the file name to TestNullable.java (it's not used elsewhere in the tests, but ideally classes should be in a file with the same name as the class and this is used as the file name that javac sees when compiling the test case, I believe 🙂 ).

Other than that, it looks good to go!

"package com.uber;",
"import javax.annotation.Nullable;",
"class TestNullable {",
" @Nullable",
" Object nullable = new Object();",
" public void setNullable(@Nullable Object nullable) {this.nullable = nullable;}",
" // BUG: Diagnostic contains: dereferenced expression nullable is @Nullable",
" public void run() {System.out.println(nullable.toString());}",
"}")
.addSourceLines(
"CheckForNull.java",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be TestCheckForNull.java, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I'll fix that. Is this value actually used somewhere?

"package com.uber;",
"import javax.annotation.CheckForNull;",
"class TestCheckForNull {",
" @CheckForNull",
" Object checkForNull = new Object();",
" public void setCheckForNull(@CheckForNull Object checkForNull) {this.checkForNull = checkForNull;}",
" // BUG: Diagnostic contains: dereferenced expression checkForNull is @Nullable",
" public void run() {System.out.println(checkForNull.toString());}",
"}")
.doTest();
}
}