Jitting Exception when using Collections or HashSet in DRL

2,062 views
Skip to first unread message

sascha.s...@signavio.com

unread,
Jun 24, 2015, 9:58:31 AM6/24/15
to drools...@googlegroups.com
I am currently trying to use Lists in my DRL files.

In order to check equality without duplicates, I am trying to create a new HashSet from my List and then compare it to another new HashSet made from another list.

The DRL looks like this:

package com.signavio.droolsexport 

import java.util.List
import java.util.Arrays
import java.util.HashSet
import java.util.Collections

declare  ListDecision 
    textList : List  
    booleanList : List  
    numberList : List  
    textOutput : String  
end

rule "listDecision_rule_1"
    no-loop 
when
    $listDecision : ListDecision( textList.equals(Arrays.asList("hallo", "welt")), booleanList.equals(Arrays.asList(true)), numberList.equals(Arrays.asList(1.0, 2.0, 3.0)) )  
then
    modify( $listDecision ){ 
        setTextOutput("EQUALS"); 
    };
end

rule "listDecision_rule_2"
    no-loop 
when
    $listDecision : ListDecision( !textList.equals(Arrays.asList("hallo", "welt")), !booleanList.equals(Arrays.asList(true)), !numberList.equals(Arrays.asList(1.0, 2.0, 3.0)) )  
then
    modify( $listDecision ){ 
        setTextOutput("NOT EQUALS"); 
    };
end

rule "listDecision_rule_3"
    no-loop 
when
    $listDecision : ListDecision( new HashSet(textList).containsAll(new HashSet(Arrays.asList("hallo", "welt"))), new HashSet(booleanList).containsAll(new HashSet(Arrays.asList(true))), new HashSet(numberList).containsAll(new HashSet(Arrays.asList(1.0, 2.0, 3.0))) )  
then
    modify( $listDecision ){ 
        setTextOutput("ELEMENTS OF"); 
    };
end

rule "listDecision_rule_4"
    no-loop 
when
    $listDecision : ListDecision( !new HashSet(textList).containsAll(new HashSet(Arrays.asList("hallo", "welt"))), !new HashSet(booleanList).containsAll(new HashSet(Arrays.asList(true))), !new HashSet(numberList).containsAll(new HashSet(Arrays.asList(1.0, 2.0, 3.0))) )  
then
    modify( $listDecision ){ 
        setTextOutput("NOT ELEMENTS OF"); 
    };
end

rule "listDecision_rule_5"
    no-loop 
when
    $listDecision : ListDecision( !Collections.disjoint(textList, Arrays.asList("hallo", "welt")), !Collections.disjoint(booleanList, Arrays.asList(true)), !Collections.disjoint(numberList, Arrays.asList(1.0, 2.0, 3.0)) )  
then
    modify( $listDecision ){ 
        setTextOutput("CONTAINS ANY OF"); 
    };
end

rule "listDecision_rule_6"
    no-loop 
when
    $listDecision : ListDecision( new HashSet(textList).equals(new HashSet(Arrays.asList("hallo", "welt"))), new HashSet(booleanList).equals(new HashSet(Arrays.asList(true))), new HashSet(numberList).equals(new HashSet(Arrays.asList(1.0, 2.0, 3.0))) )  
then
    modify( $listDecision ){ 
        setTextOutput("CONTAINS ONLY"); 
    };
end

rule "listDecision_rule_7"
    no-loop 
when
    $listDecision : ListDecision( Collections.disjoint(textList, Arrays.asList("hallo", "welt")), Collections.disjoint(booleanList, Arrays.asList(true)), Collections.disjoint(numberList, Arrays.asList(1.0, 2.0, 3.0)) )  
then
    modify( $listDecision ){ 
        setTextOutput("CONTAINS NONE OF"); 
    };
end


I'm getting the following output on the console:

