Uploaded image for project: 'Drools'
  1. Drools
  2. DROOLS-11

ArrayIndexOutOfBoundsException when calling a method with more than two varargs parameters

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • Major
    • 6.0.0.Alpha9
    • None
    • None
    • None
    • Low

    Description

      I have a rule which uses a Java Interface ILogService with Varargs Parameter. When the rule is evaluated, an ArrayIndexOutOfBoundsException is thrown within MVEL2 code which evaluates the varargs parameters. The MVEL2 code works with two varargs parameters, but not with more than two varargs parameters.

      Drools Version: 5.5.0.Final

      // Java Interface ILogService with varargs
      public interface ILogService {
      	public void debug(String logMessage, Object... arg);
      	...
      }
      
      // Global definition ILogService
      global ILogService log;
      
      rule "..."
      	ruleflow-group  " ... "
      	no-loop  true
      	salience  2
      	when
          	...
      	then
      		log.debug("{} {} {}", operation.getOrderNumber(), operation.getOperationNumber(), Long.valueOf($operationId));
      end
      
      • Breakpoint in org.mvel2.optimizers.impl.refl.nodes.MethodAccessor.executeAll(Object, VariableResolverFactory, Method), Line 149:
        for (int i = 0; i < vararg.length; i++) vararg[i] = parms[parms.length - length + i].getValue(ctx, vars);
        
      • Debugging of this context:
        vararg.length = 3
        parms.length = 4
        length = 2
        i = 0 => vararg[0] = parms[4-2+0].getValue(ctx, vars);
        i = 1 => vararg[1] = parms[4-2+1].getValue(ctx, vars);
        i = 2 => vararg[2] = parms[4-2+2].getValue(ctx, vars); => vararg[2] = parms[4].getValue(ctx, vars); => java.lang.ArrayIndexOutOfBoundsException: 4 (because params is an array of length 4 and maximum index 3.
        

      Complete Stacktrace:

      MethodAccessor.executeAll(Object, VariableResolverFactory, Method) line: 149	
      MethodAccessor.getValue(Object, Object, VariableResolverFactory) line: 48	
      VariableAccessor.getValue(Object, Object, VariableResolverFactory) line: 37	
      ASTNode.getReducedValueAccelerated(Object, Object, VariableResolverFactory) line: 108	
      MVELRuntime.execute(boolean, CompiledExpression, Object, VariableResolverFactory) line: 85	
      CompiledExpression.getDirectValue(Object, VariableResolverFactory) line: 123	
      CompiledExpression.getValue(Object, VariableResolverFactory) line: 119	
      MVEL.executeExpression(Object, Object, VariableResolverFactory) line: 930	
      MVELConsequence.evaluate(KnowledgeHelper, WorkingMemory) line: 104	
      DefaultAgenda.fireActivation(Activation) line: 1287	
      DefaultAgenda.fireNextItem(AgendaFilter) line: 1221	
      DefaultAgenda.fireAllRules(AgendaFilter, int) line: 1456	
      ReteooStatefulSession(AbstractWorkingMemory).fireAllRules(AgendaFilter, int) line: 710	
      ReteooStatefulSession(AbstractWorkingMemory).fireAllRules() line: 674	
      StatefulKnowledgeSessionImpl.fireAllRules() line: 230	
      ...
      

      I tried to create a simple test case to reproduce it, but the test case always worked - no Exception. but there was also another Stacktrace when stopping at a breakpoint in the LogService:

      LogService.info(String, Object...) line: 60	
      Rule_Hello_World_4df945f15bc043ef85d8e1317cd461f1.defaultConsequence(KnowledgeHelper, ILogService) line: 7	
      Rule_Hello_World_4df945f15bc043ef85d8e1317cd461f1DefaultConsequenceInvokerGenerated.evaluate(KnowledgeHelper, WorkingMemory) line: not available	
      Rule_Hello_World_4df945f15bc043ef85d8e1317cd461f1DefaultConsequenceInvoker.evaluate(KnowledgeHelper, WorkingMemory) line: not available	
      DefaultAgenda.fireActivation(Activation) line: 1287	
      DefaultAgenda.fireNextItem(AgendaFilter) line: 1221	
      DefaultAgenda.fireAllRules(AgendaFilter, int) line: 1456	
      

      Attachments

        Activity

          People

            mfusco@redhat.com Mario Fusco
            abentele_jira Andreas Bentele (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: