Hi Toshiya,
thanks for taking a look.
I had a go on a brand new project which I can share if you want but I think you should be able to recreate with the code below, it is more subtle than I realised. Obviously I can work around this easily but curious whether the problematic pattern outlined below is something that I should just be avoiding in general or whether it highlights anything else to be aware of? Thanks.
Below I have an 'init' rule and then three variations of the subtract, two of which work fine, the final one causes looping.
rule "init"
when
not MathFact( );
then
MathFact fact = new MathFact();
fact.setBigDecimal1(BigDecimal.valueOf(10));
fact.setBigDecimal2(BigDecimal.valueOf(5));
insert(fact);
end
// Works
rule "subtract"
when
$fact : MathFact( bigDecimal1 != null, bigDecimal2 != null );
then
// Notice the entire calculation is on one line.
BigDecimal result = $fact.getBigDecimal1().subtract($fact.getBigDecimal2());
System.out.println("\nMathFact.result: " + result);
modify($fact) {
setBigDecimalResult(result);
};
end
// Works
rule "subtract"
when
$fact : MathFact( bigDecimal1 != null, bigDecimal2 != null );
then
// Notice the calculation is split over lines but starts on the same as the assignment.
BigDecimal result = $fact.getBigDecimal1().subtract(
$fact.getBigDecimal2());
System.out.println("\nMathFact.result: " + result);
modify($fact) {
setBigDecimalResult(result);
};
end
// Looping!
rule "subtract"
when
$fact : MathFact( bigDecimal1 != null, bigDecimal2 != null );
then
// Notice the calculation is split over lines and this time starts on the line after assignment.
BigDecimal result =
$fact.getBigDecimal1().subtract($fact.getBigDecimal2());
System.out.println("\nMathFact.result: " + result);
modify($fact) {
setBigDecimalResult(result);
};
end