2015-06-24 15:28:40,512  WARN (MvelConstraint.java:312) - Exception jitting: booleanList.equals(Arrays.asList(true)) This is NOT an error and NOT prevent the correct execution since the constraint will be evaluated in intrepreted mode
2015-06-24 15:28:40,515  WARN (MvelConstraint.java:312) - Exception jitting: numberList.equals(Arrays.asList(1.0, 2.0, 3.0)) This is NOT an error and NOT prevent the correct execution since the constraint will be evaluated in intrepreted mode
2015-06-24 15:28:40,519  WARN (MvelConstraint.java:312) - Exception jitting: new HashSet(booleanList).containsAll(new HashSet(Arrays.asList(true))) This is NOT an error and NOT prevent the correct execution since the constraint will be evaluated in intrepreted mode
2015-06-24 15:28:40,520  WARN (MvelConstraint.java:312) - Exception jitting: new HashSet(numberList).containsAll(new HashSet(Arrays.asList(1.0, 2.0, 3.0))) This is NOT an error and NOT prevent the correct execution since the constraint will be evaluated in intrepreted mode
2015-06-24 15:28:40,522  WARN (MvelConstraint.java:312) - Exception jitting: !Collections.disjoint(booleanList, Arrays.asList(true)) This is NOT an error and NOT prevent the correct execution since the constraint will be evaluated in intrepreted mode
2015-06-24 15:28:40,571  WARN (MvelConstraint.java:312) - Exception jitting: !Collections.disjoint(numberList, Arrays.asList(1.0, 2.0, 3.0)) This is NOT an error and NOT prevent the correct execution since the constraint will be evaluated in intrepreted mode
2015-06-24 15:28:40,574  WARN (MvelConstraint.java:312) - Exception jitting: new HashSet(booleanList).equals(new HashSet(Arrays.asList(true))) This is NOT an error and NOT prevent the correct execution since the constraint will be evaluated in intrepreted mode
2015-06-24 15:28:40,576  WARN (MvelConstraint.java:312) - Exception jitting: new HashSet(numberList).equals(new HashSet(Arrays.asList(1.0, 2.0, 3.0))) This is NOT an error and NOT prevent the correct execution since the constraint will be evaluated in intrepreted mode

This actually causes the execution to never finish. How can I work around that?

Thanks!

- Sascha

sascha.s...@signavio.com

unread,
Jun 24, 2015, 10:22:21 AM6/24/15
to drools...@googlegroups.com
Oh and as for the components:

I am using  drools core, compiler, kie-api and kie-internal 6.2.0 Final as well as mvel2.2.4Final.

Davide Sottara

unread,
Jun 24, 2015, 11:19:15 AM6/24/15
to drools...@googlegroups.com
I didn't check the logic in detail, but it seems that your rules are loop-prone. "Modify" will cause the reevaluation of the rules, no-loop is not sufficient in this case.
Second, I wonder about the performance impact, having to manipulate all those collections. MVEL has list literals, you might want to consider custom operators / static helper functions as well



--
You received this message because you are subscribed to the Google Groups "Drools Usage" group.
To unsubscribe from this group and stop receiving emails from it, send an email to drools-usage...@googlegroups.com.
To post to this group, send email to drools...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/drools-usage/e5db8733-ac4c-40ee-9195-a005366e9013%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

sascha.s...@signavio.com

unread,
Jun 25, 2015, 11:40:52 AM6/25/15
to drools...@googlegroups.com
Hi Davide,

yes, I know about this issue but currently have other priorities. I will however change the style of rules to avoid loops.
My workaround to at least get it to compile is ugly as hell and not performant at all, but works for now:

new HashSet(Arrays.asList(new String[]{"hello", "world"}))

Do you have any pointers as to where I can read more about the MVEL list literals or maybe even an example?

Thanks,

- Sascha

Davide Sottara

unread,
Jun 25, 2015, 6:35:52 PM6/25/15
to drools...@googlegroups.com

sascha.s...@signavio.com

unread,
Jul 1, 2015, 4:04:07 AM7/1/15
to drools...@googlegroups.com
Davide,

thanks for the input.

I tried inlining the lists but still got Jitting exceptions sometimes for some rules.
Here is an example, maybe you can tell me where I went wrong?

DRL:

package com.signavio.droolsexport 

import java.util.List
import java.util.Arrays
import java.util.HashSet
import java.util.Collections

declare  ListDecision 
    textList : List  
    booleanList : List  
    numberList : List  
    textOutput : String  
end

rule "listDecision_rule_1"
    no-loop 
when
    $listDecision : ListDecision( textList.equals(["hallo", "welt"]), !booleanList.equals([true]), new HashSet([1.0, 2.0, 3.0]).containsAll(new HashSet(numberList)) )  
then
    modify( $listDecision ){ 
        setTextOutput("RULE 1"); 
    };
end

rule "listDecision_rule_2"
    no-loop 
when
    $listDecision : ListDecision( !textList.equals(["hallo", "welt"]), booleanList.equals([true]), !new HashSet([1.0, 2.0, 3.0]).containsAll(new HashSet(numberList)) )  
then
    modify( $listDecision ){ 
        setTextOutput("RULE 2"); 
    };
end

rule "listDecision_rule_3"
    no-loop 
when
    $listDecision : ListDecision( new HashSet(["hallo", "welt"]).containsAll(new HashSet(textList)), booleanList.equals([true]), !numberList.equals([1.0, 2.0, 3.0]) )  
then
    modify( $listDecision ){ 
        setTextOutput("RULE 3"); 
    };
end

rule "listDecision_rule_4"
    no-loop 
