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.

Use the @Nullable annotation on fields too

See original GitHub issue

Spring 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:closed
  • Created 7 years ago
  • Reactions:2
  • Comments:18 (18 by maintainers)

github_iconTop GitHub Comments

1reaction
gavinkingcommented, Sep 12, 2017

@xkr47 You can, but it’s been designed so that that should never be necessary.

0reactions
xkr47commented, Sep 12, 2017

So can you annotate i.e. whether Ceylon class annotations end up getting attached to the class, the constructor or both?

Read more comments on GitHub >

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

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