[jboss-svn-commits] JBL Code SVN: r11257 - in labs/jbossrules/trunk/drools-core/src: main/java/org/drools/util and 1 other directories.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Mon Apr 23 15:55:06 EDT 2007


Author: tirelli
Date: 2007-04-23 15:55:06 -0400 (Mon, 23 Apr 2007)
New Revision: 11257

Modified:
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/DefaultBetaConstraints.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/util/LinkedList.java
   labs/jbossrules/trunk/drools-core/src/test/java/org/drools/util/LinkedListTest.java
Log:
JBRULES-812 , JBRULES-722: fixing regression and NPE

Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/DefaultBetaConstraints.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/DefaultBetaConstraints.java	2007-04-23 19:46:59 UTC (rev 11256)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/DefaultBetaConstraints.java	2007-04-23 19:55:06 UTC (rev 11257)
@@ -106,6 +106,14 @@
         return current;
     }
 
+    private ContextEntry findContext(final int pos) {
+        ContextEntry current = this.contexts;
+        for ( int i = 0; i < pos; i++ ) {
+            current = current.getNext();
+        }
+        return current;
+    }
+
     private boolean isIndexable(final BetaNodeFieldConstraint constraint) {
         if ( constraint instanceof VariableConstraint ) {
             final VariableConstraint variableConstraint = (VariableConstraint) constraint;
@@ -143,8 +151,8 @@
     public boolean isAllowedCachedLeft(final Object object) {
         // skip the indexed constraints
         LinkedListEntry entry = (LinkedListEntry) findNode( this.indexed );
-        
-        ContextEntry context = this.contexts;
+
+        ContextEntry context = findContext( this.indexed );
         while ( entry != null ) {
             if ( !((BetaNodeFieldConstraint) entry.getObject()).isAllowedCachedLeft( context,
                                                                                      object ) ) {
@@ -162,8 +170,8 @@
     public boolean isAllowedCachedRight(final ReteTuple tuple) {
         // skip the indexed constraints
         LinkedListEntry entry = (LinkedListEntry) findNode( this.indexed );
-        
-        ContextEntry context = this.contexts;
+
+        ContextEntry context = findContext( this.indexed );
         while ( entry != null ) {
             if ( !((BetaNodeFieldConstraint) entry.getObject()).isAllowedCachedRight( tuple,
                                                                                       context ) ) {

Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/util/LinkedList.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/util/LinkedList.java	2007-04-23 19:46:59 UTC (rev 11256)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/util/LinkedList.java	2007-04-23 19:55:06 UTC (rev 11257)
@@ -151,11 +151,16 @@
         }
 
         if ( existingNode == null ) {
-            // if existing node is null, then insert it as a first node
-            final LinkedListNode node = this.firstNode;
-            node.setPrevious( newNode );
-            newNode.setNext( node );
-            this.firstNode = newNode;
+            if ( this.isEmpty() ) {
+                this.firstNode = newNode;
+                this.lastNode = newNode;
+            } else {
+                // if existing node is null, then insert it as a first node
+                final LinkedListNode node = this.firstNode;
+                node.setPrevious( newNode );
+                newNode.setNext( node );
+                this.firstNode = newNode;
+            }
         } else if ( existingNode == this.lastNode ) {
             existingNode.setNext( newNode );
             newNode.setPrevious( existingNode );

Modified: labs/jbossrules/trunk/drools-core/src/test/java/org/drools/util/LinkedListTest.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/test/java/org/drools/util/LinkedListTest.java	2007-04-23 19:46:59 UTC (rev 11256)
+++ labs/jbossrules/trunk/drools-core/src/test/java/org/drools/util/LinkedListTest.java	2007-04-23 19:55:06 UTC (rev 11257)
@@ -264,4 +264,14 @@
                              3 );
     }
 
+    public void testInsertAfter() {
+        try {
+            this.list.insertAfter( null,
+                                   this.node1 );
+        } catch (NullPointerException e) {
+            e.printStackTrace();
+            fail("Should NOT raise NPE!");
+        }
+    }
+
 }
\ No newline at end of file




More information about the jboss-svn-commits mailing list