[rules-users] Guvnor only: NullPointerException AfterEvaluator.evaluateCachedRight

kappert kappert at hotmail.com
Mon Jan 7 10:52:01 EST 2013


Environment: Windows 7 PC with Java 1.7.0_09, Drools 5.5.0.Final.

I have carefully cleaned up the POJO model loaded into the Guvnor: The model
now has no external dependencies except for "org.drools..." and "java..."
packages. Everything validates perfectly in Guvnor, but this did not solve
the problem.

In the debugger I can see that the line in bold in the Drools source code
below is where the NPE happens: "this.getOperator()" returns null (unless
the debugger is misleading me somehow). I have included the stack trace
right /before/ the NPE happens.

I have also found out that the problem is caused by a single specific rule.
I have removed it in Guvnor and that made the problem go away. (The event
declaration was not removed, I have included it to show that events are
involved).

The problem disappears if this rule is removed

declare TicketKaufEvent
    @role(event)
    @timeStamp(timestamp)
end

/rule "Kundenbelohnung"
    when
        $tk1 : TicketKaufEvent( $k : kunde )
        $tk2 : TicketKaufEvent( kunde == $k, produktinformation.preis >=
2*($tk1.produktinformation.preis), this != $tk1, this after[0, 2m] $tk1)
        not KundeRewarded( kunde == $k )
    then
        service.notifyKunde($k.vorname + " " + $k.name + " hat innerhalb von
2 Minuten zwei Tickets gekauft, wobei das zweite Ticket mind. doppelt so
teuer wie das erste war und erhaelt deshalb einmalig einen Kaffeegutschein")
        insert(new KundeRewarded( $k ));
end/

Source: org.drools.base.evaluators.AfterEvaluatorDefinition

It looks like "this.getOperator()" on the bold line returns null...

        public boolean evaluateCachedRight(InternalWorkingMemory
workingMemory,
                                           final VariableContextEntry
context,
                                           final Object left) {
            if ( context.rightNull ) {
                return false;
            }
            long rightTS;
            if( this.unwrapRight ) {
                if( context instanceof ObjectVariableContextEntry ) {
                    if( ((ObjectVariableContextEntry) context).right
instanceof Date ) {
                        rightTS = ((Date)((ObjectVariableContextEntry)
context).right).getTime();
                    } else {
                        rightTS = ((Number)((ObjectVariableContextEntry)
context).right).longValue();
                    }
                } else {
                    rightTS = ((LongVariableContextEntry) context).right;
                }
            } else {
                rightTS = ((EventFactHandle) ((ObjectVariableContextEntry)
context).right).getStartTimestamp();
            }
            long leftTS = this.unwrapLeft ?
context.declaration.getExtractor().getLongValue( workingMemory,
                                                                                            
left ) : ((EventFactHandle) left).getEndTimestamp();

            long dist = rightTS - leftTS;
            *return this.getOperator().isNegated() ^ (dist >= this.initRange
&& dist <= this.finalRange);*
        }

Stack Trace right before NPE is triggered

Thread [pool-2-thread-1] (Suspended (breakpoint at line 322 in
AfterEvaluatorDefinition$AfterEvaluator))	

AfterEvaluatorDefinition$AfterEvaluator.evaluateCachedRight(InternalWorkingMemory,
VariableRestriction$VariableContextEntry, Object) line: 322	
	EvaluatorConstraint.isAllowedCachedRight(LeftTuple, ContextEntry) line: 80	
	TripleBetaConstraints.isAllowedCachedRight(ContextEntry[], LeftTuple) line:
101	
	JoinNode.propagateFromRight(RightTuple, LeftTuple, BetaMemory,
PropagationContext, InternalWorkingMemory) line: 156	
	JoinNode.assertObject(InternalFactHandle, PropagationContext,
InternalWorkingMemory) line: 148	
	CompositeObjectSinkAdapter.doPropagateAssertObject(InternalFactHandle,
PropagationContext, InternalWorkingMemory, ObjectSink) line: 497	
	CompositeObjectSinkAdapter.propagateAssertObject(InternalFactHandle,
PropagationContext, InternalWorkingMemory) line: 382	
	ObjectTypeNode.assertObject(InternalFactHandle, PropagationContext,
InternalWorkingMemory) line: 235	
	EntryPointNode.assertObject(InternalFactHandle, PropagationContext,
ObjectTypeConf, InternalWorkingMemory) line: 240	
	NamedEntryPoint.insert(InternalFactHandle, Object, Rule, Activation,
ObjectTypeConf) line: 350	
	NamedEntryPoint.insert(Object, Object, boolean, boolean, Rule, Activation)
line: 311	
	ReteooStatefulSession(AbstractWorkingMemory).insert(Object, Object,
boolean, boolean, Rule, Activation) line: 903	
	ReteooStatefulSession(AbstractWorkingMemory).insert(Object) line: 847	
	StatefulKnowledgeSessionImpl.insert(Object) line: 269	
	EventHub.receive(AbstractEvent) line: 85	
	EventFeeder$FeedJob.execute(JobContext) line: 90	
	DefaultTimerJobInstance.call() line: 51	
	DefaultTimerJobInstance.call() line: 14	
	FutureTask$Sync.innerRun() line: 314	
	ScheduledThreadPoolExecutor$ScheduledFutureTask<V>(FutureTask<V>).run()
line: 149	

ScheduledThreadPoolExecutor$ScheduledFutureTask<V>.access$301(ScheduledThreadPoolExecutor$ScheduledFutureTask)
line: 109	
	ScheduledThreadPoolExecutor$ScheduledFutureTask<V>.run() line: 218	
	ThreadPoolExecutor$Worker.runTask(Runnable) line: 897	
	ThreadPoolExecutor$Worker.run() line: 919	
	Thread.run() line: 736	




--
View this message in context: http://drools.46999.n3.nabble.com/Guvnor-only-NullPointerException-AfterEvaluator-evaluateCachedRight-tp4021368p4021376.html
Sent from the Drools: User forum mailing list archive at Nabble.com.


More information about the rules-users mailing list