From 0f25dd6c0ee9b7d1b9d727ce770af12571b64222 Mon Sep 17 00:00:00 2001 From: Gary Gregory Date: Sat, 25 Nov 2023 11:55:22 -0500 Subject: [PATCH] Fix SpotBugs [ERROR] High: Found reliance on default encoding in org.apache.commons.logging.LogFactory.initDiagnostics(): new java.io.PrintStream(OutputStream) [org.apache.commons.logging.LogFactory] At LogFactory.java:[line 1205] DM_DEFAULT_ENCODING. --- src/changes/changes.xml | 3 +++ src/main/java/org/apache/commons/logging/LogFactory.java | 4 +++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/changes/changes.xml b/src/changes/changes.xml index 682748d..f0ff46d 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -92,6 +92,9 @@ The type attribute can be add,update,fix,remove. Deprecate LogConfigurationException.cause in favor of getCause(). + + Fix SpotBugs [ERROR] High: Found reliance on default encoding in org.apache.commons.logging.LogFactory.initDiagnostics(): new java.io.PrintStream(OutputStream) [org.apache.commons.logging.LogFactory] At LogFactory.java:[line 1205] DM_DEFAULT_ENCODING. + Bump Java from 6 to 8. diff --git a/src/main/java/org/apache/commons/logging/LogFactory.java b/src/main/java/org/apache/commons/logging/LogFactory.java index 88418d7..2bce859 100644 --- a/src/main/java/org/apache/commons/logging/LogFactory.java +++ b/src/main/java/org/apache/commons/logging/LogFactory.java @@ -24,6 +24,8 @@ import java.io.PrintStream; import java.lang.ref.WeakReference; import java.net.URL; import java.net.URLConnection; +import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; import java.security.AccessController; import java.security.PrivilegedAction; import java.util.Enumeration; @@ -1202,7 +1204,7 @@ public abstract class LogFactory { try { // open the file in append mode final FileOutputStream fos = new FileOutputStream(dest, true); - return new PrintStream(fos); + return new PrintStream(fos, false, StandardCharsets.UTF_8.name()); } catch (final IOException ex) { // We should report this to the user - but how? return null;