[jboss-jira] [JBoss JIRA] Created: (JBRULES-1034) NullPointerException in a simple test

Christian Spurk (JIRA) jira-events at lists.jboss.org
Fri Jul 27 10:42:48 EDT 2007


NullPointerException in a simple test
-------------------------------------

                 Key: JBRULES-1034
                 URL: http://jira.jboss.com/jira/browse/JBRULES-1034
             Project: JBoss Rules
          Issue Type: Bug
      Security Level: Public (Everyone can see)
    Affects Versions:  4.0.0.GA
            Reporter: Christian Spurk
         Assigned To: Mark Proctor
            Priority: Blocker


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.


-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://jira.jboss.com/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        



More information about the jboss-jira mailing list