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

NPE if BeanPostProcessor returns null [SPR-6926] #11591

Closed
spring-projects-issues opened this issue Mar 3, 2010 · 2 comments
Closed

NPE if BeanPostProcessor returns null [SPR-6926] #11591

spring-projects-issues opened this issue Mar 3, 2010 · 2 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

Daniel Walcher opened SPR-6926 and commented

We have a BeanPostProcessor that converts configuration beans into their actual value, sometimes the value is a 'null'. This causes a NPE as other internal spring BeanPostProcessor's do not correctly handle a null value.

Is this a bug or are we doing something wrong?

For example the org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor#postProcessBeforeInitialization does not validate the bean, attempting to call 'bean.getClass()' which causes a NPE.

Should it not prevent running other post processors if the bean has been nulled? i.e.:

	public Object applyBeanPostProcessorsBeforeInitialization(Object existingBean, String beanName)
			throws BeansException {

		Object result = existingBean;
		for (BeanPostProcessor beanProcessor : getBeanPostProcessors()) {
			if (result == null) return;
			result = beanProcessor.postProcessBeforeInitialization(result, beanName);
		}
		return result;
	}

Also can someone confirm that the org.springframework.core.Ordered interface works for BeanPostProcessor. We have been unable to use this to create a work around, investigation has indicated that the logic seems to be missing to enforce ordering.


Affects: 3.0 GA, 3.0.1

Referenced from: commits 6118d67, 8975554

@spring-projects-issues
Copy link
Collaborator Author

Daniel Walcher commented

Further investigation has shown that AbstractAutowireCapableBeanFactory#applyBeanPostProcessorsAfterInitialization also suffers from the same issue.

@spring-projects-issues
Copy link
Collaborator Author

Juergen Hoeller commented

Fixed for 3.0.2: BeanPostProcessors are allowed to return a null bean value in the middle of the chain now.

As for your ordering question: BeanPostProcessors will only honor the Ordered interface when autodetected as beans (see AbstractApplicationContext's "registerBeanPostProcessors"). Objects registered through addBeanPostProcessor do not participate in that ordering; the addBeanPostProcessor call order is significant there.

Juergen

@spring-projects-issues spring-projects-issues added type: bug A general bug in: core Issues in core modules (aop, beans, core, context, expression) labels Jan 11, 2019
@spring-projects-issues spring-projects-issues added this to the 3.0.2 milestone Jan 11, 2019
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