-
Notifications
You must be signed in to change notification settings - Fork 746
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
ReturnMissingNullable should ignore @DoNotCall and always throwing methods #2910
Comments
Thanks. I'd wondered if this would be an issue, but I should have looked into it more at the time. Probably I didn't take it seriously enough because, inside Google, we're rolling out these changes automatically, so there's relatively little cost to adding As it happens, I looked at all the findings for this kind of method about a month ago. I ended up finding a lot of "interesting" However, I've delayed in submitting that CL because we're still planning to roll out even those Once I do submit it, this problem will go away for normal users. However, I should still look at implementing your suggestions. Those would help users who do set |
Thanks for your response! I in principle would have no problem with letting Error Prone automatically insert the missing I would also like to point out that this check did find a handful of actually missing Regarding |
Thanks for sharing more from your experiences. Maybe I can try keeping the handling of While we're on the topic, one other point about |
Some quick testing on Google's codebase suggests that this particular exception is highly justified :(
error-prone/core/src/main/java/com/google/errorprone/bugpatterns/nullness/ReturnMissingNullable.java Lines 320 to 323 in 9941ae5
Hopefully you'll have a better experience if you set (I hope to report back about the type-variable case later today.) |
Interesting. I don't think we have any stubs like this. (And if there were, I would like to find them.) For the above mentioned smaller project of us, using |
The type-variable case turns out to be more interesting. Nearly all the findings from it are correct, but there are some patterns that lead to false positives. For example: static <T> T clone(T t) {
if (t == null) {
return null;
}
...
} Here, the output is null only if the input is. The best way to annotate such a method would be to say that it both accepts and returns "plain I want to look more into the type-variable case someday. For now, I'm going to leave it disabled in the conservative mode, and people can turn it on as desired. |
…le` _if_ the method can't be overridden. Anyone who calls such a method can definitely see a null result. In contrast, if the method were overridable, it might be only a "stub" that is overridden by all implementations to return non-null values. (Also, update the comment about such "stub" methods to reflect that they are indeed common enough to be a problem, as discussed in #2910 (comment)) PiperOrigin-RevId: 427259620
…le` _if_ the method can't be overridden. Anyone who calls such a method can definitely see a null result. In contrast, if the method were overridable, it might be only a "stub" that is overridden by all implementations to return non-null values. (Also, update the comment about such "stub" methods to reflect that they are indeed common enough to be a problem, as discussed in #2910 (comment)) PiperOrigin-RevId: 427291930
I don't think any of the Guava changes are user-visible. Details: - Many of these fix bugs that will be noticed by the forthcoming version of our hacky internal nullness checker. - Some of these fix bugs that even the forthcoming version won't notice but that I happened to see. - Some changes add `@Nullable` to return types of methods that always throw an exception. There's no strict need for this, but we've mostly done it otherwise, so I figured I'd be consistent (and quiet `ReturnMissingNullable`, at least until I quiet it for all such methods with google/error-prone#2910). - The `NullnessCasts` change is to discourage `ReturnMissingNullable` from adding a `@Nullable` annotation where we don't want it. (But we'll probably never run `ReturnMissingNullable` in the "aggressive" mode over this code, anyway, so there's not likely to be a need for the suppression.) - The `@ParametricNulless` changes evidently aren't necessary for anyone right now, but they could theoretically be necessary for j2objc users until j2objc further enhances its support for nullness annotations. - The `AbstractFuture` change removes a suppression that would be necessary under the Checker Framework (which would consider the supermethod's return type to be non-nullable) but isn't necessary for us (because we consider the supermethod's return type to have unspecified nullness). RELNOTES=n/a PiperOrigin-RevId: 421129392
I don't think any of the Guava changes are user-visible. Details: - Many of these fix bugs that will be noticed by the forthcoming version of our hacky internal nullness checker. - Some of these fix bugs that even the forthcoming version won't notice but that I happened to see. - Some changes add `@Nullable` to return types of methods that always throw an exception. There's no strict need for this, but we've mostly done it otherwise, so I figured I'd be consistent (and quiet `ReturnMissingNullable`, at least until I quiet it for all such methods with google/error-prone#2910). - The `NullnessCasts` change is to discourage `ReturnMissingNullable` from adding a `@Nullable` annotation where we don't want it. (But we'll probably never run `ReturnMissingNullable` in the "aggressive" mode over this code, anyway, so there's not likely to be a need for the suppression.) - The `@ParametricNulless` changes evidently aren't necessary for anyone right now, but they could theoretically be necessary for j2objc users until j2objc further enhances its support for nullness annotations. - The `AbstractFuture` change removes a suppression that would be necessary under the Checker Framework (which would consider the supermethod's return type to be non-nullable) but isn't necessary for us (because we consider the supermethod's return type to have unspecified nullness). RELNOTES=n/a PiperOrigin-RevId: 421129392
I don't think any of the Guava changes are user-visible. Details: - Many of these fix bugs that will be noticed by the forthcoming version of our hacky internal nullness checker. - Some of these fix bugs that even the forthcoming version won't notice but that I happened to see. - Some changes add `@Nullable` to return types of methods that always throw an exception. There's no strict need for this, but we've mostly done it otherwise, so I figured I'd be consistent (and quiet `ReturnMissingNullable`, at least until I quiet it for all such methods with google/error-prone#2910). - The `NullnessCasts` change is to discourage `ReturnMissingNullable` from adding a `@Nullable` annotation where we don't want it. (But we'll probably never run `ReturnMissingNullable` in the "aggressive" mode over this code, anyway, so there's not likely to be a need for the suppression.) - The `@ParametricNullness` changes evidently aren't necessary for anyone right now, but they could theoretically be necessary for j2objc users until j2objc further enhances its support for nullness annotations. - The `AbstractFuture` change removes a suppression that would be necessary under the Checker Framework (which would consider the supermethod's return type to be non-nullable) but isn't necessary for us (because we consider the supermethod's return type to have unspecified nullness). RELNOTES=n/a PiperOrigin-RevId: 421129392
I don't think any of the Guava changes are user-visible. Details: - Many of these fix bugs that will be noticed by the forthcoming version of our hacky internal nullness checker. - Some of these fix bugs that even the forthcoming version won't notice but that I happened to see. - Some changes add `@Nullable` to return types of methods that always throw an exception. There's no strict need for this, but we've mostly done it otherwise, so I figured I'd be consistent (and quiet `ReturnMissingNullable`, at least until I quiet it for all such methods with google/error-prone#2910). - The `NullnessCasts` change is to discourage `ReturnMissingNullable` from adding a `@Nullable` annotation where we don't want it. (But we'll probably never run `ReturnMissingNullable` in the "aggressive" mode over this code, anyway, so there's not likely to be a need for the suppression.) - The `@ParametricNullness` changes evidently aren't necessary for anyone right now, but they could theoretically be necessary for j2objc users until j2objc further enhances its support for nullness annotations. - The `AbstractFuture` change removes a suppression that would be necessary under the Checker Framework (which would consider the supermethod's return type to be non-nullable) but isn't necessary for us (because we consider the supermethod's return type to have unspecified nullness). RELNOTES=n/a PiperOrigin-RevId: 427818689
…` if those implementations always throw or they are `@DoNotCall`. Also, provide a different error message for this "implementations of well-known methods" case, one that is different from the usual "Method returns a definitely null value" message. (I considered continuing the make the suggestion in "aggressive" mode, but I'm not sure if it's worth the trouble even then, since it may lead to a discussion every time the suggestion appears.) Fixes #2910 PiperOrigin-RevId: 460746537
…ons of `Map.get`, etc. return `null`. This eliminates the problem reported in #2910 for users who run the normal ("conservative") mode, but arguably we should further address that issue by adding heuristics that apply in "aggressive" mode. PiperOrigin-RevId: 417689335
…ons of `Map.get`, etc. return `null`. This eliminates the problem reported in #2910 for users who run the normal ("conservative") mode, but arguably we should further address that issue by adding heuristics that apply in "aggressive" mode. PiperOrigin-RevId: 559861301
Sometimes we have methods that we need to implement due to an interface requiring them, but we do not want to support them and make them always throw, for example when implementing immutable collections. ReturnMissingNullable wants to add
@Nullable
in such cases if the interface method is known to be nullable, but this is useless. It would be nice if ReturnMissingNullable would ignore such cases.Concrete example:
ReturnMissingNullable from Error Prone 2.11.0 warns about all 3 methods:
Concrete suggestions:
@DoNotCall
or if the method implements a@DoNotCall
method from an interface.throw
should be possible, I guess.The text was updated successfully, but these errors were encountered: