-
Bug
-
Resolution: Fixed
-
P3
-
6
-
b98
-
x86
-
windows_xp
FULL PRODUCT VERSION :
java version "1.6.0-rc"
Java(TM) SE Runtime Environment (build 1.6.0-rc-b92)
Java HotSpot(TM) Client VM (build 1.6.0-rc-b92, mixed mode, sharing)
ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows XP [version 5.1.2600]
A DESCRIPTION OF THE PROBLEM :
SQLException has a mechanism to link throwable to a root SQLException
using setNextException().
In mustang, SQLException implements Iterable in order to provide a way
to iterate over next exceptions using a foreach loop.
The current implementation has two major bugs :
- first a vector that contains next exceptions is lazily ininitalized
but there is no test againt null in the method iterator().
- second, in my opinion using a Vector here is a non sense because :
- next exception are store twice
- the linked list of exception can be changed without a change
in the vector.
- it's not thread-safe, i can iterate over the vector without synchronization.
The solution here is to use the same algorithms as ConcurrentLinkedList,
i.e remove the vector, mark next as volatile, use a CAS to update next,
create a real iterator that iterate by using next.
REGRESSION. Last worked in version mustang
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
run the test
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
No NPE for the first test,
the second one must print e2 and e3
ACTUAL -
NPE for the first test and the second one only prints e2
ERROR MESSAGES/STACK TRACES THAT OCCUR :
The first test throws a NPE:
Exception in thread "main" java.lang.NullPointerException
at java.sql.SQLException.iterator(SQLException.java:317)
at SQLExceptionTest.main(SQLExceptionTest.java:11)
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import java.sql.SQLException;
public class SQLExceptionTest {
public static void main(String[] args) {
// first test
//new SQLException().iterator();
// second test
SQLException e1=new SQLException("e1");
SQLException e2=new SQLException("e2");
SQLException e3=new SQLException("e3");
e2.setNextException(e3);
e1.setNextException(e2);
for(Throwable t:e1)
System.out.println(t);
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
No workaround
java version "1.6.0-rc"
Java(TM) SE Runtime Environment (build 1.6.0-rc-b92)
Java HotSpot(TM) Client VM (build 1.6.0-rc-b92, mixed mode, sharing)
ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows XP [version 5.1.2600]
A DESCRIPTION OF THE PROBLEM :
SQLException has a mechanism to link throwable to a root SQLException
using setNextException().
In mustang, SQLException implements Iterable in order to provide a way
to iterate over next exceptions using a foreach loop.
The current implementation has two major bugs :
- first a vector that contains next exceptions is lazily ininitalized
but there is no test againt null in the method iterator().
- second, in my opinion using a Vector here is a non sense because :
- next exception are store twice
- the linked list of exception can be changed without a change
in the vector.
- it's not thread-safe, i can iterate over the vector without synchronization.
The solution here is to use the same algorithms as ConcurrentLinkedList,
i.e remove the vector, mark next as volatile, use a CAS to update next,
create a real iterator that iterate by using next.
REGRESSION. Last worked in version mustang
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
run the test
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
No NPE for the first test,
the second one must print e2 and e3
ACTUAL -
NPE for the first test and the second one only prints e2
ERROR MESSAGES/STACK TRACES THAT OCCUR :
The first test throws a NPE:
Exception in thread "main" java.lang.NullPointerException
at java.sql.SQLException.iterator(SQLException.java:317)
at SQLExceptionTest.main(SQLExceptionTest.java:11)
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import java.sql.SQLException;
public class SQLExceptionTest {
public static void main(String[] args) {
// first test
//new SQLException().iterator();
// second test
SQLException e1=new SQLException("e1");
SQLException e2=new SQLException("e2");
SQLException e3=new SQLException("e3");
e2.setNextException(e3);
e1.setNextException(e2);
for(Throwable t:e1)
System.out.println(t);
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
No workaround