Add causes when rethrowing caught exceptions (e.g. in
org.apache.directory.server.integ.state.NonExistentState)
---------------------------------------------------------------------------------------------------------------
Key: DIRSERVER-1299
URL: https://issues.apache.org/jira/browse/DIRSERVER-1299
Project: Directory ApacheDS
Issue Type: Improvement
Reporter: Aleksander Adamowski
Fix For: 1.5.4
In general, in many places in the code exceptions are rethrown only with the
message from the original exception. In tha case of some exceptions, there is
no message and only the original exception with its stack trace could help
track down the problem.
I've been bitten by this when using
org.apache.directory.server.integ.state.NonExistentState:
javax.naming.NamingException
at
org.apache.directory.server.integ.state.NonExistentState.create(NonExistentState.java:86)
at
org.apache.directory.server.integ.state.NonExistentState.test(NonExistentState.java:180)
at
org.apache.directory.server.integ.state.TestServerContext.test(TestServerContext.java:187)
at
org.apache.directory.server.integ.SiRunner.invokeTestMethod(SiRunner.java:103)
at
org.junit.internal.runners.JUnit4ClassRunner.runMethods(JUnit4ClassRunner.java:51)
at
org.junit.internal.runners.JUnit4ClassRunner$1.run(JUnit4ClassRunner.java:44)
at
org.junit.internal.runners.ClassRoadie.runUnprotected(ClassRoadie.java:27)
at
org.junit.internal.runners.ClassRoadie.runProtected(ClassRoadie.java:37)
at
org.junit.internal.runners.JUnit4ClassRunner.run(JUnit4ClassRunner.java:42)
at org.apache.directory.server.integ.SiRunner.run(SiRunner.java:77)
at
org.apache.maven.surefire.junit4.JUnit4TestSet.execute(JUnit4TestSet.java:62)
at
org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.executeTestSet(AbstractDirectoryTestSuite.java:140)
at
org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.execute(AbstractDirectoryTestSuite.java:127)
at org.apache.maven.surefire.Surefire.run(Surefire.java:177)
As can be seen in NonExistentState.java:86 the exception that is thrown is not
initialized with its cause exception (I suspect that it was a
NullPointerException):
catch ( Exception e )
{
throw new NamingException( e.getMessage() );
}
I believe this should be written like this:
catch ( Exception e )
{
NamingException rethrownEx = new NamingException( e.getMessage() );
rethrownEx.setRootCause(e);
throw rethrownEx ;
}
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.