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 e579ce72f Revert "Removed the runtime dependency on commons-lang3"
e579ce72f is described below

commit e579ce72f68a3687f7b784dd83a29994b150134c
Author: Gary Gregory <garydgreg...@gmail.com>
AuthorDate: Fri Nov 1 09:15:21 2024 -0400

    Revert "Removed the runtime dependency on commons-lang3"
    
    This reverts commit 23877f8216243df6b2f1dddac2a02b8403d2435d.
---
 pom.xml                                            |  3 ++-
 src/changes/changes.xml                            |  1 -
 .../compress/archivers/tar/TarArchiveEntry.java    |  3 ++-
 .../archivers/tar/TarArchiveOutputStream.java      |  5 ++--
 .../commons/compress/archivers/zip/BinaryTree.java |  5 ++--
 .../compressors/deflate64/HuffmanDecoder.java      |  4 ++--
 .../compressors/lz77support/LZ77Compressor.java    |  6 ++---
 .../compress/harmony/unpack200/Archive.java        |  2 +-
 .../harmony/unpack200/Pack200UnpackerAdapter.java  | 27 ++++++++++------------
 .../archivers/tar/TarArchiveOutputStreamTest.java  |  4 ++--
 .../archivers/zip/ZipArchiveInputStreamTest.java   |  5 ++--
 .../compress/archivers/zip/ZipFileTest.java        |  4 ++--
 .../lz4/BlockLZ4CompressorOutputStreamTest.java    |  5 ++--
 13 files changed, 34 insertions(+), 40 deletions(-)

diff --git a/pom.xml b/pom.xml
index 3ef7c6ebc..658864a0e 100644
--- a/pom.xml
+++ b/pom.xml
@@ -65,6 +65,8 @@ Brotli, Zstandard and ar, cpio, jar, tar, zip, dump, 7z, arj.
       javax.crypto.*;resolution:=optional,
       org.apache.commons.io;resolution:=optional,
       org.apache.commons.io.*;resolution:=optional,
+      org.apache.commons.lang3;resolution:=optional,
+      org.apache.commons.lang3.reflect;resolution:=optional,
       org.apache.commons.codec;resolution:=optional,
       org.apache.commons.codec.digest;resolution:=optional,
       *
@@ -211,7 +213,6 @@ Brotli, Zstandard and ar, cpio, jar, tar, zip, dump, 7z, 
arj.
       <groupId>org.apache.commons</groupId>
       <artifactId>commons-lang3</artifactId>
       <version>3.17.0</version>
-      <scope>test</scope>
     </dependency>    
   </dependencies>
 
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 4bfd3dd0f..cb7711e3d 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -48,7 +48,6 @@ The <action> type attribute can be add,update,fix,remove.
       <!-- FIX -->
       <action type="fix" issue="COMPRESS-686" dev="ggregory" due-to="Richard 
Blank, Gary Gregory">Better exception messages in 
SeekableInMemoryByteChannel.</action>
       <action type="fix" dev="ggregory" due-to="yujincheng08, Gary 
Gregory">ZipArchiveOutputStream.addRawArchiveEntry() should check 
is2PhaseSource #571.</action> 
-      <action type="fix" dev="ebourg" due-to="Emmanuel Bourg">The runtime 
dependency on commons-lang3 has been removed</action>
       <!-- ADD -->
       <!-- UPDATE -->
       <action type="update" dev="ggregory" due-to="Dependabot, Gary 
Gregory">Bump org.apache.commons:commons-parent from 72 to 78 #563, #567, #574, 
#582, #587, #595.</action>
diff --git 
a/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveEntry.java 
b/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveEntry.java
index ad64263d9..e02eeb3a2 100644
--- 
a/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveEntry.java
+++ 
b/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveEntry.java
@@ -53,6 +53,7 @@ import org.apache.commons.compress.utils.IOUtils;
 import org.apache.commons.compress.utils.ParsingUtils;
 import org.apache.commons.compress.utils.TimeUtils;
 import org.apache.commons.io.file.attribute.FileTimes;
