This bug is located in the drools-spring component in class org.drools.container.spring.namespace.KnowledgeSessionDefinitionParser.java
The class compares each Spring bean with a non NullPointer safe equals call.
// find any kagent's for the current kbase and assign for ( String beanName : parserContext.getRegistry().getBeanDefinitionNames() ) { BeanDefinition def = parserContext.getRegistry().getBeanDefinition(beanName); // is null if the Spring bean is abstract if ( def.getBeanClassName().equals( KnowledgeAgentBeanFactory.class.getName() ) ) { // NullPointerException comes here due to the abstract bean that does not have a bean definition PropertyValue pvalue = def.getPropertyValues().getPropertyValue( "kbase" ); RuntimeBeanReference tbf = ( RuntimeBeanReference ) pvalue.getValue(); if ( kbase.equals( tbf.getBeanName() ) ) { factory.addPropertyValue( "knowledgeAgent", new RuntimeBeanReference( beanName ) ); } } }
We use abstract beans in our Spring project and it seems that an abstract bean does not have a BeanDefinition
<bean id="i18NServiceConfig" abstract="true"> <property name="xxx"> <ref local="yyy" /> </property> </bean> <bean class="de.corag.bpm.cone.service.i18n.I18NServiceImpl" parent="i18NServiceConfig"> <property name="messageDao"><ref bean="messageDao"/></property> </bean>
if you change the equals statement like this no NullPointerException would be thrown
// find any kagent's for the current kbase and assign for ( String beanName : parserContext.getRegistry().getBeanDefinitionNames() ) { BeanDefinition def = parserContext.getRegistry().getBeanDefinition(beanName); if ( KnowledgeAgentBeanFactory.class.getName().equals( def.getBeanClassName() ) ) { // NullPointerException is avoided in this statement PropertyValue pvalue = def.getPropertyValues().getPropertyValue( "kbase" ); RuntimeBeanReference tbf = ( RuntimeBeanReference ) pvalue.getValue(); if ( kbase.equals( tbf.getBeanName() ) ) { factory.addPropertyValue( "knowledgeAgent", new RuntimeBeanReference( beanName ) ); } } }
- is duplicated by
-
JBRULES-2868 NullPointerException in KnowledgeSessionDefinitionParser
- Closed
-
JBRULES-2689 [drools-spring] KnowledgeSessionDefinitionParser generates nullpointerexception on parsing spring xml file due to missing class attribute on bean
- Closed
-
JBPM-3024 JBPM5/Drools, Spring integration and NullPointer - could a commiter apply a simple patch already?
- Resolved