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
JSR-305 @Nullable cannot be used to indicate that a parameter to an endpoint operation is optional #24647
Comments
I think we could consider this a bug. It seems reasonable that you should be able to use |
Endpoint
s with javax.annotation.Nullable
javax.annotation.Nullable
cannot be used to indicate that a parameter to an endpoint operation is optional
javax.annotation.Nullable
cannot be used to indicate that a parameter to an endpoint operation is optional@Nullable
annotations on endpoint methods
@Nullable
annotations on endpoint methods@Nullable
annotations on endpoint methods
@Nullable
annotations on endpoint methods
I've updated the reference guide to mention the support of JSR-305 in 2bd7835 |
Thanks for the quick fix! |
@snicoll Am I missing something or did you mention the wrong annotation? Nonnull instead of Nullable - it means quite the opposite? |
I've added a test that shows |
In #12020 support for optional parameters was introduced which is great. We have been using this happily for a while internally. Recently we decided as part of streamlining efforts to deduplicate several annotations that have been used (mostly) interchangeably within our code base. One such annotation was
@Nullable
. As we also have (Maven) modules that do not rely on Spring, we decided to only usejavax.annotation.Nullable
from that point on, because as far as we know, this is supported by Spring. After settling on this rule, and migrating our code base (where we have now banned the other annotations at the build level), a custom endpoint of the following form started to fail:The
@Nullable
annotation was migrated fromorg.springframework.lang.Nullable
tojavax.annotation.Nullable
, and thus support for the optional parameter broke as a result of:spring-boot/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/invoke/reflect/OperationMethodParameter.java
Line 58 in 1fb32fc
Now we realize that this is indeed documented as such here, so this is definitely not a bug report, but rather a feature request. This would allow us to keep the consistency within our code base and keep our strict rule set without having to support exceptions. Moreover, it could be less of a surprise for others since there's support for it in other parts of Spring. If it helps, I'm willing to do the legwork required and file a PR.
If any more info is required, let me know.
The text was updated successfully, but these errors were encountered: