[rules-users] NPE in Drools JPA Persistence with rules that use Flow

Shannon Hastings shannon.hastings at inventrio.com
Thu May 26 10:50:45 EDT 2011


I have debugged into this and found this issue.  The NPE comes when the session unmarsheller runs into a node that does not have a sink or the sink is null. In the debugger i can see the fact and the fact looks right, has all the data from the pojo i sent in. However, it does not have a sink, but it does have a node id.  This looks like a bug that was reportedly fixed before in 5.1.  I dont know enough about the storing of the facts in the working memory or the model that is being used under the hood, however, all i have to do to create the problem is create a session, send an object to it, and then try to restore it.  And the objects i am sending to it are simple pojo's and in the debugger I can see that it was able to read them back out just fine.  Below is an exerpt from the "InputMarshaller" class.  In the debugger The readlefttuples operation shows the nodeId = 12 and the sink  = null and the facthandleId = 1.  he it calls readLeftTuple() and the obvious NPE will be thrown because the ParentLeftTuple has a null sink and when you call "sink.getType()" you get the NPE.  Is this a known bug.

  public static void readLeftTuples(MarshallerReaderContext context) throws IOException,
                                                                      ClassNotFoundException {
        ObjectInputStream stream = context.stream;

        while ( stream.readShort() == PersisterEnums.LEFT_TUPLE ) {
            int nodeId = stream.readInt();
            LeftTupleSink sink = (LeftTupleSink) context.sinks.get( nodeId );
            int factHandleId = stream.readInt();
            LeftTuple leftTuple = new LeftTuple( context.handles.get( factHandleId ),
                                                 sink,
                                                 true );
            readLeftTuple( leftTuple,
                           context );
        }
    }

    public static void readLeftTuple(LeftTuple parentLeftTuple,
                                     MarshallerReaderContext context) throws IOException,
                                                                     ClassNotFoundException {
        ObjectInputStream stream = context.stream;
        Map<Integer, BaseNode> sinks = context.sinks;

        LeftTupleSink sink = parentLeftTuple.getLeftTupleSink();

        switch ( sink.getType() ) {


On May 24, 2011, at 9:06 AM, Edson Tirelli wrote:

> 
>     Shannon,
> 
>     What is the following method doing?
> 
> engine.process(reading);
> 
>     Can you please open a JIRA and attach your test case or point me to the jira reporting this problem if it exists already?
> 
>     Thanks,
>         Edson
> 
> 
> 2011/5/23 Shannon Hastings <shannon.hastings at inventrio.com>
> I am using drools 5.2.0.M2 and I still get this error:
> 
> Caused by: java.lang.NullPointerException
> 	at org.drools.marshalling.impl.InputMarshaller.readLeftTuple(InputMarshaller.java:469)
> 
> Which was reported on drools 5.1.0 JIRA and claimed to be fixed.  I see the error when trying to load a session that was persisted that had objects inserted that  are time depended and cause rules to fire that use terms from flow such as "after".  I only see this error if create a new session, submit some facts to it, close it, and then try to reload.  If i do not submit any facts to it I do not get the error.  I.E.  If all i do is create the KB with my rules I can reload a session from the DB no problem, but if i submit some facts and persist the session, then i cannot reload it.  This seems to be an issue with the JPA loading of the session that has facts in it that use Flow (JBPM).  Any help would be greatly appreciated.  Below are my simple rules followed by the test code used to submit the facts:
> 
> package com.inventrio.rules.readings
>  
> import com.inventrio.healthmonitoring.model.*;
> 
> declare Reading
>     @role(event)
>     @timestamp(readingTime)
> end
> 
> rule "High Blood Pressure"
> 	when
> 		$eventA :  Reading(readingType.name == "BPMETER")
> 		$systolic : Value( this.valueType.name == "SYSTOLIC"  ) from $eventA.values
> 		$diastolic : Value( this.valueType.name == "DIASTOLIC"  ) from $eventA.values
> 		eval( $systolic.getLongValue() > 180 && $diastolic.getLongValue() > 120 )
> 	then
> 		System.out.println("HIGH BLOOD PRESSURE" );  
> end
> 
> rule "Weight Trending Up"
> 	when
> 		$eventC :  Reading(readingType.name == "WEIGHT" )
> 		$eventB  : Reading( readingType.name == "WEIGHT" , this after[5s, 1m] $eventC )
> 		$eventA  : Reading( readingType.name == "WEIGHT" , this after[5s, 1m] $eventB )
> 		$weight3 : Value( this.valueType.name == "WEIGHT"  ) from $eventC.values
> 		$weight2 : Value( this.valueType.name == "WEIGHT"  ) from $eventB.values
> 		$weight1 : Value( this.valueType.name == "WEIGHT"  ) from $eventA.values
> 		eval(  $weight3.getDoubleValue().doubleValue() < $weight2.getDoubleValue().doubleValue() + 1.0  && $weight2.getDoubleValue().doubleValue() < $weight1.getDoubleValue().doubleValue() + 1.0 )
> 	then
> 		System.out.println("WEIGHT IS GOING UP" ); 
> end
> 
> rule "Weight Trending Down"
> 	when
> 		$eventC :  Reading(readingType.name == "WEIGHT" )
> 		$eventB  : Reading( readingType.name == "WEIGHT" , this after[5s, 1m] $eventC )
> 		$eventA  : Reading( readingType.name == "WEIGHT" , this after[5s, 1m] $eventB )
> 		$weight3 : Value( this.valueType.name == "WEIGHT"  ) from $eventC.values
> 		$weight2 : Value( this.valueType.name == "WEIGHT"  ) from $eventB.values
> 		$weight1 : Value( this.valueType.name == "WEIGHT"  ) from $eventA.values
> 		eval(  $weight3.getDoubleValue().doubleValue() > $weight2.getDoubleValue().doubleValue() + 1.0  && $weight2.getDoubleValue().doubleValue() > $weight1.getDoubleValue().doubleValue() + 1.0 )
> 	then
> 		System.out.println("WEIGHT IS GOING DOWN" ); 
> end
> 
> 
> 
> And next is my object i insert before closeing and then trying to reload the session.
> 
> 	public void testWeightRules() {
> 		try {
> 
> 			Reading reading = new Reading();
> 			reading.setReadingTime(new Date(System.currentTimeMillis()));
> 			ReadingType type = new ReadingType();
> 			type.setName("WEIGHT");
> 			type.setDescription("");
> 			reading.setReadingType(type);
> 			Value value = new Value();
> 			value.setDoubleValue(140.0);
> 			ValueType valueType = new ValueType();
> 			valueType.setName("WEIGHT");
> 			valueType.setDataType(ValueDataType.DOUBLE);
> 			value.setValueType(valueType);
> 			reading.getValues().add(value);
> 			reading.setReadingType(type);
> 			engine.process(reading);
> 
> 			Thread.sleep(7000);
> 
> 			reading = new Reading();
> 			reading.setReadingTime(new Date(System.currentTimeMillis()));
> 			type = new ReadingType();
> 			type.setName("WEIGHT");
> 			type.setDescription("");
> 			reading.setReadingType(type);
> 			value = new Value();
> 			value.setDoubleValue(142.0);
> 			valueType = new ValueType();
> 			valueType.setName("WEIGHT");
> 			valueType.setDataType(ValueDataType.DOUBLE);
> 			value.setValueType(valueType);
> 			reading.getValues().add(value);
> 			reading.setReadingType(type);
> 			engine.process(reading);
> 
> 			Thread.sleep(7000);
> 
> 			reading = new Reading();
> 			reading.setReadingTime(new Date(System.currentTimeMillis()));
> 			type = new ReadingType();
> 			type.setName("WEIGHT");
> 			type.setDescription("");
> 			reading.setReadingType(type);
> 			value = new Value();
> 			value.setDoubleValue(144.0);
> 			valueType = new ValueType();
> 			valueType.setName("WEIGHT");
> 			valueType.setDataType(ValueDataType.DOUBLE);
> 			value.setValueType(valueType);
> 			reading.getValues().add(value);
> 			reading.setReadingType(type);
> 			engine.process(reading);
> 
> 		} catch (Throwable t) {
> 			t.printStackTrace();
> 		}
> 	}
> 
> Shannon Hastings
> 
> Inventrio
> 545 Metro Place South, Suite 475
> Dublin, OH 43017
> Phone: (614) 389-2795 x101
> Fax: (614) 522-6249
> Email: shannon.hastings at inventrio.com
> http://www.inventrio.com
> 
> 
> _______________________________________________
> rules-users mailing list
> rules-users at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
> 
> 
> 
> 
> -- 
>   Edson Tirelli
>   JBoss Drools Core Development
>   JBoss by Red Hat @ www.jboss.com
> _______________________________________________
> rules-users mailing list
> rules-users at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users

Shannon Hastings

Inventrio
545 Metro Place South, Suite 475
Dublin, OH 43017
Phone: (614) 389-2795 x101
Fax: (614) 522-6249
Email: shannon.hastings at inventrio.com
http://www.inventrio.com

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/rules-users/attachments/20110526/766965d3/attachment.html 


More information about the rules-users mailing list