[rules-users] Null pointer when retracting Event which has an 'after'

richarda richard.ambridge at gmail.com
Mon Nov 16 11:25:28 EST 2009


I wish to have a rule that says,  if I get one event, but not another one
after a period, then do something.
But I also want to only do this once..

So, I wrote the rules: (using the eclipse sample project)



declare Message
	@role( event )
end

rule "Hello World"
	when
		$m : Message( status == Message.HELLO )
		not ( Message( status== Message.GOODBYE, this after [0s,1m] $m)) ;
	then
		System.out.println( "Hello" ); 		
end

rule "GoodBye"
	when
		$one : Message( status == Message.HELLO )
		$two : Message( status == Message.HELLO )
	then
		System.out.println( "Two hellos, remove one" );
		retract($two);
end


But, when I run;
			Message message = new Message();
			message.setMessage("Hello World");
			message.setStatus(Message.HELLO);
			ksession.insert(message);
			
			Message message2 = new Message();
			message2.setMessage("Hello World");
			message2.setStatus(Message.HELLO);
			ksession.insert(message2);
			ksession.fireAllRules();

I get:
Two hellos, remove one
java.lang.NullPointerException
	at org.drools.common.DefaultAgenda.fireActivation(DefaultAgenda.java:970)
	at org.drools.common.DefaultAgenda.fireNextItem(DefaultAgenda.java:885)
	at org.drools.common.DefaultAgenda.fireAllRules(DefaultAgenda.java:1086)
	at
org.drools.common.AbstractWorkingMemory.fireAllRules(AbstractWorkingMemory.java:660)
	at
org.drools.common.AbstractWorkingMemory.fireAllRules(AbstractWorkingMemory.java:627)
	at
org.drools.impl.StatefulKnowledgeSessionImpl.fireAllRules(StatefulKnowledgeSessionImpl.java:183)
	at com.sample.DroolsTest.main(DroolsTest.java:38)


What am i doing wrong?
-- 
View this message in context: http://old.nabble.com/Null-pointer-when-retracting-Event-which-has-an-%27after%27-tp26374807p26374807.html
Sent from the drools - user mailing list archive at Nabble.com.




More information about the rules-users mailing list