In https://github.com/spring-projects/spring-boot/issues/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 use javax.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:

@Endpoint(id = "endpoint")
final class Endpoint {

    @WriteOperation
    void adjust(@Selector someSelector, @Nullable optionalParameter) {
        ...
    }

}

The @Nullable annotation was migrated from org.springframework.lang.Nullable to javax.annotation.Nullable, and thus support for the optional parameter broke as a result of: https://github.com/spring-projects/spring-boot/blob/1fb32fcf7af1a3df4c2c02db8c0a71c98f6ec169/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/invoke/reflect/OperationMethodParameter.java#L58

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.

Comment From: philwebb

I think we could consider this a bug. It seems reasonable that you should be able to use javax.annotation.Nullable.

Comment From: snicoll

I've updated the reference guide to mention the support of JSR-305 in https://github.com/spring-projects/spring-boot/commit/2bd78355dc7213cf7049487bf05fde0a741d85c4

Comment From: nathankooij

Thanks for the quick fix!

Comment From: knoobie

@snicoll Am I missing something or did you mention the wrong annotation? Nonnull instead of Nullable - it means quite the opposite?

Comment From: snicoll

@knoobie thanks for the nudge! This is me trying to be helpful without having my coffee. I'll polish to mention both @Nullable. I'll wait for @philwebb as there is something that uses Nonnull explicitly.

Comment From: philwebb

I've added a test that shows @Nonnull works as expected. Thanks for the doc updates @snicoll