[rules-users] NPE for any @role( event )

capn_ed cncosper at capn-ed.net
Mon Jan 23 16:28:28 EST 2012


I am using Drools version 5.4.0.Beta1.  My rules are defined in a drl file.

I cannot get a type with @role(event) to run correctly. In every case I've
tried, I get the following error at runtime:

---------------------
java.lang.NullPointerException
	at
org.drools.reteoo.ReteooFactHandleFactory.newFactHandle(ReteooFactHandleFactory.java:56)
	at
org.drools.common.AbstractFactHandleFactory.newFactHandle(AbstractFactHandleFactory.java:80)
	at
org.drools.common.AbstractFactHandleFactory.newFactHandle(AbstractFactHandleFactory.java:65)
	at org.drools.common.NamedEntryPoint.createHandle(NamedEntryPoint.java:740)
	at org.drools.common.NamedEntryPoint.insert(NamedEntryPoint.java:286)
	at org.drools.common.NamedEntryPoint.insert(NamedEntryPoint.java:122)
	at org.drools.common.NamedEntryPoint.insert(NamedEntryPoint.java:52)
	at test.DroolsTest.main(DroolsTest.java:62)

--------------------
Looking at the source:

ReteooFactHandleFactory.java:56:
            if ( type.getTimestampExtractor() != null ) {

"type" is null, hence the NPE. Tracing through in Eclipse, I find that in
ReteooFactHandleFactory.java, on line 54, is the following:

TypeDeclaration type = conf.getTypeDeclaration();

getTypeDeclaration() returns null. Stepped in, goes to
AbstractRuleBase.java:745:

    public TypeDeclaration getTypeDeclaration( Class< ? > clazz ) {
        TypeDeclaration typeDeclaration = this.classTypeDeclaration.get(
clazz );
        if ( typeDeclaration == null ) {
            // check super classes and keep a score of how up in the
hierarchy is there a declaration
            TypeDeclarationCandidate candidate = checkSuperClasses( clazz );
            // now check interfaces
            candidate = checkInterfaces( clazz,
                                         candidate,
                                         1 );
            if ( candidate != null ) {
                typeDeclaration = candidate.candidate;
            }
        }
        return typeDeclaration;
    }

On line 746,
TypeDeclaration typeDeclaration = this.classTypeDeclaration.get( clazz );

this.classTypeDeclaration is type Map<Class&lt; ? >, TypeDeclaration>. Map
is empty (size = 0), so the get() returns null. checkSuperClasses() and
checkInterfaces() also attempt to retrieve a TypeDeclaration from this same
(empty) map. So, a null typeDeclaration is returned.


Checking classTypeDeclaration references, the put() occurs in
AbstractRuleBase.addPackages() (AbstractRuleBase.java:476), and in
AbstractRuleBase.populateTypeDeclarationMaps() (AbstractRuleBase.java:336).
The latter is not called before the NPE. Execution in addPackages() do not
get to the classTypeDeclaration.put() because newPkg.getTypeDeclarations()
is empty. So, apparently, the TypeDeclaration is never put into the Map.


Attached is the minimal testcase that exhibits the same behavior.
  http://drools.46999.n3.nabble.com/file/n3683063/TestRules.zip
TestRules.zip 

--
View this message in context: http://drools.46999.n3.nabble.com/NPE-for-any-role-event-tp3683063p3683063.html
Sent from the Drools: User forum mailing list archive at Nabble.com.



More information about the rules-users mailing list