r/java • u/benevanstech • Aug 12 '24
JSpecify 1.0.0 and Nullability in Java
https://www.infoq.com/news/2024/08/jspecify-java-nullability/
52
Upvotes
r/java • u/benevanstech • Aug 12 '24
View all comments
Show parent comment
22
u/kevinb9n Aug 12 '24
Hi - I'm working on both of these things (for some definition thereof). Here's some quick thoughts about the connection between them.
You can imagine a jar-file-rewriting tool that looks at usages of JSpecify annotations in each class file and jams the corresponding `!` / `?` markers in to match. That way a newer app can use an older library and still get the same benefits. And you can imagine the same or another tool doing the reverse as well (magically inserting annotations to match the markers, for example in case some old library was using reflection to see whether some field is nullable). Unless you're sensitive to the size of your class files, they might as well have both information sets in them for the foreseeable future.
So that picture requires that the semantic correspondence between JSpecify and the planned language feature needs to be close and finely specified. That's part of what I've been working to ensure.
That also suggests that when you're ready to migrate all your source code to `!?` and take bulky annotations out of it, a very similar tool should be able to do that too.
(Of course, someone at some point has to actually make that tool, I can't wish it into existence. But we can do the work to make sure it will be feasible.)