Uploaded image for project: 'JBRULES'
  1. JBRULES
  2. JBRULES-1045

Predicate Null Pointer exception when using Java 5 Enum

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed (View Workflow)
    • Priority: Minor
    • Resolution: Done
    • Affects Version/s: 4.0.0.GA
    • Fix Version/s: 4.0.1
    • Component/s: None
    • Labels:
      None
    • Environment:

      Windows XP sp2, Jboss Rules 4.0.0 GA, Sun Java 1.5.0_11 VM, Eclipse 3.3 with JBOss Rules IDE 4.0

      Description

      Java 5 enums as column constraint do not work as expected. Cqauses Null pointer exception in mvel.MVELPredicateExpression.evaluate.

      Using modified Eclipse generated Sample project to demonstrate:

      DroolsTest now has an Enum for it's Message:

      package com.sample;

      import java.io.InputStreamReader;
      import java.io.Reader;

      import org.drools.RuleBase;
      import org.drools.RuleBaseFactory;
      import org.drools.WorkingMemory;
      import org.drools.compiler.PackageBuilder;
      import org.drools.rule.Package;

      /**

      • This is a sample file to launch a rule package from a rule source file.
        */
        public class DroolsTest {

      public static final void main(String[] args) {
      try

      { RuleBase ruleBase = readRule(); WorkingMemory workingMemory = ruleBase.newStatefulSession(); workingMemory.insert(Message.HELLO); workingMemory.fireAllRules(); }

      catch (Throwable t)

      { t.printStackTrace(); }

      }

      private static RuleBase readRule() throws Exception

      { // read in the source Reader source = new InputStreamReader(DroolsTest.class.getResourceAsStream("/Sample.drl")); PackageBuilder builder = new PackageBuilder(); builder.addPackageFromDrl(source); Package pkg = builder.getPackage(); RuleBase ruleBase = RuleBaseFactory.newRuleBase(); ruleBase.addPackage(pkg); return ruleBase; }

      public enum Message

      { GOODBYE, HELLO; }

      }

      The Sample.drl rule is modified to:

      package com.sample

      import com.sample.DroolsTest.Message;

      rule "Hello World"
      when
      m : Message( Message.HELLO )
      then
      System.out.println( m );
      end

      Stack trace given is:
      org.drools.RuntimeDroolsException: Exception executing predicate org.drools.base.mvel.MVELPredicateExpression@10382a9
      at org.drools.rule.PredicateConstraint.isAllowed(PredicateConstraint.java:197)
      at org.drools.reteoo.AlphaNode.assertObject(AlphaNode.java:122)
      at org.drools.reteoo.SingleObjectSinkAdapter.propagateAssertObject(SingleObjectSinkAdapter.java:20)
      at org.drools.reteoo.ObjectTypeNode.assertObject(ObjectTypeNode.java:168)
      at org.drools.reteoo.Rete.assertObject(Rete.java:168)
      at org.drools.reteoo.ReteooRuleBase.assertObject(ReteooRuleBase.java:190)
      at org.drools.reteoo.ReteooWorkingMemory.doInsert(ReteooWorkingMemory.java:70)
      at org.drools.common.AbstractWorkingMemory.insert(AbstractWorkingMemory.java:848)
      at org.drools.common.AbstractWorkingMemory.insert(AbstractWorkingMemory.java:822)
      at org.drools.common.AbstractWorkingMemory.insert(AbstractWorkingMemory.java:623)
      at com.sample.DroolsTest.main(DroolsTest.java:21)
      Caused by: java.lang.NullPointerException
      at org.drools.base.mvel.MVELPredicateExpression.evaluate(MVELPredicateExpression.java:39)
      at org.drools.rule.PredicateConstraint.isAllowed(PredicateConstraint.java:191)
      ... 10 more

        Gliffy Diagrams

          Attachments

            Activity

              People

              • Assignee:
                tirelli Edson Tirelli
                Reporter:
                cbarham christopher barham
              • Votes:
                0 Vote for this issue
                Watchers:
                1 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: