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

A NPE occurs silently when execute a complex rule a lot of time

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Done
    • Icon: Major Major
    • 5.5.1.Final, 6.0.0.Alpha9
    • 5.5.0.Final
    • None
    • None

      Found this bug when I update from drools v5.3
      Here are the rule that simulate this bug :

      rule "toto"
       when
        $bean:Bean (
          anotherBean!=null, 
          (
            anotherBean.anotherBean !=null
            &&
            (
             (
              anotherBean.anotherBean.attribute=="TOTO"
              &&
              anotherBean.attribute=="TOTO"
             )
             ||
             (
              anotherBean.anotherBean.attribute=="TATA"
              &&
              anotherBean.attribute=="TATA"
             )
            )
           )
           ||
           (
            anotherBean.attribute=="TOTO"
           )
          )
        then
          ...
      end
      

      A part of main:

      for (int i = 0; i < 400; i++) {
       Bean input1 = new Bean();
       input1.setAttribute("" + i);
       input1.setAnotherBean(new Bean());
       kbase.newStatelessKnowledgeSession().execute(Arrays.asList(input1));
      }
      

      At one time, the log print this exception. Units tests of my application are 100%, but this exception in the log is quite disturbing

      java.lang.RuntimeException: cannot invoke getter: getAnotherBean [declr.class: fr.jsoula.jboss.drools.bugs.npe.Bean; act.class: fr.jsoula.jboss.drools.bugs.npe.Bean] (see trace)
      	at org.mvel2.optimizers.impl.refl.nodes.GetterAccessor.getValue(GetterAccessor.java:74)
      	at org.mvel2.ast.ASTNode.getReducedValueAccelerated(ASTNode.java:108)
      	at org.mvel2.ast.BinaryOperation.getReducedValueAccelerated(BinaryOperation.java:108)
      	at org.mvel2.ast.And.getReducedValueAccelerated(And.java:34)
      	at org.mvel2.MVELRuntime.execute(MVELRuntime.java:85)
      	at org.mvel2.compiler.CompiledExpression.getDirectValue(CompiledExpression.java:123)
      	at org.mvel2.compiler.CompiledExpression.getValue(CompiledExpression.java:119)
      	at org.mvel2.compiler.CompiledExpression.getValue(CompiledExpression.java:113)
      	at org.mvel2.MVEL.executeExpression(MVEL.java:930)
      	at org.drools.rule.constraint.MvelConditionEvaluator.evaluate(MvelConditionEvaluator.java:70)
      	at org.drools.rule.constraint.MvelConditionEvaluator.ensureBranchEvaluation(MvelConditionEvaluator.java:117)
      	at org.drools.rule.constraint.MvelConditionEvaluator.ensureCompleteEvaluation(MvelConditionEvaluator.java:101)
      	at org.drools.rule.constraint.MvelConditionEvaluator.ensureBranchEvaluation(MvelConditionEvaluator.java:120)
      	at org.drools.rule.constraint.MvelConditionEvaluator.ensureCompleteEvaluation(MvelConditionEvaluator.java:102)
      	at org.drools.rule.constraint.MvelConditionEvaluator.ensureBranchEvaluation(MvelConditionEvaluator.java:120)
      	at org.drools.rule.constraint.MvelConditionEvaluator.ensureCompleteEvaluation(MvelConditionEvaluator.java:101)
      	at org.drools.rule.constraint.MvelConditionEvaluator.ensureCompleteEvaluation(MvelConditionEvaluator.java:90)
      	at org.drools.rule.constraint.MvelConditionEvaluator.getAnalyzedCondition(MvelConditionEvaluator.java:82)
      	at org.drools.rule.constraint.MvelConstraint.executeJitting(MvelConstraint.java:270)
      	at org.drools.rule.constraint.MvelConstraint.access$200(MvelConstraint.java:51)
      	at org.drools.rule.constraint.MvelConstraint$ConditionJitter.run(MvelConstraint.java:250)
      	at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:651)
      	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:676)
      	at java.lang.Thread.run(Thread.java:595)
      31
      Caused by: java.lang.RuntimeException: cannot invoke getter: getAnotherBean [declr.class: fr.jsoula.jboss.drools.bugs.npe.Bean; act.class: fr.jsoula.jboss.drools.bugs.npe.Bean] (see trace)
      	at org.mvel2.optimizers.impl.refl.nodes.GetterAccessor.getValue(GetterAccessor.java:74)
      	at org.mvel2.optimizers.impl.refl.nodes.GetterAccessor.getValue(GetterAccessor.java:40)
      	... 23 more
      Caused by: java.lang.RuntimeException: unable to invoke method: fr.jsoula.jboss.drools.bugs.npe.Bean.getAttribute: target of method is null
      	at org.mvel2.optimizers.impl.refl.nodes.GetterAccessor.getValue(GetterAccessor.java:66)
      	at org.mvel2.optimizers.impl.refl.nodes.GetterAccessor.getValue(GetterAccessor.java:40)
      	... 24 more
      Caused by: java.lang.NullPointerException
      	at sun.reflect.GeneratedMethodAccessor2.invoke(Unknown Source)
      	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      	at java.lang.reflect.Method.invoke(Method.java:592)
      	at org.mvel2.optimizers.impl.refl.nodes.GetterAccessor.getValue(GetterAccessor.java:43)
      	... 25 more
      

            mfusco@redhat.com Mario Fusco
            jsoula Jérémy SOULA (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: