Author: markt
Date: Mon Jan 29 11:26:33 2018
New Revision: 1822499
URL: http://svn.apache.org/viewvc?rev=1822499&view=rev
Log:
Ensure that the toString(), toBytes() and toChars() methods of
MessageBytes behave consistently and do not throw a
NullPointerException 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.
Added:
tomcat/trunk/test/org/apache/tomcat/util/buf/TestMessageBytes.java (with
props)
Modified:
tomcat/trunk/java/org/apache/tomcat/util/buf/MessageBytes.java
tomcat/trunk/webapps/docs/changelog.xml
Modified: tomcat/trunk/java/org/apache/tomcat/util/buf/MessageBytes.java
URL:
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/buf/MessageBytes.java?rev=1822499&r1=1822498&r2=1822499&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/util/buf/MessageBytes.java (original)
+++ tomcat/trunk/java/org/apache/tomcat/util/buf/MessageBytes.java Mon Jan 29
11:26:33 2018
@@ -230,10 +230,14 @@ public final class MessageBytes implemen
byteC.setCharset(charset);
}
+
/**
* Do a char->byte conversion.
*/
public void toBytes() {
+ if (isNull()) {
+ return;
+ }
if (!byteC.isNull()) {
type = T_BYTES;
return;
@@ -245,11 +249,15 @@ public final class MessageBytes implemen
byteC.setBytes(result.array(), result.arrayOffset(), result.limit());
}
+
/**
* Convert to char[] and fill the CharChunk.
* XXX Not optimized - it converts to String first.
*/
public void toChars() {
+ if (isNull()) {
+ return;
+ }
if (!charC.isNull()) {
type = T_CHARS;
return;
Added: tomcat/trunk/test/org/apache/tomcat/util/buf/TestMessageBytes.java
URL:
http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/tomcat/util/buf/TestMessageBytes.java?rev=1822499&view=auto
==============================================================================
--- tomcat/trunk/test/org/apache/tomcat/util/buf/TestMessageBytes.java (added)
+++ tomcat/trunk/test/org/apache/tomcat/util/buf/TestMessageBytes.java Mon Jan
29 11:26:33 2018
@@ -0,0 +1,69 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.tomcat.util.buf;
+
+import org.junit.Test;
+
+public class TestMessageBytes {
+
+ @Test
+ public void testToStringFromNull() {
+ MessageBytes mb = MessageBytes.newInstance();
+ mb.toString();
+ }
+
+
+ @Test
+ public void testToBytesFromNull() {
+ MessageBytes mb = MessageBytes.newInstance();
+ mb.toBytes();
+ }
+
+
+ @Test
+ public void testToCharsFromNull() {
+ MessageBytes mb = MessageBytes.newInstance();
+ mb.toChars();
+ }
+
+
+ @Test
+ public void testToStringAfterRecycle() {
+ MessageBytes mb = MessageBytes.newInstance();
+ mb.setString("foo");
+ mb.recycle();
+ mb.toString();
+ }
+
+
+ @Test
+ public void testToBytesAfterRecycle() {
+ MessageBytes mb = MessageBytes.newInstance();
+ mb.setString("foo");
+ mb.recycle();
+ mb.toBytes();
+ }
+
+
+ @Test
+ public void testToCharsAfterRecycle() {
+ MessageBytes mb = MessageBytes.newInstance();
+ mb.setString("foo");
+ mb.recycle();
+ mb.toChars();
+ }
+}
Propchange: tomcat/trunk/test/org/apache/tomcat/util/buf/TestMessageBytes.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: tomcat/trunk/webapps/docs/changelog.xml
URL:
http://svn.apache.org/viewvc/tomcat/trunk/webapps/docs/changelog.xml?rev=1822499&r1=1822498&r2=1822499&view=diff
==============================================================================
--- tomcat/trunk/webapps/docs/changelog.xml (original)
+++ tomcat/trunk/webapps/docs/changelog.xml Mon Jan 29 11:26:33 2018
@@ -106,6 +106,15 @@
may impact users who use these classes directly in their own code.
(markt)
</fix>
+ <fix>
+ Ensure that the <code>toString()</code>, <code>toBytes()</code> and
+ <code>toChars()</code> methods of <code>MessageBytes</code> behave
+ consistently and do not throw a <code>NullPointerException</code> 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: [email protected]
For additional commands, e-mail: [email protected]