castor
  1. castor
  2. CASTOR-1850

XMLException returns null when toString is called

    Details

    • Type: Bug Bug
    • Status: Closed Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 1.0.5
    • Fix Version/s: 1.1.2
    • Component/s: XML
    • Labels:
      None
    • Testcase included:
      yes
    • Number of attachments :
      2

      Description

      If an XMLException (or subclass, like MarshalException) is created to wrap a causing exception with no message (a NullPointerException, in my case), then toString() on the XMLException will result in a null.

      This, in turn, causes problems in log4j, when it is generating a stack trace (see org.apache.log4j.spi.ThrowableInformation.getThrowableStrRep, which generates a stack trace vector will nulls in it). This, in turn, breaks error logging in weird and wonderful ways.

      I have patched the toString() method of XMLException to be more consistent with the toString() method in java.lang.Throwable.

      The testcase is simple:

      public void testWrappedExceptionToString()

      { Exception ex = new NullPointerException(); // note: no message MarshalException me = new MarshalException(ex); String strVal = me.toString(); assertNotNull("MarshalException toString is null", strVal); }
      1. ex-tostring-patch.txt
        1 kB
        Paul Philion
      2. patch.c1850.20070221.txt
        6 kB
        Werner Guttmann

        Activity

        Hide
        Werner Guttmann added a comment -

        Whilst your patch looks reasonable in what it tries to achieve, the following stack trace shows that the generated output is a bit too 'wordy'.

        Show
        Werner Guttmann added a comment - Whilst your patch looks reasonable in what it tries to achieve, the following stack trace shows that the generated output is a bit too 'wordy'.
        Hide
        Werner Guttmann added a comment -

        org.exolab.castor.xml.MarshalException
        at xml.c1850.TestTemplate.testWrappedExceptionThrown(TestTemplate.java:77)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:585)
        at junit.framework.TestCase.runTest(TestCase.java:164)
        at junit.framework.TestCase.runBare(TestCase.java:130)
        at junit.framework.TestResult$1.protect(TestResult.java:106)
        at junit.framework.TestResult.runProtected(TestResult.java:124)
        at junit.framework.TestResult.run(TestResult.java:109)
        at junit.framework.TestCase.run(TestCase.java:120)
        at org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUnit3TestReference.java:128)
        at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
        at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
        at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
        at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
        at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
        Caused by: java.lang.NullPointerException
        at xml.c1850.TestTemplate.testWrappedExceptionThrown(TestTemplate.java:75)
        ... 16 more
        Caused by:
        java.lang.NullPointerException
        at xml.c1850.TestTemplate.testWrappedExceptionThrown(TestTemplate.java:75)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:585)
        at junit.framework.TestCase.runTest(TestCase.java:164)
        at junit.framework.TestCase.runBare(TestCase.java:130)
        at junit.framework.TestResult$1.protect(TestResult.java:106)
        at junit.framework.TestResult.runProtected(TestResult.java:124)
        at junit.framework.TestResult.run(TestResult.java:109)
        at junit.framework.TestCase.run(TestCase.java:120)
        at org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUnit3TestReference.java:128)
        at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
        at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
        at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
        at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
        at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)

        Show
        Werner Guttmann added a comment - org.exolab.castor.xml.MarshalException at xml.c1850.TestTemplate.testWrappedExceptionThrown(TestTemplate.java:77) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:585) at junit.framework.TestCase.runTest(TestCase.java:164) at junit.framework.TestCase.runBare(TestCase.java:130) at junit.framework.TestResult$1.protect(TestResult.java:106) at junit.framework.TestResult.runProtected(TestResult.java:124) at junit.framework.TestResult.run(TestResult.java:109) at junit.framework.TestCase.run(TestCase.java:120) at org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUnit3TestReference.java:128) at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196) Caused by: java.lang.NullPointerException at xml.c1850.TestTemplate.testWrappedExceptionThrown(TestTemplate.java:75) ... 16 more Caused by: java.lang.NullPointerException at xml.c1850.TestTemplate.testWrappedExceptionThrown(TestTemplate.java:75) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:585) at junit.framework.TestCase.runTest(TestCase.java:164) at junit.framework.TestCase.runBare(TestCase.java:130) at junit.framework.TestResult$1.protect(TestResult.java:106) at junit.framework.TestResult.runProtected(TestResult.java:124) at junit.framework.TestResult.run(TestResult.java:109) at junit.framework.TestCase.run(TestCase.java:120) at org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUnit3TestReference.java:128) at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
        Hide
        Werner Guttmann added a comment -

        I just don't think that the NPE should be included in the stack trace twice ?

        Show
        Werner Guttmann added a comment - I just don't think that the NPE should be included in the stack trace twice ?
        Hide
        Werner Guttmann added a comment -

        Just warp the NPE with an IllegalArgumentException ... to see the difference.

        Show
        Werner Guttmann added a comment - Just warp the NPE with an IllegalArgumentException ... to see the difference.
        Hide
        Werner Guttmann added a comment -

        Question to peer committers: any objections to including this with 1.1 ? It is an improvement at least, isn't it ?

        Show
        Werner Guttmann added a comment - Question to peer committers: any objections to including this with 1.1 ? It is an improvement at least, isn't it ?
        Hide
        Ralf Joachim added a comment -

        +1

        Show
        Ralf Joachim added a comment - +1
        Hide
        Werner Guttmann added a comment -

        Final patch for review (incl. JUnit test case relative to src/bugs).

        Show
        Werner Guttmann added a comment - Final patch for review (incl. JUnit test case relative to src/bugs).
        Hide
        Werner Guttmann added a comment -

        Time to commit this to SVN trunk.

        Show
        Werner Guttmann added a comment - Time to commit this to SVN trunk.

          People

          • Assignee:
            Werner Guttmann
            Reporter:
            Paul Philion
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: