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
This commit is contained in:
Benedikt Ritter 2013-10-29 18:16:29 +00:00
parent c650b17f50
commit d27df61ab5
2 changed files with 2 additions and 12 deletions

View File

@ -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" />

View File

@ -7449,7 +7449,7 @@ public class StringUtils {
* @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 @@ public class StringUtils {
* @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());
}
}