Skip to content

NullPointerException in InjectionMetadata [SPR-7686] #12342

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 Oct 26, 2010 · 6 comments
Closed

NullPointerException in InjectionMetadata [SPR-7686] #12342

spring-projects-issues opened this issue Oct 26, 2010 · 6 comments
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 Oct 26, 2010

Christophe Roudet opened SPR-7686 and commented

When using SpringBeanAutowiringSupport.processInjectionBasedOnServletContext()
a NullPointerException is raised in
InjectionMetadata.checkPropertySkipping(PropertyValues pvs)

protected boolean checkPropertySkipping(PropertyValues pvs) {
  if (this.skip == null) {
    synchronized (pvs) { // <-- NullPointerException
      if (this.skip == null) {

in AutowiredAnnotationBeanPostProcessor.processInjection(Object bean)
metadata inject is called with null for PropertyValues

public void processInjection(Object bean) throws BeansException {
  Class<?> clazz = bean.getClass();
  InjectionMetadata metadata = findAutowiringMetadata(clazz);
  try {
    metadata.inject(bean, null, null); // <-- pvs is null
  }
  catch (Throwable ex) {
    throw new BeanCreationException("Injection of autowired dependencies failed for class [" + clazz + "]", ex);
  }
}

Here is the stack trace:

java.lang.NullPointerException
 	at org.springframework.beans.factory.annotation.InjectionMetadata$InjectedElement.checkPropertySkipping(InjectionMetadata.java:171)
 	at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredMethodElement.inject(AutowiredAnnotationBeanPostProcessor.java:526)
 	at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:84)
 	at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.processInjection(AutowiredAnnotationBeanPostProcessor.java:300)
 	at org.springframework.web.context.support.SpringBeanAutowiringSupport.processInjectionBasedOnServletContext(SpringBeanAutowiringSupport.java:110)

Affects: 3.0.5

Issue Links:

Referenced from: commits 9c64ac7

1 votes, 4 watchers

@spring-projects-issues
Copy link
Collaborator Author

spring-projects-issues commented Nov 1, 2010

Christophe Roudet commented

I think it is related to the fix for #12298.

@spring-projects-issues
Copy link
Collaborator Author

Henrik Heimbuerger commented

First of all, this not only affects processInjectionBasedOnServletContext(), but also processInjectionBasedOnCurrentContext().

Why is this prioritized as minor? It completely breaks the subclassing of SpringBeanAutowiringSupport, because its constructor always calls processInjectionBasedOnCurrentContext(). I don't see how I could upgrade to 3.0.5 as long as this bug is in place.

Is there an easy workaround that I'm missing, except for not using SpringBeanAutowiring at all?

@spring-projects-issues
Copy link
Collaborator Author

Christophe Roudet commented

If you can put the annotations on the fields rather than on the methods, it will work.

  @Autowired
  public void setXXXX(XXXX xxxx) {
    this.xxxx = xxxx;
  }

  ...

--->

  @Autowired
  private XXXX xxxx;

  ...

@spring-projects-issues
Copy link
Collaborator Author

Henrik Heimbuerger commented

As I said, the problem is not @Autowired, it's subclassing SpringBeanAutowiringSupport. (Or at least I'm not getting to the point where @Autowired would be a problem because of that.)

@spring-projects-issues
Copy link
Collaborator Author

Florian Feigenbutz commented

Henrik, as Christophe said you can bypass this bug in 3.0.5 by placing the @Autowired annotations to the fields instead of the setter methods.

This causes Spring to use the inject() method of
org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.AutowiredFieldElement
instead of
org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.AutowiredMethodElement

As the bug only affects the latter one no NPEs should be caused even if you're subclassing SpringBeanAutowiringSupport.

@spring-projects-issues
Copy link
Collaborator Author

Paul Benedict commented

Anymore 3.0 maintenance releases coming out? Can this be backported? -- Nevermind, I see it's fixed in 3.0.6.

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