You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2025/08/09 20:45:26 UTC

(commons-compress) 01/03: org.apache.commons.compress.harmony.unpack200 now throws Pack200Exception instead of Error

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 151f2bc967da6fb1842bc36089be3232fbf73a7b
Author: Gary D. Gregory <ga...@gmail.com>
AuthorDate: Sat Aug 9 16:21:13 2025 -0400

    org.apache.commons.compress.harmony.unpack200 now throws
    Pack200Exception instead of Error
    
    org.apache.commons.compress.harmony.pack200 now throws Pack200Exception
    instead of Error
---
 src/changes/changes.xml                                              | 2 ++
 .../org/apache/commons/compress/harmony/pack200/CodecEncoding.java   | 2 +-
 .../org/apache/commons/compress/harmony/unpack200/SegmentHeader.java | 5 +----
 .../compress/harmony/unpack200/bytecode/AnnotationsAttribute.java    | 4 +++-
 .../compress/harmony/unpack200/bytecode/BCIRenumberedAttribute.java  | 2 +-
 .../bytecode/RuntimeVisibleorInvisibleAnnotationsAttribute.java      | 4 +++-
 6 files changed, 11 insertions(+), 8 deletions(-)

diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 559f258f0..47611e180 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -73,10 +73,12 @@ The <action> type attribute can be add,update,fix,remove.
       <action type="fix" dev="ggregory" due-to="Gary Gregory">org.apache.commons.compress.archivers.ar.ArArchiveInputStream.read(byte[], int, int) now throws ArchiveException instead of ArithmeticException.</action>
       <!-- FIX unpack200 -->      
       <action type="fix" dev="ggregory" due-to="Gary Gregory">org.apache.commons.compress.harmony.unpack200.BandSet now throws ArchiveException instead of Arithmetic exception.</action>
+      <action type="fix" dev="ggregory" due-to="Gary Gregory">org.apache.commons.compress.harmony.unpack200 now throws Pack200Exception instead of Error.</action>
       <!-- FIX pack200 -->      
       <action type="fix" dev="ggregory" due-to="Gary Gregory">org.apache.commons.compress.harmony.pack200.BHSDCodec now throws ArchiveException instead of Arithmetic exception.</action>
       <action type="fix" dev="ggregory" due-to="Gary Gregory">org.apache.commons.compress.harmony.pack200.RunCodec now throws ArchiveException instead of Arithmetic exception.</action>
       <action type="fix" dev="ggregory" due-to="Gary Gregory">org.apache.commons.compress.harmony.pack200.FileBands now throws ArchiveException instead of Arithmetic exception.</action>
+      <action type="fix" dev="ggregory" due-to="Gary Gregory">org.apache.commons.compress.harmony.pack200 now throws Pack200Exception instead of Error.</action>
       <!-- FIX cpio -->      
       <action type="fix" dev="ggregory" due-to="Stan, Gary Gregory">org.apache.commons.compress.archivers.cpio.CpioArchiveEntry now throws ArchiveException instead of Arithmetic exception.</action>
       <action type="fix" dev="ggregory" due-to="Stan, Gary Gregory">org.apache.commons.compress.archivers.cpio.CpioArchiveInputStream.getNextEntry() now throws a MemoryLimitException instead of OutOfMemoryError when it can't process input greater than available memory.</action>
