Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NotNull annotations #170

Open
spand opened this issue Jan 15, 2021 · 4 comments
Open

NotNull annotations #170

spand opened this issue Jan 15, 2021 · 4 comments

Comments

@spand
Copy link
Contributor

spand commented Jan 15, 2021

I searched the issues but seems uncovered. Has it been considered to add NotNull annotations to various methods, parameters and such?

We use the library from Kotlin and having nullability explicit in the api would be really nice.

In any case, thanks for the awesome library!

@jodastephen
Copy link
Member

I'm not a fan of those annotations myself. IMO they are not checked without tooling and thus they provide false reassurance.

I'm reluctant to offer to accept a PR, as that would mean I would have to maintain the annotations going forward, and would have to ensure they are correct on all new additions.

@spand
Copy link
Contributor Author

spand commented Jan 18, 2021

I mostly see them as documentation as code. As you maybe allude to they can be quite disruptive if actually incorrect (nullable marked as NotNull, opposite seems harmless) but coming from Kotlin I see the benefits of explicit nullability every day and is obviously quite a fan of it.

The problem is not big though as you have been quite good at keeping null values out of the API but I would argue that the documentation is sort of missing in the places you would add the annotation. The example that triggered me to actually discover the annotations weren't present as I had assumed was methods like Interval.getStart(), Interval.getEnd(). You could argue the it follows from the factory methods but having the info when you need it is preferable since with Java apis you just never know.

I understand your concern as the maintainer. Maybe others can provide more persuasive argument in the future.

Kind regards

@jodastephen
Copy link
Member

Feel free to raise a PR to add ", can return null" or ", not null" to the end of Javadoc @return if that helps you

@sdavids
Copy link

sdavids commented Apr 21, 2024

I suggest to use jspecify once it is 1.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

3 participants