when
    $listDecision : ListDecision( !new HashSet(["hallo", "welt"]).containsAll(new HashSet(textList)), !booleanList.equals([true]), !Collections.disjoint(numberList, [1.0, 2.0, 3.0] )  
then
    modify( $listDecision ){ 
        setTextOutput("RULE 4"); 
    };
end

rule "listDecision_rule_5"
    no-loop 
when
    $listDecision : ListDecision( !Collections.disjoint(textList, ["hallo", "welt"], !new HashSet([true]).containsAll(new HashSet(booleanList)), numberList.equals([1.0, 2.0, 3.0]) )  
then
    modify( $listDecision ){ 
        setTextOutput("RULE 5"); 
    };
end

rule "listDecision_rule_6"
    no-loop 
when
    $listDecision : ListDecision( new HashSet(["hallo", "welt"]).equals(new HashSet(textList)), new HashSet([true]).equals(new HashSet(booleanList)), Collections.disjoint(numberList, [1.0, 2.0, 3.0] )  
then
    modify( $listDecision ){ 
        setTextOutput("RULE 6"); 
    };
end

rule "listDecision_rule_7"
    no-loop 
when
    $listDecision : ListDecision( Collections.disjoint(textList, ["hallo", "welt"], !booleanList.equals([true]), numberList.equals([1.0, 2.0, 3.0]) )  
then
    modify( $listDecision ){ 
        setTextOutput("RULE 7"); 
    };
end



Inputs are:

List<String> stringInput = Arrays.asList("wurst", "schmeckt", "wurst", "neckt");
List<Boolean> booleanInput = Arrays.asList(false, false);
List<Double> numberInput = Arrays.asList(1d, 2d, 3d);
String expected = "RULE 7";

With the following console Output in IntelliJ using the Janino 2.5.16 compiler:

2015-07-01 10:00:02,838  WARN (MvelConstraint.java:312) - Exception jitting: booleanList.equals([true]) This is NOT an error and NOT prevent the correct execution since the constraint will be evaluated in intrepreted mode
2015-07-01 10:00:02,869  WARN (MvelConstraint.java:312) - Exception jitting: !booleanList.equals([true]) This is NOT an error and NOT prevent the correct execution since the constraint will be evaluated in intrepreted mode
2015-07-01 10:00:02,884  WARN (MvelConstraint.java:312) - Exception jitting: !Collections.disjoint(numberList, [1.0, 2.0, 3.0]) This is NOT an error and NOT prevent the correct execution since the constraint will be evaluated in intrepreted mode
2015-07-01 10:00:02,903  WARN (MvelConstraint.java:312) - Exception jitting: !booleanList.equals([true]) This is NOT an error and NOT prevent the correct execution since the constraint will be evaluated in intrepreted mode
2015-07-01 10:00:02,906  WARN (MvelConstraint.java:312) - Exception jitting: numberList.equals([1.0, 2.0, 3.0]) This is NOT an error and NOT prevent the correct execution since the constraint will be evaluated in intrepreted mode

The rule that was supposed to fire was rule "listDecision_rule_7".

Is this a problem with my rules (overlap) or is there something I am not seeing?

Thanks already for your help!

Davide Sottara

unread,
Jul 1, 2015, 10:06:05 AM7/1/15
to drools...@googlegroups.com
The messages you're seeing are not real exceptions, it's just a warning that the engine can't optimize some of the constraints like it would with more traditional "==" or ">".
If you are not getting the expected behavior, it should be for a different reason.

sascha.s...@signavio.com

unread,
Jul 1, 2015, 10:34:09 AM7/1/15
to drools...@googlegroups.com
So my rule produced an infinite loop there?
At least my test seems to not stop any more with these inputs. Might be a bad choice of inputs then.

Thank you

Davide Sottara

unread,
Jul 1, 2015, 11:06:03 AM7/1/15
to drools...@googlegroups.com
"no-loop" is not enough to avoid infinite recursion in your rules. 
You can find possible solutions in this ever-green classic : https://ilesteban.wordpress.com/2012/11/16/about-drools-and-infinite-execution-loops/

sascha.s...@signavio.com

unread,
Jul 3, 2015, 7:58:28 AM7/3/15
to drools...@googlegroups.com
One question that I am still not entirely sure on though:

Why do the rules produce an infinite loop when inlining the lists with MVEL but terminate when I use the ugly new HashSet(Arrays.asList(new String[]{})) approach?
Shouldn't these be interchangeable?

Davide Sottara

unread,
Jul 3, 2015, 2:21:46 PM7/3/15
to drools...@googlegroups.com
The actual question is: do the same rules fire in both versions, given the facts you insert? 
Can you replace the "modify" with e.g. a printout and compare them?


Reply all
Reply to author
Forward
0 new messages