Skip to content

NPE in AnnotationAwareOrderComparator.getPriority [SPR-16508] #21051

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

Closed
spring-projects-issues opened this issue Feb 16, 2018 · 2 comments
Closed
Assignees
Labels
in: core Issues in core modules (aop, beans, core, context, expression) type: bug A general bug
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

spring-projects-issues commented Feb 16, 2018

Mario Hochreiter opened SPR-16508 and commented

The null check in spring 5 was removed. In my project a bean is returning null. It is marked as Nullable, nevertheless the container startup fails due to a NPE at line 109 in AnnotationAwareOrderComparator of 5.0.3.

Code in 4.3.12:

public Integer getPriority(Object obj) {
     Integer priority = null;
     if (obj instanceof Class) {
          priority = OrderUtils.getPriority((Class<?>) obj);
     }
     else if (obj != null) {
          priority = OrderUtils.getPriority(obj.getClass());
          if (priority == null && obj instanceof DecoratingProxy) {
               priority = OrderUtils.getOrder(((DecoratingProxy) obj).getDecoratedClass());
          }
     }
     return priority;
}

Now in 5.0.3:

public Integer getPriority(Object obj) {
     if (obj instanceof Class) {
          return OrderUtils.getPriority((Class<?>) obj);
     }
     Integer priority = OrderUtils.getPriority(obj.getClass());
     if (priority == null && obj instanceof DecoratingProxy) {
          priority = OrderUtils.getOrder(((DecoratingProxy) obj).getDecoratedClass());
     }
     return priority;
}

Affects: 5.0.3

Issue Links:

Referenced from: commits c9d08bf

@spring-projects-issues
Copy link
Collaborator Author

Juergen Hoeller commented

I suppose this happens within DefaultListableBeanFactory.determineHighestPriorityCandidate, for a bean instance that happens to resolve to null? We could also defensively bypass the entire getPriority call for null values at that level.

@spring-projects-issues
Copy link
Collaborator Author

Mario Hochreiter commented

Exactly. The bean is annotated with @Nullable, also on the inject side it is annoted with @Nullable. If only 1 possibly matching bean exists than all is good, but as soon as more than 1 probably matching bean exists above code is executed and throws a NPE.

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: bug A general bug
Projects
None yet
Development

No branches or pull requests

2 participants