You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-dev@logging.apache.org by ca...@apache.org on 2008/01/17 17:49:11 UTC

svn commit: r612863 - in /logging/log4j/trunk: src/changes/changes.xml src/main/java/org/apache/log4j/spi/ThrowableInformation.java tests/src/java/org/apache/log4j/spi/ThrowableInformationTest.java

Author: carnold
Date: Thu Jan 17 08:49:03 2008
New Revision: 612863

URL: http://svn.apache.org/viewvc?rev=612863&view=rev
Log:
Bug 44032: ThrowableInformation.getThrowableStringRep() can return null lines

Modified:
    logging/log4j/trunk/src/changes/changes.xml
    logging/log4j/trunk/src/main/java/org/apache/log4j/spi/ThrowableInformation.java
    logging/log4j/trunk/tests/src/java/org/apache/log4j/spi/ThrowableInformationTest.java

Modified: logging/log4j/trunk/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/logging/log4j/trunk/src/changes/changes.xml?rev=612863&r1=612862&r2=612863&view=diff
==============================================================================
--- logging/log4j/trunk/src/changes/changes.xml (original)
+++ logging/log4j/trunk/src/changes/changes.xml Thu Jan 17 08:49:03 2008
@@ -23,6 +23,7 @@
 
     <release version="1.2.16" date="TBD" description="">
        <action issue="43313">log4j 1.2.16 release preparation.</action>
+       <action action="fix" issue="44032">ThrowableInformation.getThrowableStringRep can return null strings.</action>
        <action action="fix" issue="43298">log4j.dtd defines class attribute for category element, but not for logger.</action>
        <action action="fix" issue="43314">SMTPAppender.setSMTPUserName and others missing @since tags.</action>
        <action action="fix" issue="43618">Request for compile-on-Windows help file in src package.</action>

Modified: logging/log4j/trunk/src/main/java/org/apache/log4j/spi/ThrowableInformation.java
URL: http://svn.apache.org/viewvc/logging/log4j/trunk/src/main/java/org/apache/log4j/spi/ThrowableInformation.java?rev=612863&r1=612862&r2=612863&view=diff
==============================================================================
--- logging/log4j/trunk/src/main/java/org/apache/log4j/spi/ThrowableInformation.java (original)
+++ logging/log4j/trunk/src/main/java/org/apache/log4j/spi/ThrowableInformation.java Thu Jan 17 08:49:03 2008
@@ -68,9 +68,7 @@
 
   public
   String[] getThrowableStrRep() {
-    if(rep != null) {
-      return (String[]) rep.clone();
-    } else {
+    if(rep == null) {
       StringWriter sw = new StringWriter();
       PrintWriter pw = new PrintWriter(sw);
       throwable.printStackTrace(pw);
@@ -87,10 +85,11 @@
       } catch(IOException ex) {
           lines.add(ex.toString());
       }
-      rep = new String[lines.size()];
-      lines.toArray(rep);
+      String[] tempRep = new String[lines.size()];
+      lines.toArray(tempRep);
+      rep = tempRep;
     }
-    return rep;
+    return (String[]) rep.clone();
   }
 }
 

Modified: logging/log4j/trunk/tests/src/java/org/apache/log4j/spi/ThrowableInformationTest.java
URL: http://svn.apache.org/viewvc/logging/log4j/trunk/tests/src/java/org/apache/log4j/spi/ThrowableInformationTest.java?rev=612863&r1=612862&r2=612863&view=diff
==============================================================================
--- logging/log4j/trunk/tests/src/java/org/apache/log4j/spi/ThrowableInformationTest.java (original)
+++ logging/log4j/trunk/tests/src/java/org/apache/log4j/spi/ThrowableInformationTest.java Thu Jan 17 08:49:03 2008
@@ -283,4 +283,20 @@
         ThrowableInformation ti = new ThrowableInformation(t);
         assertSame(t, ti.getThrowable());
     }
+
+    /**
+     *  Tests isolation of returned string representation
+     *     from internal state of ThrowableInformation.
+     *      log4j 1.2.15 and earlier did not isolate initial call.
+     *      See bug 44032.
+     */
+    public void testIsolation() {
+        ThrowableInformation ti = new ThrowableInformation(
+                new StringThrowable("Hello, World"));
+        String[] rep = ti.getThrowableStrRep();
+        assertEquals("Hello, World", rep[0]);
+        rep[0] = "Bonjour, Monde";
+        String[] rep2 = ti.getThrowableStrRep();
+        assertEquals("Hello, World", rep2[0]);
+    }
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-dev-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-dev-help@logging.apache.org