Add support for Nullable as a TYPE_USE annotation
See original GitHub issueI wanted to switch from JSR305 to Checker Framework @Nullable
, but it breaks my @Nullable
injection points:
1) null returned by binding at […]
but the 1st parameter of […].<init>([…]) is not @Nullable
Apparently, this is because Guice only looks at field and parameter annotations, not TYPE_USE annotations: https://github.com/google/guice/blob/eface212cdf3eeb1579d6e033cd54fd1426d65ba/core/src/com/google/inject/spi/InjectionPoint.java#L117-L119
Note: I couldn’t use the Java 7-compatible annotations from the Checker Framework either because it’s named @NullableDecl
, and Guice only looks at annotations named @Nullable
.
Issue Analytics
- State:
- Created 5 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Nullable reference types - Microsoft Learn
This article provides an overview of nullable reference types. You'll learn how the feature provides safety against null reference ...
Read more >Annotating your C# code - Migrating to nullable reference types
Today, let's look at the many options for annotating your code and various ways to help the flow analysis understand your code. As...
Read more >The annotation for nullable reference types should only be ...
Nullable contexts enable fine-grained control for how the compiler interprets reference type variables. The nullable annotation context of ...
Read more >Add nullability annotations also to generic type variables and ...
Adding type use annotations is much more laborious and harder to integration test than the existing method annotations; This is even worse for...
Read more >@Nullable and @NotNull | IntelliJ IDEA Documentation
@Nullable and @NotNull annotations let you check nullability of a variable, parameter, or return value. They help you control contracts ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
It looks to me like 5.0.0 (though use 5.0.1 instead), released earlier this year, contains the change that lets you write
@Nullable Foo foo
for type-use annotations as well as for declaration annotations.As discussed above, Guice could theoretically do more with type-use annotations, but this at least makes them not worse than declaration annotations. Possibly that’s enough to close this issue.
Anyone who migrates from declaration annotations to type-use annotations may need to move some annotations along the way:
@Nullable Foo[] foo
->Foo @Nullable [] foo
@Nullable Foo.Bar bar
->Foo.@Nullable Bar bar
(That’s just how type-use-annotation syntax works.)
(I don’t see mention of this in the release notes. Maybe it should be added?)
There are a lot of things that “Guice supports
@Nullable
type annotations” could mean, but https://github.com/google/guice/commit/1a410a8bef1ec721e16f9f16a447235f09951f05 accomplished the main one. I assume there hasn’t been a release yet, though.