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
commit 32d30c21b66b978b8149c6929359f4740224442b Author: Gary D. Gregory <garydgreg...@gmail.com> AuthorDate: Tue Aug 26 15:44:35 2025 -0400 org.apache.commons.compress.harmony.unpack200.IcBands.unpack() now throws Pack200Exception instead of Error Add org.apache.commons.compress.harmony.pack200.Pack200Exception.requireNonNull(T, String, Object...) --- src/changes/changes.xml | 1 + .../compress/harmony/pack200/Pack200Exception.java | 18 ++++++++++++++++++ .../commons/compress/harmony/unpack200/IcBands.java | 7 +------ 3 files changed, 20 insertions(+), 6 deletions(-) diff --git a/src/changes/changes.xml b/src/changes/changes.xml index c7f2cd91a..9aa0769a1 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -103,6 +103,7 @@ The <action> type attribute can be add,update,fix,remove. <action type="add" dev="ggregory" due-to="Gary Gregory">Add org.apache.commons.compress.archivers.ArchiveException.ArchiveException(String, Object...).</action> <action type="add" dev="ggregory" due-to="Gary Gregory">Add org.apache.commons.compress.compressors.CompressorException.CompressorException(String, Object...).</action> <action type="add" dev="ggregory" due-to="Gary Gregory">Add org.apache.commons.compress.harmony.pack200.Pack200Exception.Pack200Exception(String, Object...).</action> + <action type="add" dev="ggregory" due-to="Gary Gregory">Add org.apache.commons.compress.harmony.pack200.Pack200Exception.requireNonNull(T, String, Object...).</action> <action type="add" dev="ggregory" due-to="Gary Gregory">Add org.apache.commons.compress.MemoryLimitException.checkBytes(int, long).</action> <action type="add" dev="ggregory" due-to="Gary Gregory">Add org.apache.commons.compress.MemoryLimitException.checkKiB(long, long).</action> <action type="add" dev="ggregory" due-to="Gary Gregory">Add org.apache.commons.compress.archivers.ArchiveException.addExact(int, int).</action> 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 b08c6a2af..069b439da 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 @@ -83,6 +83,24 @@ public static void checkIntArray(final int size, final int count) throws Pack200 } } + /** + * Throws a Pack200Exception if the given object is null. + * + * @param <T> The object type. + * @param obj The object to test. + * @param message The message format (which is saved for later retrieval by the {@link #getMessage()} method). + * @param args the format arguments to use. + * @return The given object. + * @throws Pack200Exception Thrown if {@code obj} is null. + * @since 1.29.0 + */ + public static <T> T requireNonNull(final T obj, final String message, final Object... args) throws Pack200Exception { + if (obj == null) { + throw new Pack200Exception(message, args); + } + return obj; + } + /** * Constructs an {@code Pack200Exception} with the specified detail message. * diff --git a/src/main/java/org/apache/commons/compress/harmony/unpack200/IcBands.java b/src/main/java/org/apache/commons/compress/harmony/unpack200/IcBands.java index 69a146b8e..22143f652 100644 --- a/src/main/java/org/apache/commons/compress/harmony/unpack200/IcBands.java +++ b/src/main/java/org/apache/commons/compress/harmony/unpack200/IcBands.java @@ -174,7 +174,6 @@ public void read(final InputStream in) throws IOException, Pack200Exception { icName[i] = cpUTF8[icNameInts[i] - 1]; } } - // Construct IC tuples icAll = new IcTuple[icThisClass.length]; int index = 0; @@ -203,21 +202,17 @@ public void unpack() throws IOException, Pack200Exception { thisClassToTuple = new HashMap<>(allTuples.length); outerClassToTuples = new HashMap<>(allTuples.length); for (final IcTuple tuple : allTuples) { - // generate mapping thisClassString -> IcTuple // presumably this relation is 1:1 // final Object result = thisClassToTuple.put(tuple.thisClassString(), tuple); if (result != null) { - throw new Error("Collision detected in <thisClassString, IcTuple> mapping. There are at least two inner clases with the same name."); + throw new Pack200Exception("Collision detected in <thisClassString, IcTuple> mapping. There are at least two inner clases with the same name."); } - // generate mapping outerClassString -> IcTuple // this relation is 1:M - // If it's not anon and the outer is not anon, it could be relevant if (!tuple.isAnonymous() && !tuple.outerIsAnonymous() || tuple.nestedExplicitFlagSet()) { - // add tuple to corresponding bucket final String key = tuple.outerClassString(); outerClassToTuples.computeIfAbsent(key, k -> new ArrayList<>()).add(tuple);