question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add support for Nullable as a TYPE_USE annotation

See original GitHub issue

I 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:open
  • Created 5 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
cpovirkcommented, Oct 25, 2021

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?)

1reaction
cpovirkcommented, Jan 25, 2021

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found