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

Extra space between variable and field name in LHS causes crash

    Details

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

      Description

      Writing a condition as "$co:Item(attachment in ($c, $c. parent))" fails at runtime with an uninformative exception. Removing the extra space and writing "$c.parent" corrects the problem.

      Below is the rule file, sample code and exception trace.

      package com.sample

      import com.sample.DroolsTest.Child;
      import com.sample.DroolsTest.Parent;
      import com.sample.DroolsTest.Item;

      rule "My Rule"

      when
      $c:Child()
      $co:Item(attachment in ($c, $c. parent))
      then
      System.out.println("wawa");
      end

      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.event.DebugWorkingMemoryEventListener;
      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(); }

      catch (Throwable t)

      { t.printStackTrace(); }

      }

      private static RuleBase readRule() throws Exception

      { 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 static class Parent {
      }

      public static class Child {
      private Parent parent;

      public Parent getParent()

      { return parent; }

      }

      public static class Item {
      private Object attachment;

      public Object getAttachment()

      { return attachment; }

      }

      }

      java.lang.NullPointerException
      at org.drools.reteoo.builder.PatternBuilder.createConstraints(PatternBuilder.java:128)
      at org.drools.reteoo.builder.PatternBuilder.attachPattern(PatternBuilder.java:72)
      at org.drools.reteoo.builder.PatternBuilder.build(PatternBuilder.java:54)
      at org.drools.reteoo.builder.GroupElementBuilder$AndBuilder.build(GroupElementBuilder.java:112)
      at org.drools.reteoo.builder.GroupElementBuilder.build(GroupElementBuilder.java:70)
      at org.drools.reteoo.builder.ReteooRuleBuilder.addSubRule(ReteooRuleBuilder.java:136)
      at org.drools.reteoo.builder.ReteooRuleBuilder.addRule(ReteooRuleBuilder.java:109)
      at org.drools.reteoo.ReteooBuilder.addRule(ReteooBuilder.java:116)
      at org.drools.reteoo.ReteooRuleBase.addRule(ReteooRuleBase.java:262)
      at org.drools.common.AbstractRuleBase.addPackage(AbstractRuleBase.java:333)
      at com.sample.DroolsTest.readRule(DroolsTest.java:33)
      at com.sample.DroolsTest.main(DroolsTest.java:20)

        Gliffy Diagrams

          Attachments

            Activity

              People

              • Assignee:
                tirelli Edson Tirelli
                Reporter:
                agattik Alexandre Gattiker
              • Votes:
                0 Vote for this issue
                Watchers:
                0 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: