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 929af1cd0 Use totalMemory() instead of freeMemory()
929af1cd0 is described below

commit 929af1cd0fa8422168983fca10012a7818a18d97
Author: Gary D. Gregory <[email protected]>
AuthorDate: Wed Aug 27 12:54:47 2025 -0400

    Use totalMemory() instead of freeMemory()
    
    Local build OK, some GH failures previously
---
 src/main/java/org/apache/commons/compress/MemoryLimitException.java | 6 +++---
 .../commons/compress/archivers/zip/ZipArchiveInputStream.java       | 2 +-
 .../apache/commons/compress/harmony/pack200/Pack200Exception.java   | 4 ++--
 3 files changed, 6 insertions(+), 6 deletions(-)

diff --git 
a/src/main/java/org/apache/commons/compress/MemoryLimitException.java 
b/src/main/java/org/apache/commons/compress/MemoryLimitException.java
index 9cbc659e6..5a4a1591e 100644
--- a/src/main/java/org/apache/commons/compress/MemoryLimitException.java
+++ b/src/main/java/org/apache/commons/compress/MemoryLimitException.java
@@ -27,8 +27,8 @@
  */
 public class MemoryLimitException extends CompressException {
 
-    private static final String LABEL = "free memory";
-    private static final String MAXIMUM = "free";
+    private static final String LABEL = "total memory";
+    private static final String MAXIMUM = "total";
     private static final String BYTES = "bytes";
     private static final String KIB = "KiB";
     private static final long serialVersionUID = 1L;
@@ -92,7 +92,7 @@ public static long checkKiB(final long request, final long 
max) throws MemoryLim
     }
 
     private static long newObjectMemory() {
-        return Runtime.getRuntime().freeMemory();
+        return Runtime.getRuntime().totalMemory();
     }
 
     /** A long instead of int to account for overflow in corrupt files. */
diff --git 
a/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveInputStream.java
 
b/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveInputStream.java
index 03ad2dc79..ea7544772 100644
--- 
a/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveInputStream.java
+++ 
b/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveInputStream.java
@@ -378,7 +378,7 @@ private int cacheBytesRead(final ByteArrayOutputStream bos, 
int offset, final in
         final int cacheable = offset + lastRead - expectedDDLen - 3;
         if (cacheable > 0) {
             final int request = (bos.size() + cacheable) * 2;
-            MemoryLimitException.checkBytes(request + 2 * 1024 * 1024, 
Runtime.getRuntime().freeMemory()); // 2 MB headroom
+            MemoryLimitException.checkBytes(request + 2 * 1024 * 1024, 
Runtime.getRuntime().totalMemory()); // 2 MB headroom
             bos.write(buf.array(), 0, cacheable);
             System.arraycopy(buf.array(), cacheable, buf.array(), 0, 
expectedDDLen + 3);
             offset = expectedDDLen + 3;
diff --git 
a/src/main/java/org/apache/commons/compress/harmony/pack200/Pack200Exception.java
 
b/src/main/java/org/apache/commons/compress/harmony/pack200/Pack200Exception.java
index 42505798a..76dd3cdfb 100644
--- 
a/src/main/java/org/apache/commons/compress/harmony/pack200/Pack200Exception.java
+++ 
b/src/main/java/org/apache/commons/compress/harmony/pack200/Pack200Exception.java
@@ -60,7 +60,7 @@ public static int addExact(final int x, final long y) throws 
Pack200Exception {
      */
     public static int checkIntArray(final int size) throws Pack200Exception {
         try {
-            MemoryLimitException.checkBytes(Math.multiplyExact(Integer.BYTES, 
size), Runtime.getRuntime().freeMemory());
+            MemoryLimitException.checkBytes(Math.multiplyExact(Integer.BYTES, 
size), Runtime.getRuntime().totalMemory());
             return size;
         } catch (final MemoryLimitException | ArithmeticException e) {
             throw new Pack200Exception(e);
@@ -95,7 +95,7 @@ public static int checkIntArray(final int size, final int 
count) throws Pack200E
      */
     public static int checkObjectArray(final int size, final int objSize) 
throws Pack200Exception {
         try {
-            MemoryLimitException.checkBytes(Math.multiplyExact(size, objSize), 
Runtime.getRuntime().freeMemory());
+            MemoryLimitException.checkBytes(Math.multiplyExact(size, objSize), 
Runtime.getRuntime().totalMemory());
             return size;
         } catch (final MemoryLimitException | ArithmeticException e) {
             throw new Pack200Exception("Can't allocate %,d Objects of size 
%,d.", size, objSize);

Reply via email to