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

NullPointerException in a simple test

    XMLWordPrintable

    Details

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

      Description

      I have the class and rule files setup listed below and if I run the SimpleTest class, I get the following exception:

      Exception in thread "main" java.lang.NullPointerException
      at org.drools.reteoo.CompositeObjectSinkAdapter$HashKey.equals(CompositeObjectSinkAdapter.java:608)
      at org.drools.util.AbstractHashTable$EqualityEquals.equal(AbstractHashTable.java:345)
      at org.drools.util.ObjectHashMap.get(ObjectHashMap.java:86)
      at org.drools.reteoo.CompositeObjectSinkAdapter.propagateAssertObject(CompositeObjectSinkAdapter.java:295)
      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.SimpleTest.main(SimpleTest.java:22)

      Following the setup of four files:

      /* SimpleTest.java */
      package com.sample;
      // ... imports removed for brevity
      public class SimpleTest {
      public static final void main(String[] args) throws Exception

      { PackageBuilder builder = new PackageBuilder(); builder.addPackageFromDrl(new InputStreamReader(SimpleTest.class .getResourceAsStream("/rf1.drl"))); builder.addPackageFromDrl(new InputStreamReader(SimpleTest.class .getResourceAsStream("/rf2.drl"))); RuleBase rb = RuleBaseFactory.newRuleBase(); rb.addPackage(builder.getPackage()); WorkingMemory wm = rb.newStatefulSession(); wm.insert(new Task()); // <-- crashes here wm.fireAllRules(); }

      }

      /* Task.java */
      package com.sample;
      public class Task {
      private String next = null;
      public String getNext()

      { return next; }

      public void setNext(String next)

      { this.next = next; }

      }

      // rf1.drl
      package com.sample
      rule "r0"
      when
      Task( next == null ); # <-- change to "x"
      then
      System.out.println("r0");
      end
      rule "r1"
      when
      Task( next == "1" );
      then
      System.out.println("r1");
      end

      // rf2.drl
      package com.sample
      rule "r2"
      when
      Task( next == "2" );
      then
      System.out.println("r1");
      end

      I've marked the position in the source code at which the run crashes.

      Some more strange things relating to this problem:

      • If I change the 'null' in rf1.drl to '""' (empty string), the problem remains.
      • If I change the 'null' in rf1.drl to '"x"' (or some other non-empty string), then the exception is gone.
      • If I remove any of the two rule files, the exception is gone, too.

        Gliffy Diagrams

          Attachments

            Activity

              People

              • Assignee:
                tirelli Edson Tirelli
                Reporter:
                Chriki Christian Spurk
              • Votes:
                0 Vote for this issue
                Watchers:
                0 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: