Nullability annotations in ORM code base #6220
Replies: 2 comments 3 replies
-
Not-null by default. If we're going to do it, do it properly.
So the first and third items here only call for adding nullability annotations to out APIs, and don't require us to spray them over the whole codebase, which is a much bigger job, and I'm sort-of a bit skeptical that we will ever "finish" such a huge undertaking. |
Beta Was this translation helpful? Give feedback.
-
Ok, so we decided to use JSpecify annotations and try to work through package by package. Created https://hibernate.atlassian.net/browse/HHH-16389 |
Beta Was this translation helpful? Give feedback.
-
I'd like to make sure the Hibernate ORM code base makes use of
@Nullable
or@NotNull
(depending on what we decide for our default) for a few reasons:The last point is actually what finally drove me to create this discussion. There are talks about exposing value storage optimizations to the Java language through the mechanism of nullability markers on parameters, return types, fields and local variables. It kind of makes sense that flat storage requires the type to be non-nullable. There are tricks the JVM can apply to encode nullability in unused bits, but the best possible performance can only be achieved by actually making sure that something is non-nullable.
Valhalla is still far away, but since the introduction of such annotations in a code base like ORM is not an easy undertaking and will take some time, I'm starting a discussion now, so that we can start working on this as soon as we decided on the approach. Nullability information will help us anyway. I guess we just shied away from tackling this because it is probably going to be a long process.
Here are a few questions to discuss:
Here is my take on it:
RUNTIME
, but as far as I understood from a lengthy discussion, we can still use acompileOnly
dependency without causing trouble, so no new dependency for users.@NullUnmarked
, we can default to non-null by default and exclude certain packages from that default.Beta Was this translation helpful? Give feedback.
All reactions