This is an automated email from the ASF dual-hosted git repository.
ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-compress.git
The following commit(s) were added to refs/heads/master by this push:
new 05afb04f6
org.apache.commons.compress.harmony.unpack200.Archive.unpack() should not log
to system out (the console)
05afb04f6 is described below
commit 05afb04f6cc2b789c8cc2c16015d6ecefd92a970
Author: Gary Gregory <[email protected]>
AuthorDate: Thu Apr 17 12:03:53 2025 -0400
org.apache.commons.compress.harmony.unpack200.Archive.unpack() should
not log to system out (the console)
---
src/changes/changes.xml | 1 +
.../apache/commons/compress/harmony/unpack200/Archive.java | 2 +-
.../apache/commons/compress/harmony/unpack200/Segment.java | 9 ++++-----
.../commons/compress/harmony/unpack200/ArchiveTest.java | 13 +++----------
4 files changed, 9 insertions(+), 16 deletions(-)
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 6532f4e8d..86c2aaea6 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -86,6 +86,7 @@ The <action> type attribute can be add,update,fix,remove.
<action type="fix" dev="ggregory" due-to="Gary Gregory">Deprecate
org.apache.commons.compress.harmony.pack200.CanonicalCodecFamilies.CanonicalCodecFamilies().</action>
<action type="fix" dev="ggregory" due-to="Gary Gregory">Deprecate
FileNameUtils#getBaseName(Path).</action>
<action type="fix" dev="ggregory" due-to="Gary Gregory">Deprecate
FileNameUtils#getExtension(Path).</action>
+ <action type="fix" dev="ggregory" due-to="Alexis Jehan, Gary
Gregory">org.apache.commons.compress.harmony.unpack200.Archive.unpack() should
not log to system out (the console).</action>
<!-- ADD -->
<action type="add" dev="ggregory" due-to="Gary Gregory">Add
GzipParameters.getModificationInstant().</action>
<action type="add" dev="ggregory" due-to="Gary Gregory">Add
GzipParameters.setModificationInstant(Instant).</action>
diff --git
a/src/main/java/org/apache/commons/compress/harmony/unpack200/Archive.java
b/src/main/java/org/apache/commons/compress/harmony/unpack200/Archive.java
index f3bbd364f..322912021 100644
--- a/src/main/java/org/apache/commons/compress/harmony/unpack200/Archive.java
+++ b/src/main/java/org/apache/commons/compress/harmony/unpack200/Archive.java
@@ -229,7 +229,7 @@ public void unpack() throws Pack200Exception, IOException {
i++;
final Segment segment = new Segment();
segment.setLogLevel(logLevel);
- segment.setLogStream(logFile != null ? logFile :
System.out);
+ segment.setLogStream(logFile);
segment.setPreRead(false);
if (i == 1) {
segment.log(Segment.LOG_LEVEL_VERBOSE, "Unpacking from
" + inputPath + " to " + outputFileName);
diff --git
a/src/main/java/org/apache/commons/compress/harmony/unpack200/Segment.java
b/src/main/java/org/apache/commons/compress/harmony/unpack200/Segment.java
index 585a89afc..727eac14c 100644
--- a/src/main/java/org/apache/commons/compress/harmony/unpack200/Segment.java
+++ b/src/main/java/org/apache/commons/compress/harmony/unpack200/Segment.java
@@ -404,7 +404,7 @@ public SegmentHeader getSegmentHeader() {
* @param message the message.
*/
public void log(final int messageLevel, final String message) {
- if (logLevel >= messageLevel) {
+ if (logLevel >= messageLevel && logPrintWriter != null) {
logPrintWriter.println(message);
}
}
@@ -500,7 +500,6 @@ private void readSegment(final InputStream in) throws
IOException, Pack200Except
bcBands.read(in);
fileBands = new FileBands(this);
fileBands.read(in);
-
fileBands.processFileBits();
}
@@ -514,12 +513,12 @@ public void setLogLevel(final int logLevel) {
}
/**
- * Sets the log output.
+ * Sets the log output stream.
*
- * @param logStream log output.
+ * @param logStream log output stream.
*/
public void setLogStream(final OutputStream logStream) {
- this.logPrintWriter = new PrintWriter(new
OutputStreamWriter(logStream, Charset.defaultCharset()), false);
+ this.logPrintWriter = logStream != null ? new PrintWriter(new
OutputStreamWriter(logStream, Charset.defaultCharset()), false) : null;
}
/**
diff --git
a/src/test/java/org/apache/commons/compress/harmony/unpack200/ArchiveTest.java
b/src/test/java/org/apache/commons/compress/harmony/unpack200/ArchiveTest.java
index 06287d800..0ceb6394a 100644
---
a/src/test/java/org/apache/commons/compress/harmony/unpack200/ArchiveTest.java
+++
b/src/test/java/org/apache/commons/compress/harmony/unpack200/ArchiveTest.java
@@ -30,7 +30,6 @@
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
-import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
@@ -108,9 +107,7 @@ public void testLoggingOptions() throws Exception {
archive.unpack();
}
// log file should be empty
- try (FileReader reader = new FileReader(logFile)) {
- assertFalse(reader.ready());
- }
+ assertEquals(0, logFile.length());
// test verbose
file = createTempFile("logtest", ".jar");
try (InputStream in =
Archive.class.getResourceAsStream("/pack200/sql.pack.gz");
@@ -122,9 +119,7 @@ public void testLoggingOptions() throws Exception {
archive.unpack();
}
// log file should not be empty
- try (FileReader reader = new FileReader(logFile)) {
- assertTrue(reader.ready());
- }
+ assertTrue(logFile.length() > 0);
// test append option
final long length = logFile.length();
file = createTempFile("logtest", ".jar");
@@ -156,9 +151,7 @@ public void testLoggingOptions() throws Exception {
archive.unpack();
}
// log file should be empty
- try (FileReader reader = new FileReader(logFile)) {
- assertFalse(reader.ready());
- }
+ assertEquals(0, logFile.length());
}
@ParameterizedTest