Wolfgang,<br><br>first of all let me reenforce one of the advices you already gave: never rely on overloading of functions. Always try to use different names for different functions. This will be even more true in Drools 6 especially if we will decide to take in the functional programming features I suggested a few months ago.<br>
<br>Said that, at the moment I am not sure where the problem could be. I fixed a few varargs related issues on mvel and I hoped it was ok now, but there is still the possibility that Bojan found an edge case.<br><br>Bojan, btw which version of Drools (and mvel) are you using? Of course I need to reproduce this issue to have a clue about what it is going wrong. I will try to do that on my own, but if you could send a self contained project reproducing this bug it could save me lots of time, make me sure that I am working on the &quot;right&quot; problem and allow me to focus on its resolution.<br>
<br>Cheers,<br>Mario<br><br><div class="gmail_quote">On Thu, Mar 7, 2013 at 4:42 PM, Wolfgang Laun <span dir="ltr">&lt;<a href="mailto:wolfgang.laun@gmail.com" target="_blank">wolfgang.laun@gmail.com</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">The problem is not the loop in isEqualMore. I think the problem is caused<br>
by MVEL not handling the signature (Ann...) correctly.<br>
<br>
@Mario: should MVEL be able to deal with such a function call?<br>
<br>
-W<br>
<br>
<br>
On 07/03/2013, Bojan Janisch &lt;<a href="mailto:bojan.janisch@scai.fraunhofer.de">bojan.janisch@scai.fraunhofer.de</a>&gt; wrote:<br>
&gt; I&#39;ve tested all 4 cases. It is strange that each Rule fired exactly one<br>
&gt; time,<br>
&gt; directly before the exception occurs. Here the rules, I&#39;ve built them<br>
&gt; exactly<br>
&gt; for this problem.<br>
&gt; ============================================<br>
&gt; Test 1(isEqualMore):<br>
&gt; rule &quot;Test Experiment 1&quot;<br>
&gt; no-loop<br>
&gt;     when<br>
&gt;         $a1:ODMAnswer()<br>
&gt;<br>
&gt;         $a2:ODMAnswer(<br>
&gt;         !isEqual($a1,$a2),<br>
&gt;         comesAfter($a1,$a2,50))<br>
&gt;<br>
&gt;         $a3:ODMAnswer(<br>
&gt;         comesAfter($a2,$a3,20),<br>
&gt;         !isEqualMore($a1,$a2,$a3))<br>
&gt;     then<br>
&gt;         System.out.println(&quot;Test 1 works&quot;);<br>
&gt; end<br>
&gt;<br>
&gt; Result:<br>
&gt; Same Runtime exception<br>
&gt; ============================================<br>
&gt; Test 2(isEqualThree):<br>
&gt; rule &quot;Test Experiment 2&quot;<br>
&gt; no-loop<br>
&gt;     when<br>
&gt;         $a1:ODMAnswer()<br>
&gt;<br>
&gt;         $a2:ODMAnswer(<br>
&gt;         !isEqual($a1,$a2),<br>
&gt;         comesAfter($a1,$a2,50))<br>
&gt;<br>
&gt;         $a3:ODMAnswer(<br>
&gt;         comesAfter($a2,$a3,20),<br>
&gt;         !isEqualThree($a1,$a2,$a3))<br>
&gt;     then<br>
&gt;         System.out.println(&quot;Test 2 works&quot;);<br>
&gt; end<br>
&gt; Result:<br>
&gt; Works perfect without errors.<br>
&gt; ============================================<br>
&gt; Test 3(isEqualMore):<br>
&gt; rule &quot;Test Experiment 3&quot;<br>
&gt; no-loop<br>
&gt;     when<br>
&gt;         $a1:ODMAnswer()<br>
&gt;<br>
&gt;         $a2:ODMAnswer(<br>
&gt;         !isEqual($a1,$a2),<br>
&gt;         comesAfter($a1,$a2,5))<br>
&gt;<br>
&gt;         ($a3:ODMAnswer(<br>
&gt;         comesAfter($a2,$a3,5)) and<br>
&gt;         eval(!isEqualMore($a1,$a2,$a3)))<br>
&gt;     then<br>
&gt;         System.out.println(&quot;Test 3 works&quot;);<br>
&gt; end<br>
&gt; Result:<br>
&gt; Works also without errors (I&#39;m surprised).<br>
&gt; ============================================<br>
&gt; Test 4(isEqualThree):<br>
&gt; rule &quot;Test Experiment 4&quot;<br>
&gt; no-loop<br>
&gt;     when<br>
&gt;         $a1:ODMAnswer()<br>
&gt;<br>
&gt;         $a2:ODMAnswer(<br>
&gt;         !isEqual($a1,$a2),<br>
&gt;         comesAfter($a1,$a2,5))<br>
&gt;<br>
&gt;         ($a3:ODMAnswer(<br>
&gt;         comesAfter($a2,$a3,5)) and<br>
&gt;         eval(!isEqualThree($a1,$a2,$a3)))<br>
&gt;     then<br>
&gt;         System.out.println(&quot;Test 4 works&quot;);<br>
&gt; end<br>
&gt; Result:<br>
&gt; Works perfect, but seems to get more matches<br>
&gt; than the 3. experiment.<br>
&gt; ============================================<br>
&gt; Fazit:<br>
&gt;<br>
&gt; In my eyes there seems to be a problem using a loop in a constraint.<br>
&gt; Even if I use different names (see Test 2), I&#39;m still getting the<br>
&gt; runtime exception. As bonus test-case I&#39;ve tried using Test 3 and<br>
&gt; overloading the function, rather than using a different function name,<br>
&gt; but this also failed.<br>
&gt;<br>
&gt; Seems that I have to use eval() and different names if I want to compare<br>
&gt; multiple named entities, though I still don&#39;t know why. Maybe the isEqual<br>
&gt; call in the loop is calling itself and generating an out of bounds exception<br>
&gt; at the last array entity.<br>
&gt;<br>
&gt; Thank you wolfgang.<br>
&gt;<br>
&gt; JB<br>
&gt; ----- Ursprüngliche Mail -----<br>
&gt; Von: &quot;Wolfgang Laun&quot; &lt;<a href="mailto:wolfgang.laun@gmail.com">wolfgang.laun@gmail.com</a>&gt;<br>
&gt; An: &quot;Rules Users List&quot; &lt;<a href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a>&gt;<br>
&gt; Gesendet: Donnerstag, 7. März 2013 13:36:12<br>
&gt; Betreff: Re: [rules-users] Cannot invoke method because<br>
&gt; of    ArrayIndexOutOfBoundsException<br>
&gt;<br>
&gt; You have lost me - I&#39;m not sure anymore what works and what doesn&#39;t.<br>
&gt;<br>
&gt; Please check or rewrite, using the names<br>
&gt; isEqualMore(Annotation... annos)<br>
&gt; isEqualThree(Annotation a1, Annotation a2, Annotation a3)<br>
&gt;<br>
&gt; 1) not $a5:ODMAnswer(..., ! isEqualX($a3,$a4,$a5) )<br>
&gt; does not work for X==More and<br>
&gt; does not work for X==Three<br>
&gt;<br>
&gt; 2) not( $a5:ODMAnswer(...) and eval( ! isEqualX($a3,$a4,$a5) )<br>
&gt; works for X==More and<br>
&gt; works for X==Three<br>
&gt;<br>
&gt; -W<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt; On 07/03/2013, Bojan Janisch &lt;<a href="mailto:bojan.janisch@scai.fraunhofer.de">bojan.janisch@scai.fraunhofer.de</a>&gt; wrote:<br>
&gt;&gt;&gt; Experiment 1<br>
&gt;&gt;&gt; Please write isEqualThree for 3 Annotation arguments and use this,<br>
&gt;&gt;&gt; just to make sure that these Problems are caused by Drools. (Do NOT<br>
&gt;&gt;&gt; rely on overloading, use another name.)<br>
&gt;&gt;<br>
&gt;&gt; I&#39;ve created an isEqualThree function<br>
&gt;&gt;<br>
&gt;&gt; public static boolean isEqualThree(Annotation a, Annotation b, Annotation<br>
&gt;&gt; c){<br>
&gt;&gt;      if(isEqual(a,b) || isEqual(b,c) || isEqual(a,c)){<br>
&gt;&gt;              return true;<br>
&gt;&gt;      }<br>
&gt;&gt;      return false;<br>
&gt;&gt; }<br>
&gt;&gt;<br>
&gt;&gt; By the way, it works also with overloading, I&#39;ve never had problems with<br>
&gt;&gt; overloading in Drools. And I&#39;ve tested also with different names, the<br>
&gt;&gt; problem<br>
&gt;&gt; remains, even using different function names.<br>
&gt;&gt;<br>
&gt;&gt;&gt; Experiment 2<br>
&gt;&gt;&gt; Using the isEqual as it is now, rewrite the last pattern as:<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; not ( $a5:ODMAnswer(<br>
&gt;&gt;&gt;               isInAnnotation($a1,$a5),<br>
&gt;&gt;&gt;               isBigger($a3,$a5) )<br>
&gt;&gt;&gt;          and<br>
&gt;&gt;&gt;          eval( ! isEqual($a3,$a4,$a5) )<br>
&gt;&gt;&gt;        )<br>
&gt;&gt;<br>
&gt;&gt; Your condition works without problems using the isEqualThree function, it<br>
&gt;&gt; works<br>
&gt;&gt; also if I overload the function. It also works if I put the isEqual<br>
&gt;&gt; condition out<br>
&gt;&gt; of the eval, into the object constraints. But if I want to use my primary<br>
&gt;&gt; idea, using<br>
&gt;&gt; different names,<br>
&gt;&gt;<br>
&gt;&gt; public static boolean isEqualMore(Annotation... a)<br>
&gt;&gt;<br>
&gt;&gt; I still get the same error from the isEqualMore function.<br>
&gt;&gt;<br>
&gt;&gt; java.lang.RuntimeException: cannot invoke method: isEqualMore<br>
&gt;&gt;      at<br>
&gt;&gt; de.fraunhofer.scai.bio.uima.core.deploy.StatusCallbackListenerImpl.entityProcessComplete(StatusCallbackListenerImpl.java:151)<br>
&gt;&gt;      at<br>
&gt;&gt; org.apache.uima.collection.impl.cpm.engine.CPMThreadGroup.notifyListener(CPMThreadGroup.java:103)<br>
&gt;&gt;      at<br>
&gt;&gt; org.apache.uima.collection.impl.cpm.engine.CPMThreadGroup.uncaughtException(CPMThreadGroup.java:86)<br>
&gt;&gt;      at java.lang.Thread.dispatchUncaughtException(Thread.java:1888)<br>
&gt;&gt; Caused by: java.lang.ArrayIndexOutOfBoundsException: 3<br>
&gt;&gt;      at<br>
&gt;&gt; org.mvel2.optimizers.impl.refl.nodes.MethodAccessor.executeAll(MethodAccessor.java:149)<br>
&gt;&gt;      at<br>
&gt;&gt; org.mvel2.optimizers.impl.refl.nodes.MethodAccessor.getValue(MethodAccessor.java:48)<br>
&gt;&gt;      at org.mvel2.ast.ASTNode.getReducedValueAccelerated(ASTNode.java:108)<br>
&gt;&gt;      at<br>
&gt;&gt; org.mvel2.compiler.ExecutableAccessor.getValue(ExecutableAccessor.java:38)<br>
&gt;&gt;      at org.mvel2.ast.Negation.getReducedValueAccelerated(Negation.java:48)<br>
&gt;&gt;      at org.mvel2.MVELRuntime.execute(MVELRuntime.java:85)<br>
&gt;&gt;      at<br>
&gt;&gt; org.mvel2.compiler.CompiledExpression.getValue(CompiledExpression.java:123)<br>
&gt;&gt;      at<br>
&gt;&gt; org.mvel2.compiler.CompiledExpression.getValue(CompiledExpression.java:116)<br>
&gt;&gt;      at org.mvel2.MVEL.executeExpression(MVEL.java:930)<br>
&gt;&gt;      at<br>
&gt;&gt; org.drools.rule.constraint.MvelConditionEvaluator.evaluate(MvelConditionEvaluator.java:70)<br>
&gt;&gt;      at<br>
&gt;&gt; org.drools.rule.constraint.MvelConditionEvaluator.ensureBranchEvaluation(MvelConditionEvaluator.java:113)<br>
&gt;&gt;      at<br>
&gt;&gt; org.drools.rule.constraint.MvelConditionEvaluator.ensureCompleteEvaluation(MvelConditionEvaluator.java:106)<br>
&gt;&gt;      at<br>
&gt;&gt; org.drools.rule.constraint.MvelConditionEvaluator.ensureCompleteEvaluation(MvelConditionEvaluator.java:90)<br>
&gt;&gt;      at<br>
&gt;&gt; org.drools.rule.constraint.MvelConditionEvaluator.getAnalyzedCondition(MvelConditionEvaluator.java:82)<br>
&gt;&gt;      at<br>
&gt;&gt; org.drools.rule.constraint.MvelConstraint.executeJitting(MvelConstraint.java:214)<br>
&gt;&gt;      at<br>
&gt;&gt; org.drools.rule.constraint.MvelConstraint.access$000(MvelConstraint.java:41)<br>
&gt;&gt;      at<br>
&gt;&gt; org.drools.rule.constraint.MvelConstraint$1.run(MvelConstraint.java:201)<br>
&gt;&gt;      at<br>
&gt;&gt; java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1146)<br>
&gt;&gt;      at<br>
&gt;&gt; java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)<br>
&gt;&gt;      at java.lang.Thread.run(Thread.java:679)<br>
&gt;&gt;<br>
&gt;&gt; JB<br>
&gt;&gt;<br>
&gt;&gt; ----- Ursprüngliche Mail -----<br>
&gt;&gt; Von: &quot;Wolfgang Laun&quot; &lt;<a href="mailto:wolfgang.laun@gmail.com">wolfgang.laun@gmail.com</a>&gt;<br>
&gt;&gt; An: &quot;Rules Users List&quot; &lt;<a href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a>&gt;<br>
&gt;&gt; Gesendet: Donnerstag, 7. März 2013 06:46:29<br>
&gt;&gt; Betreff: Re: [rules-users] Cannot invoke method because<br>
&gt;&gt; of   ArrayIndexOutOfBoundsException<br>
&gt;&gt;<br>
&gt;&gt; On 06/03/2013, Bojan Janisch &lt;<a href="mailto:bojan.janisch@scai.fraunhofer.de">bojan.janisch@scai.fraunhofer.de</a>&gt; wrote:<br>
&gt;&gt;&gt; But that&#39;s exactly what java is doing if you say the Arguments are<br>
&gt;&gt;&gt; method(X... xs).<br>
&gt;&gt;&gt; Java is then generating an array of the type you set and you can work<br>
&gt;&gt;&gt; with<br>
&gt;&gt;&gt; xs like an<br>
&gt;&gt;&gt; normal array.<br>
&gt;&gt;<br>
&gt;&gt; Yes, Java, but.<br>
&gt;&gt;<br>
&gt;&gt;&gt; By the way, seems I get this Error<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; Unable to Analyse Expression isEqual(new Annotation[]{$a3,$a4,$a5})<br>
&gt;&gt;&gt; [Error: could not instantiate class]<br>
&gt;&gt;&gt; [Near : {... isEqual(new Annotation[]{$a3,$a4,$a5}) ....}]<br>
&gt;&gt;&gt;                                      ^<br>
&gt;&gt;&gt; [Line: 129, Column: 8]<br>
&gt;&gt;<br>
&gt;&gt; Suspicious, may have to raise a JIRA.<br>
&gt;&gt;<br>
&gt;&gt; Experiment 1<br>
&gt;&gt; Please write isEqualThree for 3 Annotation arguments and use this,<br>
&gt;&gt; just to make sure that these Problems are caused by Drools. (Do NOT<br>
&gt;&gt; rely on overloading, use another name.)<br>
&gt;&gt;<br>
&gt;&gt; Experiment 2<br>
&gt;&gt; Using the isEqual as it is now, rewrite the last pattern as:<br>
&gt;&gt;<br>
&gt;&gt;  not ( $a5:ODMAnswer(<br>
&gt;&gt;                isInAnnotation($a1,$a5),<br>
&gt;&gt;                isBigger($a3,$a5) )<br>
&gt;&gt;           and<br>
&gt;&gt;           eval( ! isEqual($a3,$a4,$a5) )<br>
&gt;&gt;         )<br>
&gt;&gt;<br>
&gt;&gt;<br>
&gt;&gt; -W<br>
&gt;&gt;<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; The changed method is:<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; public static boolean isEqual(Annotation[] a){<br>
&gt;&gt;&gt;     ArrayList&lt;Annotation&gt; outLoop = new<br>
&gt;&gt;&gt; ArrayList&lt;Annotation&gt;(Arrays.asList(a));<br>
&gt;&gt;&gt;     ArrayList&lt;Annotation&gt; inLoop = new<br>
&gt;&gt;&gt; ArrayList&lt;Annotation&gt;(Arrays.asList(a));<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt;     for (Annotation anno1 : outLoop) {<br>
&gt;&gt;&gt;             inLoop.remove(anno1);<br>
&gt;&gt;&gt;             for (Annotation anno2 : inLoop) {<br>
&gt;&gt;&gt;                     if(isEqual(anno1,anno2)){<br>
&gt;&gt;&gt;                             return true;<br>
&gt;&gt;&gt;                     }<br>
&gt;&gt;&gt;             }<br>
&gt;&gt;&gt;     }<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt;     return false;<br>
&gt;&gt;&gt; }<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; ----- Ursprüngliche Mail -----<br>
&gt;&gt;&gt; Von: &quot;Wolfgang Laun&quot; &lt;<a href="mailto:wolfgang.laun@gmail.com">wolfgang.laun@gmail.com</a>&gt;<br>
&gt;&gt;&gt; An: &quot;Rules Users List&quot; &lt;<a href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a>&gt;<br>
&gt;&gt;&gt; Gesendet: Mittwoch, 6. März 2013 17:11:43<br>
&gt;&gt;&gt; Betreff: Re: [rules-users] Cannot invoke method because<br>
&gt;&gt;&gt; of  ArrayIndexOutOfBoundsException<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; I wouldn&#39;t use (X... xs) in this context.<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; Try the simple modification of isEqual( Annotation[] annos ) and<br>
&gt;&gt;&gt; call it with isEqual( new Annotation[]{$a3,$a4,$a5})<br>
&gt;&gt;&gt; and we&#39;ll see what we&#39;ll see.<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; -W<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; On 06/03/2013, Bojan Janisch &lt;<a href="mailto:bojan.janisch@scai.fraunhofer.de">bojan.janisch@scai.fraunhofer.de</a>&gt; wrote:<br>
&gt;&gt;&gt;&gt; Like you wish wolfgang. The complete Rule is:<br>
&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt; rule &quot;Generate Finding_ConceptId&quot;<br>
&gt;&gt;&gt;&gt; no-loop<br>
&gt;&gt;&gt;&gt;     when<br>
&gt;&gt;&gt;&gt;            $a1:ODMAnswer(<br>
&gt;&gt;&gt;&gt;         q1:QuestionId,<br>
&gt;&gt;&gt;&gt;         q1.toLowerCase.contains(&quot;diagnose&quot;) ||<br>
&gt;&gt;&gt;&gt;         q1.toLowerCase.contains(&quot;indication&quot;),<br>
&gt;&gt;&gt;&gt;         q1.toLowerCase.contains(&quot;sections&quot;),<br>
&gt;&gt;&gt;&gt;         a1_begin:begin,<br>
&gt;&gt;&gt;&gt;         label1:ResponseAttribute)<br>
&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt;         $a2:ODMAnswer(<br>
&gt;&gt;&gt;&gt;            ResponseAttribute.contains(label1),<br>
&gt;&gt;&gt;&gt;         QuestionId.contains(&quot;sectionheader&quot;),<br>
&gt;&gt;&gt;&gt;         comesBefore($a1,$a2));<br>
&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt;         $a3:ODMAnswer(<br>
&gt;&gt;&gt;&gt;         q3:QuestionId,<br>
&gt;&gt;&gt;&gt;         !q3.contains(&quot;finding.conceptId&quot;),<br>
&gt;&gt;&gt;&gt;         !q3.contains(&quot;itemGroup&quot;),<br>
&gt;&gt;&gt;&gt;         !q3.contains(&quot;section&quot;),<br>
&gt;&gt;&gt;&gt;         a3_begin:begin,<br>
&gt;&gt;&gt;&gt;         a3_end:end,<br>
&gt;&gt;&gt;&gt;         label2:ResponseAttribute,<br>
&gt;&gt;&gt;&gt;         isInAnnotation($a1,$a3))<br>
&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt;         $a4:ODMAnswer(<br>
&gt;&gt;&gt;&gt;         q4:QuestionId.contains(&quot;finding.conceptId&quot;),<br>
&gt;&gt;&gt;&gt;         a4_begin:begin,<br>
&gt;&gt;&gt;&gt;         comesAfter($a2,$a4),<br>
&gt;&gt;&gt;&gt;         isBetween($a2,$a3,$a4),<br>
&gt;&gt;&gt;&gt;         isInAnnotation($a1,$a4))<br>
&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt;         not $a5:ODMAnswer(<br>
&gt;&gt;&gt;&gt;         isInAnnotation($a1,$a5),<br>
&gt;&gt;&gt;&gt;         isBigger($a3,$a5),<br>
&gt;&gt;&gt;&gt;            !isEqual($a3,$a4,$a5))<br>
&gt;&gt;&gt;&gt;     then<br>
&gt;&gt;&gt;&gt;         String questionId = &quot;finding.conceptId&quot;;<br>
&gt;&gt;&gt;&gt;            String attribute = label1 +&quot; &quot;+ label2;<br>
&gt;&gt;&gt;&gt;            int begin = a4_begin;<br>
&gt;&gt;&gt;&gt;            int ende = a3_end;<br>
&gt;&gt;&gt;&gt;            boolean addToIndexes = true;<br>
&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt;            insert(annotate(aJCas, questionId, attribute, begin, ende,<br>
&gt;&gt;&gt;&gt; addToIndexes));<br>
&gt;&gt;&gt;&gt; end<br>
&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt; The functions are in a seperate FactChecker class, because the<br>
&gt;&gt;&gt;&gt; &quot;incode-comparison&quot;<br>
&gt;&gt;&gt;&gt; was too much of a chaos. So I wrote functions which explains themselves<br>
&gt;&gt;&gt;&gt; what<br>
&gt;&gt;&gt;&gt; they do:<br>
&gt;&gt;&gt;&gt; ==================================================================<br>
&gt;&gt;&gt;&gt; public static boolean isInAnnotation(Annotation a, Annotation b){<br>
&gt;&gt;&gt;&gt;    if(isNull(a,b)){<br>
&gt;&gt;&gt;&gt;            return false;<br>
&gt;&gt;&gt;&gt;    }<br>
&gt;&gt;&gt;&gt;    if(b.getBegin() &gt; a.getBegin() &amp;&amp; b.getEnd() &lt; a.getEnd()){<br>
&gt;&gt;&gt;&gt;            return true;<br>
&gt;&gt;&gt;&gt;    }<br>
&gt;&gt;&gt;&gt;    if(a.getBegin() &gt; b.getBegin() &amp;&amp; a.getEnd() &lt; b.getEnd()){<br>
&gt;&gt;&gt;&gt;            return true;<br>
&gt;&gt;&gt;&gt;    }<br>
&gt;&gt;&gt;&gt;    return false;<br>
&gt;&gt;&gt;&gt; }<br>
&gt;&gt;&gt;&gt; ==================================================================<br>
&gt;&gt;&gt;&gt; public static boolean isInAnnotation(Annotation... a){<br>
&gt;&gt;&gt;&gt;    for (int i = 0; i &lt; a.length; i++){<br>
&gt;&gt;&gt;&gt;            if(i+1 == a.length){<br>
&gt;&gt;&gt;&gt;                    return false;<br>
&gt;&gt;&gt;&gt;            }<br>
&gt;&gt;&gt;&gt;            if(isInAnnotation(a[i], a[i+1])){<br>
&gt;&gt;&gt;&gt;                    return true;<br>
&gt;&gt;&gt;&gt;            }<br>
&gt;&gt;&gt;&gt;    }<br>
&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt;    return false;<br>
&gt;&gt;&gt;&gt; }<br>
&gt;&gt;&gt;&gt; ==================================================================<br>
&gt;&gt;&gt;&gt; public static boolean comesBefore(Annotation a, Annotation b){<br>
&gt;&gt;&gt;&gt;    if(isNull(a,b)){<br>
&gt;&gt;&gt;&gt;            return false;<br>
&gt;&gt;&gt;&gt;    }<br>
&gt;&gt;&gt;&gt;    if(b.getEnd() &lt;= a.getBegin()){<br>
&gt;&gt;&gt;&gt;            return true;<br>
&gt;&gt;&gt;&gt;    }<br>
&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt;    return false;<br>
&gt;&gt;&gt;&gt; }<br>
&gt;&gt;&gt;&gt; ==================================================================<br>
&gt;&gt;&gt;&gt; public static boolean comesAfter(Annotation a, Annotation b){<br>
&gt;&gt;&gt;&gt;    if(isNull(a,b)){<br>
&gt;&gt;&gt;&gt;            return false;<br>
&gt;&gt;&gt;&gt;    }<br>
&gt;&gt;&gt;&gt;    if(a.getEnd() &lt;= b.getBegin()){<br>
&gt;&gt;&gt;&gt;            return true;<br>
&gt;&gt;&gt;&gt;    }<br>
&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt;    return false;<br>
&gt;&gt;&gt;&gt; }<br>
&gt;&gt;&gt;&gt; ==================================================================<br>
&gt;&gt;&gt;&gt; public static boolean isEqual(Annotation a, Annotation b){<br>
&gt;&gt;&gt;&gt;    if(isNull(a,b)){<br>
&gt;&gt;&gt;&gt;            return false;<br>
&gt;&gt;&gt;&gt;    }<br>
&gt;&gt;&gt;&gt;    if(a.equals(b)){<br>
&gt;&gt;&gt;&gt;            return true;<br>
&gt;&gt;&gt;&gt;    }<br>
&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt;    return false;<br>
&gt;&gt;&gt;&gt; }<br>
&gt;&gt;&gt;&gt; ==================================================================<br>
&gt;&gt;&gt;&gt; public static boolean isEqual(Annotation... a){<br>
&gt;&gt;&gt;&gt;    ArrayList&lt;Annotation&gt; outLoop = new<br>
&gt;&gt;&gt;&gt; ArrayList&lt;Annotation&gt;(Arrays.asList(a));<br>
&gt;&gt;&gt;&gt;    ArrayList&lt;Annotation&gt; inLoop = new<br>
&gt;&gt;&gt;&gt; ArrayList&lt;Annotation&gt;(Arrays.asList(a));<br>
&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt;    for (Annotation anno1 : outLoop) {<br>
&gt;&gt;&gt;&gt;            if(anno1 == null){<br>
&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt;            }<br>
&gt;&gt;&gt;&gt;            inLoop.remove(anno1);<br>
&gt;&gt;&gt;&gt;            for (Annotation anno2 : inLoop) {<br>
&gt;&gt;&gt;&gt;                    if(isEqual(anno1,anno2)){<br>
&gt;&gt;&gt;&gt;                            return true;<br>
&gt;&gt;&gt;&gt;                    }<br>
&gt;&gt;&gt;&gt;            }<br>
&gt;&gt;&gt;&gt;    }<br>
&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt;    return false;<br>
&gt;&gt;&gt;&gt; }<br>
&gt;&gt;&gt;&gt; ==================================================================<br>
&gt;&gt;&gt;&gt; public static boolean isNull(Annotation... a){<br>
&gt;&gt;&gt;&gt;    for (Annotation annotation : a) {<br>
&gt;&gt;&gt;&gt;            if(annotation == null){<br>
&gt;&gt;&gt;&gt;                    return true;<br>
&gt;&gt;&gt;&gt;            }<br>
&gt;&gt;&gt;&gt;    }<br>
&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt;    return false;<br>
&gt;&gt;&gt;&gt; }<br>
&gt;&gt;&gt;&gt; ==================================================================<br>
&gt;&gt;&gt;&gt; public static boolean isBigger(Annotation a, Annotation b){<br>
&gt;&gt;&gt;&gt;    if(isNull(a,b)){<br>
&gt;&gt;&gt;&gt;            return false;<br>
&gt;&gt;&gt;&gt;    }<br>
&gt;&gt;&gt;&gt;    if(a.getBegin() == b.getBegin() &amp;&amp; a.getEnd() &lt; b.getEnd()){<br>
&gt;&gt;&gt;&gt;            return true;<br>
&gt;&gt;&gt;&gt;    }<br>
&gt;&gt;&gt;&gt;    if(b.getBegin() &lt; a.getBegin() &amp;&amp; a.getEnd() == b.getEnd()){<br>
&gt;&gt;&gt;&gt;            return true;<br>
&gt;&gt;&gt;&gt;    }<br>
&gt;&gt;&gt;&gt;    if(b.getBegin() &lt; a.getBegin() &amp;&amp; a.getEnd() &lt; b.getEnd()){<br>
&gt;&gt;&gt;&gt;            return true;<br>
&gt;&gt;&gt;&gt;    }<br>
&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt;    return false;<br>
&gt;&gt;&gt;&gt; }<br>
&gt;&gt;&gt;&gt; ==================================================================<br>
&gt;&gt;&gt;&gt; public static boolean isBetween(Annotation a, Annotation b, Annotation<br>
&gt;&gt;&gt;&gt; c){<br>
&gt;&gt;&gt;&gt;    if(isNull(a,b,c)){<br>
&gt;&gt;&gt;&gt;            return false;<br>
&gt;&gt;&gt;&gt;    }<br>
&gt;&gt;&gt;&gt;    Annotation min = getMin(a,b);<br>
&gt;&gt;&gt;&gt;    Annotation max = getMax(a,b);<br>
&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt;    if(isOverlapping(a,c) || isOverlapping(b,c)){<br>
&gt;&gt;&gt;&gt;            return true;<br>
&gt;&gt;&gt;&gt;    }<br>
&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt;    if(c.getBegin() &gt; min.getEnd() &amp;&amp; c.getEnd() &lt; max.getBegin()){<br>
&gt;&gt;&gt;&gt;            return true;<br>
&gt;&gt;&gt;&gt;    }<br>
&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt;    return false;<br>
&gt;&gt;&gt;&gt; }<br>
&gt;&gt;&gt;&gt; ==================================================================<br>
&gt;&gt;&gt;&gt; public static Annotation getMax(Annotation a, Annotation b){<br>
&gt;&gt;&gt;&gt;    isNull(a,b);<br>
&gt;&gt;&gt;&gt;    if(a.getBegin() &gt;= b.getBegin()){<br>
&gt;&gt;&gt;&gt;            return a;<br>
&gt;&gt;&gt;&gt;    }<br>
&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt;    return b;<br>
&gt;&gt;&gt;&gt; }<br>
&gt;&gt;&gt;&gt; ==================================================================<br>
&gt;&gt;&gt;&gt; public static Annotation getMin(Annotation a, Annotation b){<br>
&gt;&gt;&gt;&gt;    isNull(a,b);<br>
&gt;&gt;&gt;&gt;    if(a.getEnd() &lt;= b.getEnd()){<br>
&gt;&gt;&gt;&gt;            return a;<br>
&gt;&gt;&gt;&gt;    }<br>
&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt;    return b;<br>
&gt;&gt;&gt;&gt; }<br>
&gt;&gt;&gt;&gt; ==================================================================<br>
&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt; I&#39;ve posted all functions that are used by the rule. Actually it crushes<br>
&gt;&gt;&gt;&gt; if I use more than 2 statements in the isEqual() call in $a5.<br>
&gt;&gt;&gt;&gt; It works with !isEqual($a3,$a4) &amp;&amp; !isEqual($a3,$a5) &amp;&amp;<br>
&gt;&gt;&gt;&gt; !isEqual($a4,$a5)<br>
&gt;&gt;&gt;&gt; but not with !isEqual($a3,$a4,$a5).<br>
&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt; So do you got an idea where the problem comes from?<br>
&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt; JB<br>
&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt; ----- Ursprüngliche Mail -----<br>
&gt;&gt;&gt;&gt; Von: &quot;Wolfgang Laun&quot; &lt;<a href="mailto:wolfgang.laun@gmail.com">wolfgang.laun@gmail.com</a>&gt;<br>
&gt;&gt;&gt;&gt; An: &quot;Rules Users List&quot; &lt;<a href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a>&gt;<br>
&gt;&gt;&gt;&gt; Gesendet: Mittwoch, 6. März 2013 15:09:47<br>
&gt;&gt;&gt;&gt; Betreff: Re: [rules-users] Cannot invoke method because<br>
&gt;&gt;&gt;&gt; of ArrayIndexOutOfBoundsException<br>
&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt; Nice try - but, please, don&#39;t. Kindly post the code that actually<br>
&gt;&gt;&gt;&gt; causes your problem.<br>
&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt; -W<br>
&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt; On 06/03/2013, Bojan Janisch &lt;<a href="mailto:bojan.janisch@scai.fraunhofer.de">bojan.janisch@scai.fraunhofer.de</a>&gt; wrote:<br>
&gt;&gt;&gt;&gt;&gt; Hello Guys,<br>
&gt;&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt;&gt; sorry to bother you with this problem, but I&#39;m out of ideas.<br>
&gt;&gt;&gt;&gt;&gt; I&#39;m using Drools in textmining-context and in basic I have<br>
&gt;&gt;&gt;&gt;&gt; a function that checks 2 named entites for equality to<br>
&gt;&gt;&gt;&gt;&gt; ensure that the entities are all different and that the rules<br>
&gt;&gt;&gt;&gt;&gt; do work only on different named entity objects:<br>
&gt;&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt;&gt; public static boolean isEqual(Annotation a, Annotation b){<br>
&gt;&gt;&gt;&gt;&gt; if(a.equals(b)){<br>
&gt;&gt;&gt;&gt;&gt;    return true;<br>
&gt;&gt;&gt;&gt;&gt; }<br>
&gt;&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt;&gt; return false;<br>
&gt;&gt;&gt;&gt;&gt; }<br>
&gt;&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt;&gt; Sometimes there are conditions that need tests of more than<br>
&gt;&gt;&gt;&gt;&gt; 2 named entites. For this I&#39;ve written a super method that<br>
&gt;&gt;&gt;&gt;&gt; calls the isEqual method in a loop:<br>
&gt;&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt;&gt; public static boolean isEqual(Annotation... a){<br>
&gt;&gt;&gt;&gt;&gt; ArrayList&lt;Annotation&gt; outLoop = new<br>
&gt;&gt;&gt;&gt;&gt; ArrayList&lt;Annotation&gt;(Arrays.asList(a));<br>
&gt;&gt;&gt;&gt;&gt; ArrayList&lt;Annotation&gt; inLoop = new<br>
&gt;&gt;&gt;&gt;&gt; ArrayList&lt;Annotation&gt;(Arrays.asList(a));<br>
&gt;&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt;&gt; for (Annotation anno1 : outLoop) {<br>
&gt;&gt;&gt;&gt;&gt;    inLoop.remove(anno1);<br>
&gt;&gt;&gt;&gt;&gt;    for (Annotation anno2 : inLoop) {<br>
&gt;&gt;&gt;&gt;&gt;       if(isEqual(anno1,anno2)){<br>
&gt;&gt;&gt;&gt;&gt;       return true;<br>
&gt;&gt;&gt;&gt;&gt;       }<br>
&gt;&gt;&gt;&gt;&gt;    }<br>
&gt;&gt;&gt;&gt;&gt; }<br>
&gt;&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt;&gt; return false;<br>
&gt;&gt;&gt;&gt;&gt; }<br>
&gt;&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt;&gt; My rules could (theoretically) now call the function<br>
&gt;&gt;&gt;&gt;&gt; eval(isEqual($ne1,$ne2)) or<br>
&gt;&gt;&gt;&gt;&gt; eval(isEqual($ne1,$ne2,$ne3) or even<br>
&gt;&gt;&gt;&gt;&gt; eval(isEqual($ne1,$ne2,$ne3,$ne4,$ne5)) and so on.<br>
&gt;&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt;&gt; So there starts my problem:<br>
&gt;&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt;&gt; Each time I&#39;m getting an ArrayIndexOutOfBounds Exception from the<br>
&gt;&gt;&gt;&gt;&gt; second<br>
&gt;&gt;&gt;&gt;&gt; method that looks like this:<br>
&gt;&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt;&gt; java.lang.RuntimeException: cannot invoke method: isEqual<br>
&gt;&gt;&gt;&gt;&gt;         ...<br>
&gt;&gt;&gt;&gt;&gt;   at java.lang.Thread.dispatchUncaughtException(Thread.java:1888)<br>
&gt;&gt;&gt;&gt;&gt; Caused by: java.lang.ArrayIndexOutOfBoundsException: 3<br>
&gt;&gt;&gt;&gt;&gt;   at<br>
&gt;&gt;&gt;&gt;&gt; org.mvel2.optimizers.impl.refl.nodes.MethodAccessor.executeAll(MethodAccessor.java:149)<br>
&gt;&gt;&gt;&gt;&gt;   at<br>
&gt;&gt;&gt;&gt;&gt; org.mvel2.optimizers.impl.refl.nodes.MethodAccessor.getValue(MethodAccessor.java:48)<br>
&gt;&gt;&gt;&gt;&gt;   at org.mvel2.ast.ASTNode.getReducedValueAccelerated(ASTNode.java:108)<br>
&gt;&gt;&gt;&gt;&gt;   at<br>
&gt;&gt;&gt;&gt;&gt; org.mvel2.compiler.ExecutableAccessor.getValue(ExecutableAccessor.java:38)<br>
&gt;&gt;&gt;&gt;&gt;         ...<br>
&gt;&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt;&gt; Could someone explain me what&#39;s wrong with my code? Thanks for any<br>
&gt;&gt;&gt;&gt;&gt; help.<br>
&gt;&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt;&gt; Greetings<br>
&gt;&gt;&gt;&gt;&gt; JB<br>
&gt;&gt;&gt;&gt;&gt; _______________________________________________<br>
&gt;&gt;&gt;&gt;&gt; rules-users mailing list<br>
&gt;&gt;&gt;&gt;&gt; <a href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a><br>
&gt;&gt;&gt;&gt;&gt; <a href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>
&gt;&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt; _______________________________________________<br>
&gt;&gt;&gt;&gt; rules-users mailing list<br>
&gt;&gt;&gt;&gt; <a href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a><br>
&gt;&gt;&gt;&gt; <a href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>
&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt; _______________________________________________<br>
&gt;&gt;&gt;&gt; rules-users mailing list<br>
&gt;&gt;&gt;&gt; <a href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a><br>
&gt;&gt;&gt;&gt; <a href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; _______________________________________________<br>
&gt;&gt;&gt; rules-users mailing list<br>
&gt;&gt;&gt; <a href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a><br>
&gt;&gt;&gt; <a href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; _______________________________________________<br>
&gt;&gt;&gt; rules-users mailing list<br>
&gt;&gt;&gt; <a href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a><br>
&gt;&gt;&gt; <a href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>
&gt;&gt;<br>
&gt;&gt; _______________________________________________<br>
&gt;&gt; rules-users mailing list<br>
&gt;&gt; <a href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a><br>
&gt;&gt; <a href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>
&gt;&gt;<br>
&gt;&gt; _______________________________________________<br>
&gt;&gt; rules-users mailing list<br>
&gt;&gt; <a href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a><br>
&gt;&gt; <a href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>
&gt;<br>
&gt; _______________________________________________<br>
&gt; rules-users mailing list<br>
&gt; <a href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a><br>
&gt; <a href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>
&gt;<br>
&gt; _______________________________________________<br>
&gt; rules-users mailing list<br>
&gt; <a href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a><br>
&gt; <a href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>
</blockquote></div><br>