Author: sebb
Date: Sun Mar 26 17:22:08 2017
New Revision: 1788755
URL: http://svn.apache.org/viewvc?rev=1788755&view=rev
Log:
CODEC-229 StringUtils.newStringxxx(null) should return null, not NPE
Modified:
commons/proper/codec/trunk/src/changes/changes.xml
commons/proper/codec/trunk/src/main/java/org/apache/commons/codec/binary/StringUtils.java
commons/proper/codec/trunk/src/test/java/org/apache/commons/codec/binary/StringUtilsTest.java
Modified: commons/proper/codec/trunk/src/changes/changes.xml
URL:
http://svn.apache.org/viewvc/commons/proper/codec/trunk/src/changes/changes.xml?rev=1788755&r1=1788754&r2=1788755&view=diff
==============================================================================
--- commons/proper/codec/trunk/src/changes/changes.xml (original)
+++ commons/proper/codec/trunk/src/changes/changes.xml Sun Mar 26 17:22:08 2017
@@ -42,9 +42,10 @@ The <action> type attribute can be add,u
<author>Apache Commons Developers</author>
</properties>
<body>
- <release version="1.11" date="2016-MM-DD" description="Feature and fix
release.">
+ <release version="1.11" date="2017-MM-DD" description="Feature and fix
release.">
<!-- The first attribute below should be the issue id; makes it easier
to navigate in the IDE outline -->
+ <action issue="CODEC-229" dev="sebb"
type="fix">StringUtils.newStringxxx(null) should return null, not NPE</action>
<action issue="CODEC-220" dev="sebb" type="add">Fluent interface for
DigestUtils</action>
<action issue="CODEC-222" dev="sebb" type="add">Fluent interface for
HmacUtils</action>
<action issue="CODEC-225" dev="jochen" type="fix" due-to="Svetlin
Zarev">Fix minor resource leaks</action>
Modified:
commons/proper/codec/trunk/src/main/java/org/apache/commons/codec/binary/StringUtils.java
URL:
http://svn.apache.org/viewvc/commons/proper/codec/trunk/src/main/java/org/apache/commons/codec/binary/StringUtils.java?rev=1788755&r1=1788754&r2=1788755&view=diff
==============================================================================
---
commons/proper/codec/trunk/src/main/java/org/apache/commons/codec/binary/StringUtils.java
(original)
+++
commons/proper/codec/trunk/src/main/java/org/apache/commons/codec/binary/StringUtils.java
Sun Mar 26 17:22:08 2017
@@ -336,7 +336,7 @@ public class StringUtils {
* @since As of 1.7, throws {@link NullPointerException} instead of
UnsupportedEncodingException
*/
public static String newStringIso8859_1(final byte[] bytes) {
- return new String(bytes, Charsets.ISO_8859_1);
+ return newString(bytes, Charsets.ISO_8859_1);
}
/**
@@ -352,7 +352,7 @@ public class StringUtils {
* @since As of 1.7, throws {@link NullPointerException} instead of
UnsupportedEncodingException
*/
public static String newStringUsAscii(final byte[] bytes) {
- return new String(bytes, Charsets.US_ASCII);
+ return newString(bytes, Charsets.US_ASCII);
}
/**
@@ -368,7 +368,7 @@ public class StringUtils {
* @since As of 1.7, throws {@link NullPointerException} instead of
UnsupportedEncodingException
*/
public static String newStringUtf16(final byte[] bytes) {
- return new String(bytes, Charsets.UTF_16);
+ return newString(bytes, Charsets.UTF_16);
}
/**
@@ -384,7 +384,7 @@ public class StringUtils {
* @since As of 1.7, throws {@link NullPointerException} instead of
UnsupportedEncodingException
*/
public static String newStringUtf16Be(final byte[] bytes) {
- return new String(bytes, Charsets.UTF_16BE);
+ return newString(bytes, Charsets.UTF_16BE);
}
/**
@@ -400,7 +400,7 @@ public class StringUtils {
* @since As of 1.7, throws {@link NullPointerException} instead of
UnsupportedEncodingException
*/
public static String newStringUtf16Le(final byte[] bytes) {
- return new String(bytes, Charsets.UTF_16LE);
+ return newString(bytes, Charsets.UTF_16LE);
}
/**
Modified:
commons/proper/codec/trunk/src/test/java/org/apache/commons/codec/binary/StringUtilsTest.java
URL:
http://svn.apache.org/viewvc/commons/proper/codec/trunk/src/test/java/org/apache/commons/codec/binary/StringUtilsTest.java?rev=1788755&r1=1788754&r2=1788755&view=diff
==============================================================================
---
commons/proper/codec/trunk/src/test/java/org/apache/commons/codec/binary/StringUtilsTest.java
(original)
+++
commons/proper/codec/trunk/src/test/java/org/apache/commons/codec/binary/StringUtilsTest.java
Sun Mar 26 17:22:08 2017
@@ -146,6 +146,16 @@ public class StringUtilsTest {
}
@Test
+ public void testNewStringNullInput_CODEC229() {
+ Assert.assertNull(StringUtils.newStringUtf8(null));
+ Assert.assertNull(StringUtils.newStringIso8859_1(null));
+ Assert.assertNull(StringUtils.newStringUsAscii(null));
+ Assert.assertNull(StringUtils.newStringUtf16(null));
+ Assert.assertNull(StringUtils.newStringUtf16Be(null));
+ Assert.assertNull(StringUtils.newStringUtf16Le(null));
+ }
+
+ @Test
public void testNewStringIso8859_1() throws UnsupportedEncodingException {
final String charsetName = "ISO-8859-1";
testNewString(charsetName);