r/java • • Aug 12 '24

JSpecify 1.0.0 and Nullability in Java

https://www.infoq.com/news/2024/08/jspecify-java-nullability/
52 Upvotes

33 comments sorted by

View all comments

2

u/pragmasoft Aug 12 '24

This has IMO the same problem as JPMS modules - adoption. In order to be useful, you need to have 100% of your dependencies including transitive ones annotated, or being able somehow to write some type definitions for 3rd party libraries, like Typescript does. Kotlin solves this differently, so without a language support JSpecify or any other nullability annotations simply add more harm than use.

5

u/kevinb9n Aug 12 '24

It's true that the more your dependencies are annotated, the more useful it becomes. But there is no "cliff" like you suggest. Nullness is tri-state: nullable, non-null, and "unspecified nullness" which is handled leniently. This makes it a lot easier to adopt than the original checker framework two-state, soundness-based approach. Any library that isn't providing the information just isn't going to be as well-validated, that's all.

And you can write type definitions for third-party libraries. Checker framework has a tool for reannotating class files, and I assume Google will opensource theirs when the demand is there. They use it to munge nullness annotations into JDK class files and it works!

I hope this changes your impression somewhat, but if not, sorry!

3

u/ventuspilot Aug 14 '24

But there is no "cliff" like you suggest.

Can confirm: in a toy project of mine I annotated a few methods to return @NotNull and IntelliJ Idea's inspections showed me a few unneeded null checks. Very little effort for immediate profit.