[rules-users] Help debugging NPE

Dirk Bergstrom dirk at juniper.net
Thu Jun 25 12:40:02 EDT 2009


Edson Tirelli was heard to exclaim, On 06/24/09 15:43:
>     Drools 5 is mostly backward compatible with Drools 4. You don't need
> to migrate to the new API, although it is recommended.

Ahh, that's good to know.  You might want to mention that somewhere in the
release notes, or on the website.  It would probably improve the adoption rate.

>     Anyway, I understand your concern. My wild wild guess is that the
> memberOf operator is complaining about a null in that constraint.

Nope, it's stranger than that.  The problem arose because I'd changed the
hashCode() method of the base Record class to a final method.  I un-finalized
the method, and the NPEs stopped happening.

I don't understand how this could cause a problem, but I'm pretty sure it's a
bug in Drools.  Once I get some free time, I'm going to test the code with 5.0,
and I'll see if the bug shows up there.

> 2009/6/24 Dirk Bergstrom <dirk at juniper.net <mailto:dirk at juniper.net>>
> 
>     Edson Tirelli was heard to exclaim, On 06/24/09 06:14:
>     >       The problem seems not related to shadow facts, but to constraint
>     > resolution and fact data extraction. It might be a bug or not... need
>     > more info.
> 
>     I've also seen the following stacktrace:
> 
>     java.lang.ArrayIndexOutOfBoundsException: 40440
>            at
>     org.drools.util.TupleIndexHashTable.toArray(TupleIndexHashTable.java:217)
>            at
>     org.drools.reteoo.CollectNode.retractObject(CollectNode.java:260)
>            at
>     org.drools.reteoo.SingleObjectSinkAdapter.propagateRetractObject(SingleObjectSinkAdapter.java:32)
>            at org.drools.reteoo.AlphaNode.retractObject(AlphaNode.java:164)
>            at
>     org.drools.reteoo.SingleObjectSinkAdapter.propagateRetractObject(SingleObjectSinkAdapter.java:32)
>            at org.drools.reteoo.AlphaNode.retractObject(AlphaNode.java:164)
>            at
>     org.drools.reteoo.CompositeObjectSinkAdapter.propagateRetractObject(CompositeObjectSinkAdapter.java:366)
>            at
>     org.drools.reteoo.ObjectTypeNode.retractObject(ObjectTypeNode.java:189)
>            at org.drools.reteoo.Rete.retractObject(Rete.java:215)
>            at
>     org.drools.reteoo.ReteooRuleBase.retractObject(ReteooRuleBase.java:211)
>            at
>     org.drools.reteoo.ReteooWorkingMemory.doRetract(ReteooWorkingMemory.java:79)
>            at
>     org.drools.common.AbstractWorkingMemory.retract(AbstractWorkingMemory.java:1023)
>            at
>     org.drools.common.AbstractWorkingMemory.retract(AbstractWorkingMemory.java:982)
>            at
>     net.juniper.dash.data.DataSource.reconcileAssertedRecords(DataSource.java:362)
> 
>     >       In any case, the offending rule is not the one you showed. The
>     > offending rule contains a double beta constraint in a join:
> 
>     I know it's not in that rule.  It must be in this one, since it's
>     the only one
>     that uses rli_nums:
> 
>     $npi : NPIRecord( )
>     $pr : PRRecord( npi == "", rli != "" )
>     $rli : RLIRecord( id memberOf $pr.rli_nums, npi_program ==
>     $npi.synopsis )
> 
>     >       Can you narrow it down? Did you tried with Drools 5.0.1?
> 
>     I haven't tried any of the 5.x series.  Is there a guide to
>     migrating my code
>     from 4.0 to 5.0?  I looked on the jboss site, the wiki, the blog,
>     and this
>     mailing list, but I didn't find anything.  I'm under a lot of time
>     pressure, and
>     changing to 5.0 doesn't look like a quick fix...
> 
>     > 2009/6/24 Dirk Bergstrom <dirk at juniper.net
>     <mailto:dirk at juniper.net> <mailto:dirk at juniper.net
>     <mailto:dirk at juniper.net>>>
>     >
>     >     I'm running into an NPE using Drools 4.0.7, and I'm stumped by it
>     >     (stacktrace
>     >     below).  I made some changes to seemingly unrelated code, and this
>     >     error started
>     >     showing up.  It would help me to understand what's going on if
>     >     someone could
>     >     tell me roughly what's going on here.  Since the error is
>     thrown by
>     >     generated
>     >     code (in what I assume is a shadow proxy), I can't tell what the
>     >     offending null
>     >     pointer is.  I'm not even entirely sure what's triggering the bug
>     >     (it happens
>     >     half an hour into the run of big multi-threaded application with
>     >     about 40K
>     >     objects in the working memory).
>     >
>     >     Is this happening because:
>     >
>     >     *) getRli_nums() in one of my PRRecord objects is returning a null
>     >     value?
>     >
>     >     *) There is a null PRRecord object backing the shadow proxy?
>     >
>     >     *) Some other thing is null?
>     >
>     >     *) I'm running into a bug in Drools?
>     >
>     >     I stuck in this rule:
>     >
>     >     when
>     >      $pr : PRRecord( rli_nums == null )
>     >     then
>     >      System.out.println($pr.getId());
>     >     end
>     >
>     >     And it didn't print anything, so I'm inclined to think that
>     this is
>     >     not a simple
>     >     matter of something returning a null value...
>     >
>     >     I'll be most appreciative of any help I can get.
>     >
>     >     Here's the stacktrace:
>     >
>     >     java.lang.NullPointerException
>     >            at
>     >    
>     org.drools.base.net.juniper.dash.data.PRRecord13409648$getRli_nums.getValue(Unknown
>     >     Source)
>     >            at
>     >    
>     org.drools.base.ClassFieldExtractor.getValue(ClassFieldExtractor.java:127)
>     >            at
>     >    
>     org.drools.base.evaluators.BaseMemberOfEvaluator.evaluateCachedRight(BaseMemberOfEvaluator.java:45)
>     >            at
>     >    
>     org.drools.rule.VariableRestriction.isAllowedCachedRight(VariableRestriction.java:89)
>     >            at
>     >    
>     org.drools.rule.VariableConstraint.isAllowedCachedRight(VariableConstraint.java:81)
>     >            at
>     >    
>     org.drools.common.DoubleBetaConstraints.isAllowedCachedRight(DoubleBetaConstraints.java:164)
>     >            at
>     org.drools.reteoo.JoinNode.retractObject(JoinNode.java:189)
>     >            at
>     >    
>     org.drools.reteoo.CompositeObjectSinkAdapter.propagateRetractObject(CompositeObjectSinkAdapter.java:375)
>     >            at
>     >    
>     org.drools.reteoo.ObjectTypeNode.retractObject(ObjectTypeNode.java:189)
>     >            at org.drools.reteoo.Rete.retractObject(Rete.java:215)
>     >            at
>     >    
>     org.drools.reteoo.ReteooRuleBase.retractObject(ReteooRuleBase.java:211)
>     >            at
>     >    
>     org.drools.reteoo.ReteooWorkingMemory.doRetract(ReteooWorkingMemory.java:79)
>     >            at
>     >    
>     org.drools.common.AbstractWorkingMemory.update(AbstractWorkingMemory.java:1250)
>     >            at
>     >    
>     org.drools.common.AbstractWorkingMemory.update(AbstractWorkingMemory.java:1203)
>     >            at
>     >    
>     net.juniper.dash.data.DataSource.reconcileAssertedRecords(DataSource.java:409)


-- 
Dirk Bergstrom               dirk at juniper.net
_____________________________________________
Juniper Networks Inc.,          Computer Geek
Tel: 408.745.3182           Fax: 408.745.8905



More information about the rules-users mailing list