[jboss-jira] [JBoss JIRA] Commented: (JBRULES-904) ArrayIndexOutOfBoundsException in org.drools.util.TupleIndexHashTable.toArray

Brian Stiles (JIRA) jira-events at lists.jboss.org
Tue Jun 26 16:09:12 EDT 2007


    [ http://jira.jboss.com/jira/browse/JBRULES-904?page=comments#action_12366915 ] 
            
Brian Stiles commented on JBRULES-904:
--------------------------------------

I ran into this too.  The problem appears to be faulty logic dealing with hash collisions in org.drools.util.TupleIndexHashTable.

I stepped through and found that org.drools.util.TupleIndexHashTable.add(ReteTuple) calls org.drools.util.TupleIndexHashTable.getOrCreate(ReteTuple) to create the new entry and then calls org.drools.util.TupleIndexHashTable.FieldIndexEntry.add(ReteTuple) to set the tuple as the new entry's "first" and the entry's "first" as the tuple's "next" (inserting the new tuple/entry in the chain).  The "add" logic assumes that entry is not new/uninitialized.  The entry's "first" has never been set and is null, and so the tuple's "next" is always null.

The following patch solves the immediate problem.  There may be a better way to do it.

By the way, I'm a new JBoss Rules user.  Thanks so much for the great product.  I'm very pleased with it.

---


Index: /Users/bstiles/Development/Projects/Drools/trunk/drools-core/src/main/java/org/drools/util/TupleIndexHashTable.java
===================================================================
--- /Users/bstiles/Development/Projects/Drools/trunk/drools-core/src/main/java/org/drools/util/TupleIndexHashTable.java	(revision 12870)
+++ /Users/bstiles/Development/Projects/Drools/trunk/drools-core/src/main/java/org/drools/util/TupleIndexHashTable.java	(working copy)
@@ -289,6 +289,9 @@
         if ( entry == null ) {
             entry = new FieldIndexEntry( this.index,
                                          hashCode );
+            if (this.table[index] != null) {
+                entry.first = ((FieldIndexEntry)this.table[index]).first;
+            }
             entry.next = this.table[index];
             this.table[index] = entry;
 


> ArrayIndexOutOfBoundsException in org.drools.util.TupleIndexHashTable.toArray
> -----------------------------------------------------------------------------
>
>                 Key: JBRULES-904
>                 URL: http://jira.jboss.com/jira/browse/JBRULES-904
>             Project: JBoss Rules
>          Issue Type: Bug
>      Security Level: Public(Everyone can see) 
>    Affects Versions:  4.0.0.MR3
>         Environment: Java 1.5
>            Reporter: Dirk Bergstrom
>         Assigned To: Edson Tirelli
>         Attachments: real-testcase.tgz, testcase.tar.gz
>
>
> When asserting a particular object type, I get the following stacktrace:
> java.lang.ArrayIndexOutOfBoundsException: 26
>         at org.drools.util.TupleIndexHashTable.toArray(TupleIndexHashTable.java:178)
>         at org.drools.reteoo.CollectNode.assertObject(CollectNode.java:212)
>         at org.drools.reteoo.CompositeObjectSinkAdapter.propagateAssertObject(CompositeObjectSinkAdapter.java:317)
>         at org.drools.reteoo.ObjectTypeNode.assertObject(ObjectTypeNode.java:183)
>         at org.drools.reteoo.Rete.assertObject(Rete.java:121)
>         at org.drools.reteoo.ReteooRuleBase.assertObject(ReteooRuleBase.java:201)
>         at org.drools.reteoo.ReteooWorkingMemory.doAssertObject(ReteooWorkingMemory.java:70)
>         at org.drools.common.AbstractWorkingMemory.assertObject(AbstractWorkingMemory.java:766)
>         at org.drools.common.AbstractWorkingMemory.assertObject(AbstractWorkingMemory.java:578)
>         at net.juniper.dash.data.DataSource.reconcileAssertedRecords(DataSource.java:250)
>         at net.juniper.dash.data.DataSource.populateRecords(DataSource.java:193)
>         at net.juniper.dash.Updater$DataSourceProcessor.work(Updater.java:177)
>         at net.juniper.dash.Refresher.run(Refresher.java:69)
> I added some println() statements, and it's not an off-by-one error, it's something more serious.  I changed the allocated size of the array to (this.size * 10), and it *still* tried to overfill the array.  The hashtable had 26 entries, but it tried to add 261, and counting.

-- 
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