You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by oh...@apache.org on 2015/04/18 21:03:48 UTC
svn commit: r1674554 -
/commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration2/plist/XMLPropertyListConfiguration.java
Author: oheger
Date: Sat Apr 18 19:03:48 2015
New Revision: 1674554
URL: http://svn.apache.org/r1674554
Log:
Findbugs error "DM_DEFAULT_ENCODING".
This is fixed by setting an explicit encoding used for base64-encoded binary
data.
Modified:
commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration2/plist/XMLPropertyListConfiguration.java
Modified: commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration2/plist/XMLPropertyListConfiguration.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration2/plist/XMLPropertyListConfiguration.java?rev=1674554&r1=1674553&r2=1674554&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration2/plist/XMLPropertyListConfiguration.java (original)
+++ commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration2/plist/XMLPropertyListConfiguration.java Sat Apr 18 19:03:48 2015
@@ -21,6 +21,7 @@ import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
import java.io.PrintWriter;
import java.io.Reader;
+import java.io.UnsupportedEncodingException;
import java.io.Writer;
import java.math.BigDecimal;
import java.math.BigInteger;
@@ -130,6 +131,9 @@ public class XMLPropertyListConfiguratio
/** Size of the indentation for the generated file. */
private static final int INDENT_SIZE = 4;
+ /** Constant for the encoding for binary data. */
+ private static final String DATA_ENCODING = "UTF-8";
+
/** Temporarily stores the current file location. */
private FileLocator locator;
@@ -409,7 +413,16 @@ public class XMLPropertyListConfiguratio
}
else if (value instanceof byte[])
{
- String base64 = new String(Base64.encodeBase64((byte[]) value));
+ String base64 = null;
+ try
+ {
+ base64 = new String(Base64.encodeBase64((byte[]) value), DATA_ENCODING);
+ }
+ catch (UnsupportedEncodingException e)
+ {
+ // Cannot happen as UTF-8 is a standard encoding
+ throw new AssertionError(e);
+ }
out.println(padding + "<data>" + StringEscapeUtils.escapeXml(base64) + "</data>");
}
else if (value != null)
@@ -721,7 +734,15 @@ public class XMLPropertyListConfiguratio
*/
public void addDataValue(String value)
{
- addValue(Base64.decodeBase64(value.getBytes()));
+ try
+ {
+ addValue(Base64.decodeBase64(value.getBytes(DATA_ENCODING)));
+ }
+ catch (UnsupportedEncodingException e)
+ {
+ //Cannot happen as UTF-8 is a default encoding
+ throw new AssertionError(e);
+ }
}
/**