spring-data-commons
spring-data-commons copied to clipboard
NulllableUtils only considers javax.annotation nullability annotations, should it also consider jakarta.annotation nullability annotations?
Greetings. I am upgrading from Spring Boot 2.7 to Spring Boot 3. That means I'm going from spring-data-commons:2.7.18
to spring-data-commons:3.2.5
. Additionally this upgrade is bringing along a Hibernate 5.4 to 6.4.4 migration. Hibernate 6+ is all in on jakarta.annotation
stuff.
In fact the automation my company wrote to help with the upgrade generously refactored all usages in my repo of javax.annotation
to jakarta.annotation
.
However, now a JPA query class I have is making org.springframework.data.repository.core.support.MethodInvocationValidator
sad because the method is annotated with jakarta.annotation.Nullable
but NullableUtils does evaluate that annotation when deciding whether something is or is not documented as "nullable".
Here are some questions to guide this discussion:
- It seems that this strategy of "if this one annotation class is on the classpath, then that must be the right one to use" is a bit...myopic. Especially given the code falls back to
org.springframework.lang.Nullable
,reactor.util.lang.NonNullApi
, andrg.springframework.lang.NonNullApi
if it can't findjavax.annotation.Nullable
. Is it fair to say "this strategy could be improved upon"? - Do you agree that the current state of NullabileUtils is at best a paper cut when upgrading to SB3 and Spring 6 (and at worst a blocker if you use spring-data-jpa)?
- Would you support an annotation resolution strategy that is as follows? a. Evaluate what nullability annotations are on the classpath (javax, jakarta, spring, reactor, spotbugs, findbugs, intellij, etc) b. When attempting to evaluate if a given parameter or return type are nullable, consult all annotations that are present on the method or parameter in a deterministic order, if any are present, use them. c. bonus points: if there is a disagreement in the annotations (e.g. both Nullable and Nonnull) throw an exception
I look forward to hearing back from you