[jboss-jira] [JBoss JIRA] Updated: (JBRULES-722) NullPointerException when using inserAfter method with an empty LinkedList
Pierre Paysant-Le Roux (JIRA)
jira-events at lists.jboss.org
Mon Apr 23 13:11:30 EDT 2007
[ http://jira.jboss.com/jira/browse/JBRULES-722?page=all ]
Pierre Paysant-Le Roux updated JBRULES-722:
-------------------------------------------
Description:
JBoss rules throws a NullPointerException when adding my rules file. The problem is with the inserAfter methode in LinkedList. Debug shows that it appends when inserting a node in an empty list.
I wrote a simple test case to illustrate the problem :
Index: drools-core/src/test/java/org/drools/util/LinkedListTest.java
===================================================================
--- drools-core/src/test/java/org/drools/util/LinkedListTest.java (revision 9968)
+++ drools-core/src/test/java/org/drools/util/LinkedListTest.java (working copy)
@@ -264,4 +264,7 @@
3 );
}
-}
\ No newline at end of file
+ public void testInsertAfter(){
+ this.list.insertAfter( null, this.node1 );
+ }
+}
And a patch to avoid the problem :
Index: drools-core/src/main/java/org/drools/util/LinkedList.java
===================================================================
--- drools-core/src/main/java/org/drools/util/LinkedList.java (revision 9968)
+++ drools-core/src/main/java/org/drools/util/LinkedList.java (working copy)
@@ -151,17 +151,21 @@
}
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 );
this.lastNode = newNode;
} else {
- ((LinkedListNode)existingNode.getNext()).setPrevious( newNode );
+ ((LinkedListNode)existingNode.getNext()).setPrevious( newNode );
newNode.setNext( existingNode.getNext() );
existingNode.setNext( newNode );
newNode.setPrevious( existingNode );
Excuse me if I'm wrong.
was:
JBoss rules throws a NullPointerException when adding my rules file. The problem is with the inserAfter methode in LinkedList. Debug shows that it appends when inserting a node in an empty list.
I wrote a simple test case to illustrate the problem :
Index: drools-core/src/test/java/org/drools/util/LinkedListTest.java
===================================================================
--- drools-core/src/test/java/org/drools/util/LinkedListTest.java (revision 9968)
+++ drools-core/src/test/java/org/drools/util/LinkedListTest.java (working copy)
@@ -264,4 +264,7 @@
3 );
}
-}
\ No newline at end of file
+ public void testInsertAfter(){
+ this.list.insertAfter( null, this.node1 );
+ }
+}
And a patch to avoid the problem :
Index: drools-core/src/main/java/org/drools/util/LinkedList.java
===================================================================
--- drools-core/src/main/java/org/drools/util/LinkedList.java (revision 9968)
+++ drools-core/src/main/java/org/drools/util/LinkedList.java (working copy)
@@ -151,17 +151,21 @@
}
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.add(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 );
this.lastNode = newNode;
} else {
- ((LinkedListNode)existingNode.getNext()).setPrevious( newNode );
+ ((LinkedListNode)existingNode.getNext()).setPrevious( newNode );
newNode.setNext( existingNode.getNext() );
existingNode.setNext( newNode );
newNode.setPrevious( existingNode );
Excuse me if I'm wrong.
> NullPointerException when using inserAfter method with an empty LinkedList
> --------------------------------------------------------------------------
>
> Key: JBRULES-722
> URL: http://jira.jboss.com/jira/browse/JBRULES-722
> Project: JBoss Rules
> Issue Type: Bug
> Security Level: Public(Everyone can see)
> Affects Versions: 3.1-m1
> Environment: Windows, jdk 1.5
> Reporter: Pierre Paysant-Le Roux
> Assigned To: Edson Tirelli
>
> JBoss rules throws a NullPointerException when adding my rules file. The problem is with the inserAfter methode in LinkedList. Debug shows that it appends when inserting a node in an empty list.
> I wrote a simple test case to illustrate the problem :
> Index: drools-core/src/test/java/org/drools/util/LinkedListTest.java
> ===================================================================
> --- drools-core/src/test/java/org/drools/util/LinkedListTest.java (revision 9968)
> +++ drools-core/src/test/java/org/drools/util/LinkedListTest.java (working copy)
> @@ -264,4 +264,7 @@
> 3 );
> }
> -}
> \ No newline at end of file
> + public void testInsertAfter(){
> + this.list.insertAfter( null, this.node1 );
> + }
> +}
> And a patch to avoid the problem :
> Index: drools-core/src/main/java/org/drools/util/LinkedList.java
> ===================================================================
> --- drools-core/src/main/java/org/drools/util/LinkedList.java (revision 9968)
> +++ drools-core/src/main/java/org/drools/util/LinkedList.java (working copy)
> @@ -151,17 +151,21 @@
> }
>
> 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 );
> this.lastNode = newNode;
> } else {
> - ((LinkedListNode)existingNode.getNext()).setPrevious( newNode );
> + ((LinkedListNode)existingNode.getNext()).setPrevious( newNode );
> newNode.setNext( existingNode.getNext() );
> existingNode.setNext( newNode );
> newNode.setPrevious( existingNode );
> Excuse me if I'm wrong.
--
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