diff --git a/src/main/java/org/apache/commons/compress/harmony/pack200/CodecEncoding.java b/src/main/java/org/apache/commons/compress/harmony/pack200/CodecEncoding.java
index b4543cd27..76067752f 100644
--- a/src/main/java/org/apache/commons/compress/harmony/pack200/CodecEncoding.java
+++ b/src/main/java/org/apache/commons/compress/harmony/pack200/CodecEncoding.java
@@ -91,7 +91,7 @@ public static Codec getCodec(final int value, final InputStream in, final Codec
         // Sanity check to make sure that no-one has changed
         // the canonical codecs, which would really cause havoc
         if (canonicalCodec.length != 116) {
-            throw new Error("Canonical encodings have been incorrectly modified");
+            throw new Pack200Exception("Canonical encodings have been incorrectly modified");
         }
         if (value < 0) {
             throw new IllegalArgumentException("Encoding cannot be less than zero");
diff --git a/src/main/java/org/apache/commons/compress/harmony/unpack200/SegmentHeader.java b/src/main/java/org/apache/commons/compress/harmony/unpack200/SegmentHeader.java
index aaa4c078e..2b1fefcd7 100644
--- a/src/main/java/org/apache/commons/compress/harmony/unpack200/SegmentHeader.java
+++ b/src/main/java/org/apache/commons/compress/harmony/unpack200/SegmentHeader.java
@@ -285,11 +285,10 @@ private void parseCpCounts(final InputStream in) throws IOException, Pack200Exce
     }
 
     public void read(final InputStream in) throws IOException, Error, Pack200Exception {
-
         final int[] word = decodeScalar("archive_magic_word", in, Codec.BYTE1, magic.length);
         for (int m = 0; m < magic.length; m++) {
             if (word[m] != magic[m]) {
-                throw new Error("Bad header");
+                throw new Pack200Exception("Bad header");
             }
         }
         setArchiveMinorVersion(decodeScalar("archive_minver", in, Codec.UNSIGNED5));
@@ -299,11 +298,9 @@ public void read(final InputStream in) throws IOException, Error, Pack200Excepti
         parseArchiveSpecialCounts(in);
         parseCpCounts(in);
         parseClassCounts(in);
-
         if (getBandHeadersSize() > 0) {
             setBandHeadersData(IOUtils.readRange(in, getBandHeadersSize()));
         }
-
         archiveSizeOffset -= in.available();
     }
 
diff --git a/src/main/java/org/apache/commons/compress/harmony/unpack200/bytecode/AnnotationsAttribute.java b/src/main/java/org/apache/commons/compress/harmony/unpack200/bytecode/AnnotationsAttribute.java
index 93b16d999..baeff52a3 100644
--- a/src/main/java/org/apache/commons/compress/harmony/unpack200/bytecode/AnnotationsAttribute.java
+++ b/src/main/java/org/apache/commons/compress/harmony/unpack200/bytecode/AnnotationsAttribute.java
@@ -23,6 +23,8 @@
 import java.util.ArrayList;
 import java.util.List;
 
+import org.apache.commons.compress.harmony.pack200.Pack200Exception;
+
 /**
  * Abstracts Annotations attributes.
  */
@@ -246,7 +248,7 @@ public void writeBody(final DataOutputStream dos) throws IOException {
                     nestedValue.writeBody(dos);
                 }
             } else {
-                throw new Error("");
+                throw new Pack200Exception("Value is not a CPNameAndType, Annotation, or ElementValue.");
             }
         }
     }
diff --git a/src/main/java/org/apache/commons/compress/harmony/unpack200/bytecode/BCIRenumberedAttribute.java b/src/main/java/org/apache/commons/compress/harmony/unpack200/bytecode/BCIRenumberedAttribute.java
index 21d010f9d..5f8137a2a 100644
--- a/src/main/java/org/apache/commons/compress/harmony/unpack200/bytecode/BCIRenumberedAttribute.java
+++ b/src/main/java/org/apache/commons/compress/harmony/unpack200/bytecode/BCIRenumberedAttribute.java
@@ -73,7 +73,7 @@ public boolean hasBCIRenumbering() {
      */
     public void renumber(final List<Integer> byteCodeOffsets) throws Pack200Exception {
         if (renumbered) {
-            throw new Error("Trying to renumber a line number table that has already been renumbered");
+            throw new Pack200Exception("Trying to renumber a line number table that has already been renumbered");
         }
         renumbered = true;
         final int[] startPCs = getStartPCs();
diff --git a/src/main/java/org/apache/commons/compress/harmony/unpack200/bytecode/RuntimeVisibleorInvisibleAnnotationsAttribute.java b/src/main/java/org/apache/commons/compress/harmony/unpack200/bytecode/RuntimeVisibleorInvisibleAnnotationsAttribute.java
index 8de517b1e..83b1e01a0 100644
--- a/src/main/java/org/apache/commons/compress/harmony/unpack200/bytecode/RuntimeVisibleorInvisibleAnnotationsAttribute.java
+++ b/src/main/java/org/apache/commons/compress/harmony/unpack200/bytecode/RuntimeVisibleorInvisibleAnnotationsAttribute.java
@@ -23,6 +23,8 @@
 import java.util.ArrayList;
 import java.util.List;
 
+import org.apache.commons.compress.harmony.pack200.Pack200Exception;
+
 /**
  * Annotations class file attribute, either a RuntimeVisibleAnnotations attribute or a RuntimeInvisibleAnnotations attribute.
  */
@@ -81,7 +83,7 @@ protected void writeBody(final DataOutputStream dos) throws IOException {
             annotation.writeBody(dos);
         }
         if (dos.size() - size != getLength()) {
-            throw new Error();
+            throw new Pack200Exception("Bad length");
         }
     }
 }