Make usage of default charset explicit and remove FindBugs exclusion. Kudos to Sebb for spotting this.
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/lang/trunk@1536835 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/findbugs-exclude-filter.xml b/findbugs-exclude-filter.xml
index 4710f29..f239b2a 100644
--- a/findbugs-exclude-filter.xml
+++ b/findbugs-exclude-filter.xml
@@ -48,16 +48,6 @@
<Bug pattern="NP_BOOLEAN_RETURN_NULL" />
</Match>
- <!-- Reason: methods are supposed to fall back to default encoding if no charset is specified -->
- <Match>
- <Class name="org.apache.commons.lang3.StringUtils" />
- <Or>
- <Method name="toString" />
- <Method name="toEncodedString" />
- </Or>
- <Bug pattern="DM_DEFAULT_ENCODING" />
- </Match>
-
<!-- Reason: base class cannot be changed and field is properly checked against null so behavior is OK -->
<Match>
<Class name="org.apache.commons.lang3.text.ExtendedMessageFormat" />
diff --git a/src/main/java/org/apache/commons/lang3/StringUtils.java b/src/main/java/org/apache/commons/lang3/StringUtils.java
index df41329..2978f1b 100644
--- a/src/main/java/org/apache/commons/lang3/StringUtils.java
+++ b/src/main/java/org/apache/commons/lang3/StringUtils.java
@@ -7449,7 +7449,7 @@
* @since 3.1
*/
public static String toString(final byte[] bytes, final String charsetName) throws UnsupportedEncodingException {
- return charsetName == null ? new String(bytes) : new String(bytes, charsetName);
+ return charsetName != null ? new String(bytes, charsetName) : new String(bytes, Charset.defaultCharset());
}
/**
@@ -7467,7 +7467,7 @@
* @since 3.2
*/
public static String toEncodedString(byte[] bytes, Charset charset) throws UnsupportedEncodingException {
- return charset == null ? new String(bytes) : new String(bytes, charset);
+ return new String(bytes, charset != null ? charset : Charset.defaultCharset());
}
}