+import org.apache.commons.lang3.SystemProperties;
 
 /**
  * An entry in a <a 
href="https://www.gnu.org/software/tar/manual/html_node/Standard.html";>Tar 
archive</a>.
@@ -228,7 +229,7 @@ public class TarArchiveEntry implements ArchiveEntry, 
TarConstants, EntryStreamO
      */
     private static String normalizeFileName(String fileName, final boolean 
preserveAbsolutePath) {
         if (!preserveAbsolutePath) {
-            final String property = System.getProperty("os.name");
+            final String property = SystemProperties.getOsName();
             if (property != null) {
                 final String osName = property.toLowerCase(Locale.ROOT);
 
diff --git 
a/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveOutputStream.java
 
b/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveOutputStream.java
index f84064772..4f3588d9b 100644
--- 
a/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveOutputStream.java
+++ 
b/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveOutputStream.java
@@ -32,7 +32,6 @@ import java.nio.file.LinkOption;
 import java.nio.file.Path;
 import java.nio.file.attribute.FileTime;
 import java.time.Instant;
-import java.util.Arrays;
 import java.util.HashMap;
 import java.util.Map;
 
@@ -44,6 +43,7 @@ import org.apache.commons.compress.utils.TimeUtils;
 import org.apache.commons.io.Charsets;
 import org.apache.commons.io.file.attribute.FileTimes;
 import org.apache.commons.io.output.CountingOutputStream;
+import org.apache.commons.lang3.ArrayFill;
 
 /**
  * The TarOutputStream writes a UNIX tar archive as an OutputStream. Methods 
are provided to put entries, and then write their contents by writing to this
@@ -649,8 +649,7 @@ public class TarArchiveOutputStream extends 
ArchiveOutputStream<TarArchiveEntry>
      * Writes an EOF (end of archive) record to the tar archive. An EOF record 
consists of a record of all zeros.
      */
     private void writeEOFRecord() throws IOException {
-        Arrays.fill(recordBuf, (byte) 0);
-        writeRecord(recordBuf);
+        writeRecord(ArrayFill.fill(recordBuf, (byte) 0));
     }
 
     /**
diff --git 
a/src/main/java/org/apache/commons/compress/archivers/zip/BinaryTree.java 
b/src/main/java/org/apache/commons/compress/archivers/zip/BinaryTree.java
index 586a0aea7..c02fce78c 100644
--- a/src/main/java/org/apache/commons/compress/archivers/zip/BinaryTree.java
+++ b/src/main/java/org/apache/commons/compress/archivers/zip/BinaryTree.java
@@ -22,9 +22,9 @@ package org.apache.commons.compress.archivers.zip;
 import java.io.EOFException;
 import java.io.IOException;
 import java.io.InputStream;
-import java.util.Arrays;
 
 import org.apache.commons.compress.utils.IOUtils;
+import org.apache.commons.lang3.ArrayFill;
 
 /**
  * Binary tree of positive values.
@@ -140,8 +140,7 @@ final class BinaryTree {
         if (depth < 0 || depth > 30) {
             throw new IllegalArgumentException("depth must be bigger than 0 
and not bigger than 30" + " but is " + depth);
         }
-        tree = new int[(int) ((1L << depth + 1) - 1)];
-        Arrays.fill(tree, UNDEFINED);
+        tree = ArrayFill.fill(new int[(int) ((1L << depth + 1) - 1)], 
UNDEFINED);
     }
 
     /**
diff --git 
a/src/main/java/org/apache/commons/compress/compressors/deflate64/HuffmanDecoder.java
 
b/src/main/java/org/apache/commons/compress/compressors/deflate64/HuffmanDecoder.java
index 33881a69e..4d77de9ec 100644
--- 
a/src/main/java/org/apache/commons/compress/compressors/deflate64/HuffmanDecoder.java
+++ 
b/src/main/java/org/apache/commons/compress/compressors/deflate64/HuffmanDecoder.java
@@ -31,6 +31,7 @@ import java.util.Arrays;
 import org.apache.commons.compress.utils.BitInputStream;
 import org.apache.commons.compress.utils.ByteUtils;
 import org.apache.commons.compress.utils.ExactMath;
+import org.apache.commons.lang3.ArrayFill;
 
 /**
  * TODO This class can't be final because it is mocked by Mockito.
@@ -361,8 +362,7 @@ class HuffmanDecoder implements Closeable {
         Arrays.fill(FIXED_LITERALS, 256, 280, 7);
         Arrays.fill(FIXED_LITERALS, 280, 288, 8);
 
-        FIXED_DISTANCE = new int[32];
-        Arrays.fill(FIXED_DISTANCE, 5);
+        FIXED_DISTANCE = ArrayFill.fill(new int[32], 5);
     }
 
     private static BinaryTreeNode buildTree(final int[] litTable) {
diff --git 
a/src/main/java/org/apache/commons/compress/compressors/lz77support/LZ77Compressor.java
 
b/src/main/java/org/apache/commons/compress/compressors/lz77support/LZ77Compressor.java
index 224065659..1feb1e5bc 100644
--- 
a/src/main/java/org/apache/commons/compress/compressors/lz77support/LZ77Compressor.java
+++ 
b/src/main/java/org/apache/commons/compress/compressors/lz77support/LZ77Compressor.java
@@ -19,9 +19,10 @@
 package org.apache.commons.compress.compressors.lz77support;
 
 import java.io.IOException;
-import java.util.Arrays;
 import java.util.Objects;
 
+import org.apache.commons.lang3.ArrayFill;
+
 /**
  * Helper class for compression algorithms that use the ideas of LZ77.
  *
@@ -285,8 +286,7 @@ public class LZ77Compressor {
         final int wSize = params.getWindowSize();
         window = new byte[wSize * 2];
         wMask = wSize - 1;
-        head = new int[HASH_SIZE];
-        Arrays.fill(head, NO_MATCH);
+        head = ArrayFill.fill(new int[HASH_SIZE], NO_MATCH);
         prev = new int[wSize];
     }
 
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 56bcca212..9935180b4 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
@@ -77,7 +77,7 @@ public class Archive {
         this.inputStream = 
Pack200UnpackerAdapter.newBoundedInputStream(inputStream);
         this.outputStream = outputStream;
         if (inputStream instanceof FileInputStream) {
-            inputPath = Pack200UnpackerAdapter.readPath((FileInputStream) 
inputStream);
+            inputPath = 
Paths.get(Pack200UnpackerAdapter.readPathString((FileInputStream) inputStream));
         } else {
             inputPath = null;
         }
diff --git 
a/src/main/java/org/apache/commons/compress/harmony/unpack200/Pack200UnpackerAdapter.java
 
b/src/main/java/org/apache/commons/compress/harmony/unpack200/Pack200UnpackerAdapter.java
index 0e05a2326..430e8a867 100644
--- 
a/src/main/java/org/apache/commons/compress/harmony/unpack200/Pack200UnpackerAdapter.java
+++ 
b/src/main/java/org/apache/commons/compress/harmony/unpack200/Pack200UnpackerAdapter.java
@@ -22,7 +22,6 @@ import java.io.FileInputStream;
 import java.io.FilterInputStream;
 import java.io.IOException;
 import java.io.InputStream;
-import java.lang.reflect.Field;
 import java.net.URISyntaxException;
 import java.net.URL;
 import java.nio.file.Files;
@@ -35,6 +34,7 @@ import 
org.apache.commons.compress.harmony.pack200.Pack200Exception;
 import org.apache.commons.compress.java.util.jar.Pack200.Unpacker;
 import org.apache.commons.io.input.BoundedInputStream;
 import org.apache.commons.io.input.CloseShieldInputStream;
+import org.apache.commons.lang3.reflect.FieldUtils;
 
 /**
  * This class provides the binding between the standard Pack200 interface and 
the internal interface for (un)packing.
@@ -56,7 +56,7 @@ public class Pack200UnpackerAdapter extends Pack200Adapter 
implements Unpacker {
     }
 
     private static BoundedInputStream newBoundedInputStream(final 
FileInputStream fileInputStream) throws IOException {
-        return newBoundedInputStream(readPath(fileInputStream));
+        return newBoundedInputStream(readPathString(fileInputStream));
     }
 
     @SuppressWarnings("resource") // Caller closes.
@@ -130,16 +130,19 @@ public class Pack200UnpackerAdapter extends 
Pack200Adapter implements Unpacker {
         return newBoundedInputStream(Paths.get(url.toURI()));
     }
 
-    static Path readPath(final FileInputStream fis) {
+    @SuppressWarnings("unchecked")
+    private static <T> T readField(final Object object, final String 
fieldName) {
         try {
-            Field field = FileInputStream.class.getDeclaredField("path");
-            field.setAccessible(true);
-            return Paths.get((String) field.get(fis));
-        } catch (NoSuchFieldException | IllegalAccessException e) {
-            throw new RuntimeException("Failed to read the path from the 
FileInputStream", e);
+            return (T) FieldUtils.readField(object, fieldName, true);
+        } catch (final IllegalAccessException e) {
+            return null;
         }
     }
 
+    static String readPathString(final FileInputStream fis) {
+        return readField(fis, "path");
+    }
+
     /**
      * Unwraps the given FilterInputStream to return its wrapped InputStream.
      *
@@ -147,13 +150,7 @@ public class Pack200UnpackerAdapter extends Pack200Adapter 
implements Unpacker {
      * @return The wrapped InputStream
      */
     static InputStream unwrap(final FilterInputStream filterInputStream) {
-        try {
-            Field field = FilterInputStream.class.getDeclaredField("in");
-            field.setAccessible(true);
-            return (InputStream) field.get(filterInputStream);
-        } catch (NoSuchFieldException | IllegalAccessException e) {
-            throw new RuntimeException("Failed to unwrap the 
FilterInputStream", e);
-        }
+        return readField(filterInputStream, "in");
     }
 
     /**
diff --git 
a/src/test/java/org/apache/commons/compress/archivers/tar/TarArchiveOutputStreamTest.java
 
b/src/test/java/org/apache/commons/compress/archivers/tar/TarArchiveOutputStreamTest.java
index cbfee27e2..e1fd352a1 100644
--- 
a/src/test/java/org/apache/commons/compress/archivers/tar/TarArchiveOutputStreamTest.java
+++ 
b/src/test/java/org/apache/commons/compress/archivers/tar/TarArchiveOutputStreamTest.java
@@ -48,6 +48,7 @@ import 
org.apache.commons.compress.archivers.ArchiveOutputStream;
 import org.apache.commons.compress.archivers.ArchiveStreamFactory;
 import org.apache.commons.io.IOUtils;
 import org.apache.commons.io.output.NullOutputStream;
+import org.apache.commons.lang3.ArrayFill;
 import org.junit.jupiter.api.Disabled;
 import org.junit.jupiter.api.Test;
 
@@ -147,8 +148,7 @@ public class TarArchiveOutputStreamTest extends 
AbstractTest {
         assertThrows(IllegalArgumentException.class, () -> testPadding(0, 
fileName, contents));
 
         // test with "content" that is an exact multiple of record length
-        final byte[] contents2 = new byte[2048];
-        java.util.Arrays.fill(contents2, (byte) 42);
+        final byte[] contents2 = ArrayFill.fill(new byte[2048], (byte) 42);
         testPadding(TarConstants.DEFAULT_BLKSIZE, fileName, contents2);
     }
 
diff --git 
a/src/test/java/org/apache/commons/compress/archivers/zip/ZipArchiveInputStreamTest.java
 
b/src/test/java/org/apache/commons/compress/archivers/zip/ZipArchiveInputStreamTest.java
index 50551d300..0a2fd6506 100644
--- 
a/src/test/java/org/apache/commons/compress/archivers/zip/ZipArchiveInputStreamTest.java
+++ 
b/src/test/java/org/apache/commons/compress/archivers/zip/ZipArchiveInputStreamTest.java
@@ -40,7 +40,6 @@ import java.nio.file.Files;
 import java.nio.file.Path;
 import java.nio.file.Paths;
 import java.time.Instant;
-import java.util.Arrays;
 import java.util.zip.ZipEntry;
 import java.util.zip.ZipException;
 
@@ -50,6 +49,7 @@ import 
org.apache.commons.compress.archivers.ArchiveInputStream;
 import org.apache.commons.compress.archivers.ArchiveStreamFactory;
 import org.apache.commons.compress.utils.ByteUtils;
 import org.apache.commons.io.IOUtils;
+import org.apache.commons.lang3.ArrayFill;
 import org.junit.jupiter.api.Test;
 import org.junit.jupiter.params.ParameterizedTest;
 import org.junit.jupiter.params.provider.ValueSource;
@@ -666,8 +666,7 @@ public class ZipArchiveInputStreamTest extends AbstractTest 
{
         try (ZipArchiveInputStream in = new 
ZipArchiveInputStream(newInputStream("bzip2-zip.zip"))) {
             final ZipArchiveEntry ze = in.getNextZipEntry();
             assertEquals(42, ze.getSize());
-            final byte[] expected = new byte[42];
-            Arrays.fill(expected, (byte) 'a');
+            final byte[] expected = ArrayFill.fill(new byte[42], (byte) 'a');
             assertArrayEquals(expected, IOUtils.toByteArray(in));
         }
     }
diff --git 
a/src/test/java/org/apache/commons/compress/archivers/zip/ZipFileTest.java 
b/src/test/java/org/apache/commons/compress/archivers/zip/ZipFileTest.java
index 967652187..c2501d15d 100644
--- a/src/test/java/org/apache/commons/compress/archivers/zip/ZipFileTest.java
+++ b/src/test/java/org/apache/commons/compress/archivers/zip/ZipFileTest.java
@@ -58,6 +58,7 @@ import org.apache.commons.compress.utils.ByteUtils;
 import org.apache.commons.compress.utils.SeekableInMemoryByteChannel;
 import org.apache.commons.io.IOUtils;
 import org.apache.commons.io.function.IORunnable;
+import org.apache.commons.lang3.ArrayFill;
 import org.apache.commons.lang3.SystemUtils;
 import org.junit.Assume;
 import org.junit.jupiter.api.AfterEach;
@@ -943,8 +944,7 @@ public class ZipFileTest extends AbstractTest {
         zf = new ZipFile(archive);
         final ZipArchiveEntry ze = zf.getEntry("lots-of-as");
         assertEquals(42, ze.getSize());
-        final byte[] expected = new byte[42];
-        Arrays.fill(expected, (byte) 'a');
+        final byte[] expected = ArrayFill.fill(new byte[42], (byte) 'a');
         try (InputStream inputStream = zf.getInputStream(ze)) {
             assertArrayEquals(expected, IOUtils.toByteArray(inputStream));
         }
diff --git 
a/src/test/java/org/apache/commons/compress/compressors/lz4/BlockLZ4CompressorOutputStreamTest.java
 
b/src/test/java/org/apache/commons/compress/compressors/lz4/BlockLZ4CompressorOutputStreamTest.java
index 6d545472c..4f4dfb571 100644
--- 
a/src/test/java/org/apache/commons/compress/compressors/lz4/BlockLZ4CompressorOutputStreamTest.java
+++ 
b/src/test/java/org/apache/commons/compress/compressors/lz4/BlockLZ4CompressorOutputStreamTest.java
@@ -28,6 +28,7 @@ import java.io.IOException;
 import java.util.Arrays;
 
 import org.apache.commons.compress.compressors.lz77support.LZ77Compressor;
+import org.apache.commons.lang3.ArrayFill;
 import org.junit.jupiter.api.Disabled;
 import org.junit.jupiter.api.Test;
 
@@ -74,9 +75,7 @@ public class BlockLZ4CompressorOutputStreamTest {
     }
 
     private byte[] prepareExpected(final int length) {
-        final byte[] b = new byte[length];
-        Arrays.fill(b, (byte) -1);
-        return b;
+        return ArrayFill.fill(new byte[length], (byte) -1);
     }
 
     @Test

Reply via email to