-
Notifications
You must be signed in to change notification settings - Fork 299
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
Fix handling of java.lang.Void
and enable a couple more Error Prone checks
#586
Conversation
Pull Request Test Coverage Report for Build #814
💛 - Coveralls |
@@ -72,6 +72,8 @@ subprojects { project -> | |||
check("StringSplitter", CheckSeverity.OFF) | |||
check("WildcardImport", CheckSeverity.ERROR) | |||
check("MissingBraces", CheckSeverity.ERROR) | |||
check("TypeToString", CheckSeverity.ERROR) | |||
check("SymbolToString", CheckSeverity.ERROR) |
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.
Interesting, these are all suggestion-level, so even with -Werror
, we don't get them by default...
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.
Yup. I found these just browsing through the available checks one day a while back
@@ -178,6 +179,8 @@ | |||
// Unmatched, used for when we only want full checker suppressions to work | |||
static final String CORE_CHECK_NAME = "NullAway.<core>"; | |||
|
|||
private static final Supplier<Type> JAVA_LANG_VOID = Suppliers.typeFromString("java.lang.Void"); |
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.
There's also Suppliers.VOID_TYPE
, which looking at the implementation may be more efficient. (Uses state.getSymtab().voidType
.)
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.
Oh, or is that the non-boxed variant? In that case, nevermind.
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.
There is Suppliers#JAVA_LANG_VOID_TYPE
which I think does what we want. Thanks for the tip!
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.
Missed that one 🤦. Nice!
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.
In the end I realized we really meant to be checking for the unboxed type! 🙂 And there is an isPrimitiveOrVoid()
method for doing that.
We now report an error for this code in NullAway/nullaway/src/test/resources/com/uber/nullaway/testdata/NullAwayNegativeCases.java Lines 440 to 442 in 4a426db
I think this is just wrong and we messed up before. In fact, since the return type is |
Arguably |
@msridhar JSpecify currently says "No special treatment" for Is this technically the first NullAway question, unrelated to direct efforts to support JSpecify, that is settled by referring to the standard? 😉 |
First time! So cool to have a standard 😄 |
java.lang.Void
and enable a couple more Error Prone checks
Asking for a new review @lazaroclapp since the main purpose of this PR has changed 🙂 We should note this change in the release notes, as after updating to the next release, users will have to add |
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.
LGTM
This reverts the user-visible change from #586. We have found use cases involving generics and method overriding where requiring writing of `@Nullable Void` currently requires adding some ugly error suppressions. We need to think through those cases more carefully before requiring `@Nullable` on `Void`. To be clear, this restored handling of `Void` is unsound. We treat a `Void` return type as `@Nullable Void` when checking `return` statements (so they are allowed to return `null`), but at call sites of methods with a `Void` return type, we assume the method will return a `@NonNull` value. Also, if an overriding method has return type `Void`, we treat it as `@NonNull Void`, which leads to unsound checking of method subtyping.
We now require the developer to write
@Nullable
on usages ofjava.lang.Void
, consistent with JSpecify (see jspecify/jspecify#51).This issue was discovered while enabling two new Error Prone checks,
TypeToString and SymbolToString.