[rules-users] NullPointer after inserting fact in RHS

nch underscore_dot at yahoo.com
Wed Apr 27 03:49:36 EDT 2011


I think I have an AspectJ based solution for this which consists on making every 
isAllowed* method  return "false" instead of letting exceptions thrown inside 
them propagate:

    pointcut isAllowed(Object o) : execution(boolean *.isAllowed*(..)) && 
target(o); 
        
    boolean around(Object o) : isAllowed(o) { 
        boolean r= false;
        //debug("-> "+ o.getClass().getName()+ "#"+ 
thisJoinPoint.getSignature().getName()+ "("+ 
thisJoinPoint.getSourceLocation().getLine()+ ")");
        
        try{
            r= proceed(o);
            //debug("<- "+ o.getClass().getName()+ "#"+ 
thisJoinPoint.getSignature().getName()+ "("+ 
thisJoinPoint.getSourceLocation().getLine()+ ")");
        }catch(Exception e){
            //debug("<- "+ o.getClass().getName()+ "#"+ 
thisJoinPoint.getSignature().getName()+ "("+ 
thisJoinPoint.getSourceLocation().getLine()+ "): "+ e.getMessage());
            executeLHSExceptionHandlers(o, e);
        }
        
        return r;
    }

AFAIK, it impacts classes implementing AlphaNodeFieldConstraint, 
BetaNodeFieldConstraint and Restriction interfaces.
I'd appreciate comments/improvements on this (ie, more detailed information for 
the exception handlers).

Kind regards.



________________________________
De: Wolfgang Laun <wolfgang.laun at gmail.com>
Para: Rules Users List <rules-users at lists.jboss.org>
Enviado: mié,27 abril, 2011 09:13
Asunto: Re: [rules-users] NullPointer after inserting fact in RHS


The location of the NPE suggests that some field (mmlCommandUid) is null
when you insert the object, but some rule wants to access its intValue.

All fields accessed in all rules must be initialized properly; Drools does not
guard field accesses with "!= null" for you.

-W

 
On 26 April 2011 20:27, dabar <david.barrett.0+drools at gmail.com> wrote:

I've been battling with drools and just wanting a second viewpoint.  I'm
>using drools 5.2.0 flow and rules.
>
>I have a rule that inserts a new fact as part of the RHS of the rule and
>then I'm getting a null pointer exception - stack below. I assume when the
>fact is inserted all the rules are evaluated to build up the agenda.
>
>I've debugged through drools code and found that in ClassFieldReader object1
>is null and object2 is my new fact.
>
>I'm interested in what a JoinNode represents as I think this is what is
>being evaluated. I would guess its a join node in the flow but these don't
>contain any rules so perhaps not.
>
>Similar threads here suggest this is a fault in one of the rules but I have
>about 100 rules so working out the culprit isn't straightforward.
>What I really want to know is if there a way I can find out which rule is
>being assessed for the agenda so I check that rule.
>
>
>Caused by: java.lang.NullPointerException
>       at
>org.drools.base.com.somecompany.prov.rulesbased.facts.ProvResponse1649170666$getMmlCommandUid.getIntValue(Unknown
>
>Source)
>       at
>org.drools.base.ClassFieldReader.getIntValue(ClassFieldReader.java:165)
>       at
>org.drools.base.evaluators.EqualityEvaluatorsDefinition$IntegerEqualEvaluator.evaluate(EqualityEvaluatorsDefinition.java:1522)
>
>       at
>org.drools.core.util.AbstractHashTable$SingleIndex.equal(AbstractHashTable.java:619)
>
>       at
>org.drools.core.util.LeftTupleList.matches(LeftTupleList.java:190)
>       at
>org.drools.core.util.LeftTupleIndexHashTable.getOrCreate(LeftTupleIndexHashTable.java:347)
>
>       at
>org.drools.core.util.LeftTupleIndexHashTable.add(LeftTupleIndexHashTable.java:233)
>
>       at org.drools.reteoo.JoinNode.assertLeftTuple(JoinNode.java:65)
>       at
>org.drools.reteoo.SingleLeftTupleSinkAdapter.doPropagateAssertLeftTuple(SingleLeftTupleSinkAdapter.java:189)
>
>       at
>org.drools.reteoo.SingleLeftTupleSinkAdapter.createAndPropagateAssertLeftTuple(SingleLeftTupleSinkAdapter.java:138)
>
>       at
>org.drools.reteoo.LeftInputAdapterNode.assertObject(LeftInputAdapterNode.java:148)
>
>       at
>org.drools.reteoo.CompositeObjectSinkAdapter.doPropagateAssertObject(CompositeObjectSinkAdapter.java:450)
>
>       at
>org.drools.reteoo.CompositeObjectSinkAdapter.propagateAssertObject(CompositeObjectSinkAdapter.java:378)
>
>       at
>org.drools.reteoo.ObjectTypeNode.assertObject(ObjectTypeNode.java:190)
>       at
>org.drools.reteoo.EntryPointNode.assertObject(EntryPointNode.java:145)
>       at
>org.drools.common.AbstractWorkingMemory.insert(AbstractWorkingMemory.java:1183)
>       at
>org.drools.common.AbstractWorkingMemory.insert(AbstractWorkingMemory.java:1085)
>       at
>org.drools.common.AbstractWorkingMemory.insert(AbstractWorkingMemory.java:889)
>       at
>org.drools.impl.StatefulKnowledgeSessionImpl.insert(StatefulKnowledgeSessionImpl.java:238)
>
>       at
>com.somecompany.rules.global.RulesUtils.insertFact(RulesUtils.java:159)
>       at
>com.somecompany.rules.common.Rule_Common_HandleUnexpectedResponse___Mark_an_unexpected_response_as_handled_0.defaultConsequence(Rule_Common_HandleUnexpectedResponse___Mark_an_unexpected_response_as_handled_0.java:28)
>
>
>
>--
>View this message in context: 
>http://drools.46999.n3.nabble.com/NullPointer-after-inserting-fact-in-RHS-tp2866772p2866772.html
>
>Sent from the Drools: User forum mailing list archive at Nabble.com.
>_______________________________________________
>rules-users mailing list
>rules-users at lists.jboss.org
>https://lists.jboss.org/mailman/listinfo/rules-users
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/rules-users/attachments/20110427/4d51eb12/attachment.html 


More information about the rules-users mailing list