Rules with "not" patterns are sometimes fired incorrectly even though there are facts which must not exist.
Issue
When executing a rule with one or more not
patterns, the rule is sometimes fired unexpectedly. For example, when I execute a rule (*1) containing a not
pattern like (*1-1) with a java code (*2) inserting some facts which must not exist and modifying some properties of one of the facts, the rule (*1) is sometimes fired unexpectedly like (*3-1).
(*1) DRL Rules
dialect "mvel"
rule "cond_1d_01"
salience 3
when
Cheese( $type : type )
not ( Person( likes == $type, salary == null ) ) // <---------- (*1-1)
then
System.out.println("***** Rule \"cond_1d_01\" FIRED!");
end
rule "cond_1d_02"
salience 2
when
Cheese( $type : type )
$person : Person( likes == $type, name == "George" )
then
modify($person) {
age = 40
}
System.out.println("***** Rule \"cond_1d_02\": " + $person);
end
rule "cond_1d_03"
salience 1
when
Cheese( $type : type )
$person : Person( likes == $type, name == "George" )
then
modify($person) {
salary = new BigDecimal(1000)
}
System.out.println("***** Rule \"cond_1d_03\": " + $person);
end
(*2) Java code
Cheese cheese = new Cheese("cheddar");
Person p1 = new Person("John");
p1.setId(1);
p1.setLikes("cheddar");
p1.setSalary(null);
Person p2 = new Person("Paul");
p2.setId(2);
p2.setLikes("cheddar");
p2.setSalary(null);
Person p3 = new Person("George");
p3.setId(3);
p3.setLikes("cheddar");
p3.setSalary(null);
kSession.insert(cheese);
kSession.insert(p1);
kSession.insert(p2);
kSession.insert(p3);
kSession.fireAllRules();
(*3) The result of rule execution
***** Rule "cond_1d_02": com.example.reproducer.Person[id='3', name='George', age='0', likes='cheddar', salary='null']
***** Rule "cond_1d_03": com.example.reproducer.Person[id='3', name='George', age='40', likes='cheddar', salary='null']
***** Rule "cond_1d_01" FIRED! <---------- (*3-1)
Environment
- Red Hat Decision Manager (RHDM)
- 7.1.0 - 7.11.1
Subscriber exclusive content
A Red Hat subscription provides unlimited access to our knowledgebase, tools, and much more.