Use the @Nullable annotation on fields too
See original GitHub issueSpring 5 (currently in M4) is going to support Kotlin’s nullable types when injecting beans. Under the hood, it will look for any @Nullable
annotation on autowired fields. That’s great, except it doesn’t work on Ceylon declarations, because we put @Nullable
on $priv$
getters but not on the actual field for code like this:
class MyClass() {
autowired late IService? myService;
}
In such classes, Spring will use the field because there’s no public getter (only a getMyService$priv()$
method).
It might be interesting to add another @Nullable
annotation on the field to leverage that new feature in Spring core.
Issue Analytics
- State:
- Created 7 years ago
- Reactions:2
- Comments:18 (18 by maintainers)
Top Results From Across the Web
java - How to use @Nullable and @Nonnull annotations more ...
Short answer: I guess these annotations are only useful for your IDE to warn you of potentially null pointer errors.
Read more >Protect Your Code from NullPointerExceptions with Spring's ...
We can express our intention using the @Nullable annotation on the field. This will tell the IDE that the field can be null...
Read more >Spring Null-Safety Annotations - Baeldung
The @NonNullFields annotation is generally preferable to @NonNull as it helps reduce boilerplate. At times we want to exempt some fields from ...
Read more >Optionally generate @Nullable annotation for column getters
eq(Field) can be annotated @Nullable as jOOQ can handle this, too. This is will be done in #6244 (perhaps in 3.10, certainly in...
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
@xkr47 You can, but it’s been designed so that that should never be necessary.
So can you annotate i.e. whether Ceylon class annotations end up getting attached to the class, the constructor or both?