Skip to content
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

Assert preconditions for MergedAnnotations.from() factory methods #25568

Closed
sbrannen opened this issue Aug 8, 2020 · 0 comments
Closed

Assert preconditions for MergedAnnotations.from() factory methods #25568

sbrannen opened this issue Aug 8, 2020 · 0 comments
Assignees
Labels
in: core Issues in core modules (aop, beans, core, context, expression) type: enhancement A general enhancement
Milestone

Comments

@sbrannen
Copy link
Member

sbrannen commented Aug 8, 2020

If null values are supplied for the RepeatableContainers or AnnotationFilter arguments to from() factory methods in MergedAnnotations, certain operations will eventually result in a NullPointerException.

This is to be expected; however, the NullPointerException is often swallowed and only logged at INFO level with an exception message similar to the following.

Failed to introspect annotations on org.example.MyClass: NullPointerException

In such cases, the INFO log message is not helpful in diagnosing the problem. Furthermore, since the exception is swallowed, the desired operation (e.g., MergedAnnotations.stream(...)) simply returns no
results, and the user is left wondering what happened.

@sbrannen sbrannen added in: core Issues in core modules (aop, beans, core, context, expression) type: enhancement A general enhancement labels Aug 8, 2020
@sbrannen sbrannen added this to the 5.2.9 milestone Aug 8, 2020
@sbrannen sbrannen self-assigned this Aug 8, 2020
FelixFly pushed a commit to FelixFly/spring-framework that referenced this issue Aug 16, 2020
Prior to this commit, if null values were supplied for the
RepeatableContainers or AnnotationFilter arguments to `from()` factory
methods in MergedAnnotations, certain operations would eventually
result in a NullPointerException. This is to be expected; however, the
NullPointerException is often swallowed and only logged at INFO level
with an exception message similar to the following.

> Failed to introspect annotations on org.example.MyClass: NullPointerException

In such cases, the INFO log message is not helpful in diagnosing the
problem. Furthermore, since the exception is swallowed, the desired
operation (e.g., MergedAnnotations.stream(...)) simply returns no
results.

This commit improves the user experience by eagerly asserting non-null
preconditions for required arguments in MergedAnnotations.from()
factory methods.

Closes spring-projectsgh-25568
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core Issues in core modules (aop, beans, core, context, expression) type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

1 participant