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.

@NonNull and @Nullable annotations on parameters and return types

See original GitHub issue

I think adding @NonNull and @Nullable annotations to the source code would be very helpful documentation. It would also allow better Kotlin interoperability, since the Kotlin compiler can recognize these annotations. There are already a few places where the javadoc indicates that a parameter may be null but it’s far from being widespread.

For example the Batch in draw method and the events in event listeners are never null. These are obvious, but there are many cases where all the usages of a method but be looked at to know whether the parameter type is nullable or not. Kotlin also marks the Color and Interpolation constants as potentially nullable.

I understand that adding these annotations to every public method would be a very big undertaking, but I think it would prove to be very useful.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:6
  • Comments:7 (7 by maintainers)

github_iconTop GitHub Comments

5reactions
Darkyenuscommented, May 4, 2020

I have recently added them to Spigot API (for Minecaft server mods). It took about 30 hours, but I did find some bugs and I think that their API is now better for it. I think that this would be a good-first-issue (especially if it is split up into multiple smaller PRs), but someone (=core contributor) must first decide, which annotations should be used, as there is a lot of options, and all have their pros and cons. I outlined some of the options in the issue linked above, and ended up using the Jetbrains flavored ones, but libGDX may have a different needs and decide differently.

0reactions
Blunderchipscommented, May 4, 2020

Can this issue be closed seeing that https://github.com/libgdx/libgdx/pull/5812 has been merged in?

Read more comments on GitHub >

github_iconTop Results From Across the Web

@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 >
Annotations for Nullable and NonNull return values ... - GitHub
Nullable and NonNull annotations can be used by the major IDEs and by Kotlin to determine nullability. The Kotlin compiler even infers the...
Read more >
java - How to use @Nullable and @Nonnull annotations more ...
Suggest @Nullable annotation for methods that may possibly return null and report nullable values passed to non-annotated parameters Inspections.
Read more >
Nullable & NonNull - Medium
The @NonNull/@Nullable annotation can put in front of functions as well to indicate the return value nullability. @NonNull public A getA() {
Read more >
JML Tutorial - Nullable and non-null values and types
Type annotations and arrays ... @NonNull String @Nullable [] s;. declares s to have the type possibly null array of non-null String values....
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