Skip to content

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

Closed
@spring-projects-issues

Description

@spring-projects-issues

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

Metadata

Metadata

Assignees

Labels

in: coreIssues in core modules (aop, beans, core, context, expression)type: bugA general bug

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions