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 22c22a18e Add MemoryLimitException.MemoryLimitException(long, int, Throwable) and deprecate MemoryLimitException.MemoryLimitException(long, int, Exception) 22c22a18e is described below commit 22c22a18ee4baef803a5e96515089c08a9e6072d Author: Gary D. Gregory <garydgreg...@gmail.com> AuthorDate: Sat Jan 4 10:21:26 2025 -0500 Add MemoryLimitException.MemoryLimitException(long, int, Throwable) and deprecate MemoryLimitException.MemoryLimitException(long, int, Exception) --- src/changes/changes.xml | 1 + .../apache/commons/compress/MemoryLimitException.java | 16 ++++++++++++++++ .../compressors/lzma/LZMACompressorInputStream.java | 2 +- .../compress/compressors/xz/XZCompressorInputStream.java | 6 +++--- .../commons/compress/MemoryLimitExceptionTest.java | 10 ++++++++++ 5 files changed, 31 insertions(+), 4 deletions(-) diff --git a/src/changes/changes.xml b/src/changes/changes.xml index 8bb3e72c1..9e8b25d03 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -82,6 +82,7 @@ The <action> type attribute can be add,update,fix,remove. <action type="add" dev="ggregory" due-to="Gary Gregory">Add GzipCompressorInputStream.Builder.setOnMemberEnd(IOConsumer) to monitor member parsing.</action> <action type="add" dev="ggregory" due-to="Gary Gregory">Add PMD check to default Maven goal.</action> <action type="add" dev="ggregory" due-to="Gary Gregory">Add SevenZFile.Builder.setMaxMemoryLimitKiB(int).</action> + <action type="add" dev="ggregory" due-to="Gary Gregory">Add MemoryLimitException.MemoryLimitException(long, int, Throwable) and deprecate MemoryLimitException.MemoryLimitException(long, int, Exception).</action> <!-- 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> <action type="update" dev="ggregory" due-to="Dependabot, Gary Gregory">Bump com.github.luben:zstd-jni from 1.5.6-4 to 1.5.6-9 #565, #578, #601, #616, #630.</action> diff --git a/src/main/java/org/apache/commons/compress/MemoryLimitException.java b/src/main/java/org/apache/commons/compress/MemoryLimitException.java index 7e3026c6a..6527876f1 100644 --- a/src/main/java/org/apache/commons/compress/MemoryLimitException.java +++ b/src/main/java/org/apache/commons/compress/MemoryLimitException.java @@ -58,13 +58,29 @@ public class MemoryLimitException extends IOException { * @param memoryLimitKiB The memory limit in kibibytes (KiB). * @param cause The cause (which is saved for later retrieval by the {@link #getCause()} method). (A null value is permitted, and indicates that * the cause is nonexistent or unknown.) + * @deprecated Use {@link #MemoryLimitException(long, int, Throwable)}. */ + @Deprecated public MemoryLimitException(final long memoryNeededKiB, final int memoryLimitKiB, final Exception cause) { super(buildMessage(memoryNeededKiB, memoryLimitKiB), cause); this.memoryNeededKiB = memoryNeededKiB; this.memoryLimitKiB = memoryLimitKiB; } + /** + * Constructs a new instance. + * + * @param memoryNeededKiB The memory needed in kibibytes (KiB). + * @param memoryLimitKiB The memory limit in kibibytes (KiB). + * @param cause The cause (which is saved for later retrieval by the {@link #getCause()} method). (A null value is permitted, and indicates that + * the cause is nonexistent or unknown.) + */ + public MemoryLimitException(final long memoryNeededKiB, final int memoryLimitKiB, final Throwable cause) { + super(buildMessage(memoryNeededKiB, memoryLimitKiB), cause); + this.memoryNeededKiB = memoryNeededKiB; + this.memoryLimitKiB = memoryLimitKiB; + } + /** * Gets the memory limit in kibibytes (KiB). * diff --git a/src/main/java/org/apache/commons/compress/compressors/lzma/LZMACompressorInputStream.java b/src/main/java/org/apache/commons/compress/compressors/lzma/LZMACompressorInputStream.java index 834330523..48e5b3cd2 100644 --- a/src/main/java/org/apache/commons/compress/compressors/lzma/LZMACompressorInputStream.java +++ b/src/main/java/org/apache/commons/compress/compressors/lzma/LZMACompressorInputStream.java @@ -76,7 +76,7 @@ public class LZMACompressorInputStream extends CompressorInputStream implements in = new LZMAInputStream(countingStream = BoundedInputStream.builder().setInputStream(inputStream).get(), memoryLimitKiB); } catch (final org.tukaani.xz.MemoryLimitException e) { // convert to commons-compress exception - throw new MemoryLimitException(e.getMemoryNeeded(), e.getMemoryLimit(), e); + throw new MemoryLimitException(e.getMemoryNeeded(), e.getMemoryLimit(), (Throwable) e); } } diff --git a/src/main/java/org/apache/commons/compress/compressors/xz/XZCompressorInputStream.java b/src/main/java/org/apache/commons/compress/compressors/xz/XZCompressorInputStream.java index 0b2a40efb..9b7a88ef9 100644 --- a/src/main/java/org/apache/commons/compress/compressors/xz/XZCompressorInputStream.java +++ b/src/main/java/org/apache/commons/compress/compressors/xz/XZCompressorInputStream.java @@ -134,7 +134,7 @@ public class XZCompressorInputStream extends CompressorInputStream implements In count(ret == -1 ? -1 : 1); return ret; } catch (final org.tukaani.xz.MemoryLimitException e) { - throw new MemoryLimitException(e.getMemoryNeeded(), e.getMemoryLimit(), e); + throw new MemoryLimitException(e.getMemoryNeeded(), e.getMemoryLimit(), (Throwable) e); } } @@ -149,7 +149,7 @@ public class XZCompressorInputStream extends CompressorInputStream implements In return ret; } catch (final org.tukaani.xz.MemoryLimitException e) { // convert to commons-compress MemoryLimtException - throw new MemoryLimitException(e.getMemoryNeeded(), e.getMemoryLimit(), e); + throw new MemoryLimitException(e.getMemoryNeeded(), e.getMemoryLimit(), (Throwable) e); } } @@ -159,7 +159,7 @@ public class XZCompressorInputStream extends CompressorInputStream implements In return org.apache.commons.io.IOUtils.skip(in, n); } catch (final org.tukaani.xz.MemoryLimitException e) { // convert to commons-compress MemoryLimtException - throw new MemoryLimitException(e.getMemoryNeeded(), e.getMemoryLimit(), e); + throw new MemoryLimitException(e.getMemoryNeeded(), e.getMemoryLimit(), (Throwable) e); } } } diff --git a/src/test/java/org/apache/commons/compress/MemoryLimitExceptionTest.java b/src/test/java/org/apache/commons/compress/MemoryLimitExceptionTest.java index e9884db0a..ca942ade2 100644 --- a/src/test/java/org/apache/commons/compress/MemoryLimitExceptionTest.java +++ b/src/test/java/org/apache/commons/compress/MemoryLimitExceptionTest.java @@ -34,6 +34,16 @@ public class MemoryLimitExceptionTest { @Test public void testAccessorsCause() { final IOException ioe = new IOException(); + final MemoryLimitException e = new MemoryLimitException(1, 2, (Throwable) ioe); + assertEquals(1, e.getMemoryNeededInKb()); + assertEquals(2, e.getMemoryLimitInKb()); + assertSame(ioe, e.getCause()); + } + + @Test + public void testAccessorsCauseDepreacted() { + final IOException ioe = new IOException(); + @SuppressWarnings("deprecation") final MemoryLimitException e = new MemoryLimitException(1, 2, ioe); assertEquals(1, e.getMemoryNeededInKb()); assertEquals(2, e.getMemoryLimitInKb());