Author: markt
Date: Sun Jan 28 21:33:53 2018
New Revision: 1822482

URL: http://svn.apache.org/viewvc?rev=1822482&view=rev
Log:
Ensure that the toString() method behaves consistently for ByteChunk and 
CharChunk and that null is returned when toString() is called both on newly 
created objects and immediately after a call to recycle().
This should not impact typical Tomcat users.
It may impact users who use these classes directly in their own code.

Modified:
    tomcat/trunk/java/org/apache/tomcat/util/buf/ByteChunk.java
    tomcat/trunk/java/org/apache/tomcat/util/buf/CharChunk.java
    tomcat/trunk/test/org/apache/tomcat/util/buf/TestByteChunk.java
    tomcat/trunk/test/org/apache/tomcat/util/buf/TestCharChunk.java
    tomcat/trunk/test/org/apache/tomcat/util/net/TestCustomSsl.java
    tomcat/trunk/webapps/docs/changelog.xml

Modified: tomcat/trunk/java/org/apache/tomcat/util/buf/ByteChunk.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/buf/ByteChunk.java?rev=1822482&r1=1822481&r2=1822482&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/util/buf/ByteChunk.java (original)
+++ tomcat/trunk/java/org/apache/tomcat/util/buf/ByteChunk.java Sun Jan 28 
21:33:53 2018
@@ -529,7 +529,7 @@ public final class ByteChunk extends Abs
 
     @Override
     public String toString() {
-        if (null == buff) {
+        if (isNull()) {
             return null;
         } else if (end - start == 0) {
             return "";

Modified: tomcat/trunk/java/org/apache/tomcat/util/buf/CharChunk.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/buf/CharChunk.java?rev=1822482&r1=1822481&r2=1822482&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/util/buf/CharChunk.java (original)
+++ tomcat/trunk/java/org/apache/tomcat/util/buf/CharChunk.java Sun Jan 28 
21:33:53 2018
@@ -396,7 +396,7 @@ public final class CharChunk extends Abs
 
     @Override
     public String toString() {
-        if (null == buff) {
+        if (isNull()) {
             return null;
         } else if (end - start == 0) {
             return "";

Modified: tomcat/trunk/test/org/apache/tomcat/util/buf/TestByteChunk.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/tomcat/util/buf/TestByteChunk.java?rev=1822482&r1=1822481&r2=1822482&view=diff
==============================================================================
--- tomcat/trunk/test/org/apache/tomcat/util/buf/TestByteChunk.java (original)
+++ tomcat/trunk/test/org/apache/tomcat/util/buf/TestByteChunk.java Sun Jan 28 
21:33:53 2018
@@ -201,4 +201,18 @@ public class TestByteChunk {
             // NO-OP
         }
     }
+
+
+    @Test
+    public void testToString() {
+        ByteChunk bc = new ByteChunk();
+        Assert.assertNull(bc.toString());
+        byte[] data = new byte[8];
+        bc.setBytes(data, 0, data.length);
+        Assert.assertNotNull(bc.toString());
+        bc.recycle();
+        // toString() should behave consistently for new ByteChunk and
+        // immediately after a call to recycle().
+        Assert.assertNull(bc.toString());
+    }
 }

Modified: tomcat/trunk/test/org/apache/tomcat/util/buf/TestCharChunk.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/tomcat/util/buf/TestCharChunk.java?rev=1822482&r1=1822481&r2=1822482&view=diff
==============================================================================
--- tomcat/trunk/test/org/apache/tomcat/util/buf/TestCharChunk.java (original)
+++ tomcat/trunk/test/org/apache/tomcat/util/buf/TestCharChunk.java Sun Jan 28 
21:33:53 2018
@@ -93,4 +93,19 @@ public class TestCharChunk {
             // NO-OP
         }
     }
+
+
+    @Test
+    public void testToString() {
+        CharChunk cc = new CharChunk();
+        Assert.assertNull(cc.toString());
+        char[] data = new char[8];
+        cc.setChars(data, 0, data.length);
+        Assert.assertNotNull(cc.toString());
+        cc.recycle();
+        // toString() should behave consistently for new ByteChunk and
+        // immediately after a call to recycle().
+        Assert.assertNull(cc.toString());
+    }
+
 }

Modified: tomcat/trunk/test/org/apache/tomcat/util/net/TestCustomSsl.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/tomcat/util/net/TestCustomSsl.java?rev=1822482&r1=1822481&r2=1822482&view=diff
==============================================================================
--- tomcat/trunk/test/org/apache/tomcat/util/net/TestCustomSsl.java (original)
+++ tomcat/trunk/test/org/apache/tomcat/util/net/TestCustomSsl.java Sun Jan 28 
21:33:53 2018
@@ -172,7 +172,7 @@ public class TestCustomSsl extends Tomca
 
         if (trustType.equals(TrustType.NONE)) {
             Assert.assertTrue(rc != 200);
-            Assert.assertEquals("", res.toString());
+            Assert.assertNull(res.toString());
         } else {
             Assert.assertEquals(200, rc);
             Assert.assertEquals("OK-" + TesterSupport.ROLE, res.toString());

Modified: tomcat/trunk/webapps/docs/changelog.xml
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/webapps/docs/changelog.xml?rev=1822482&r1=1822481&r2=1822482&view=diff
==============================================================================
--- tomcat/trunk/webapps/docs/changelog.xml (original)
+++ tomcat/trunk/webapps/docs/changelog.xml Sun Jan 28 21:33:53 2018
@@ -97,6 +97,15 @@
         certificateFile is defined but the file does not exist for both
         JKS and PEM file types.
       </fix>
+      <fix>
+        Ensure that the <code>toString()</code> method behaves consistently for
+        <code>ByteChunk</code> and <code>CharChunk</code> and that
+        <code>null</code> is returned when <code>toString()</code> is called
+        both on newly created objects and immediately after a call to
+        <code>recycle()</code>. This should not impact typical Tomcat users. It
+        may impact users who use these classes directly in their own code.
+        (markt)
+      </fix>
     </changelog>
   </subsection>
   <subsection name="Jasper">



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org

Reply via email to