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 2022/09/30 12:41:01 UTC

[commons-compress] 02/02: Replace anti-pattern of throwing RuntimeException with more precise runtime exceptions

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 24193630a2ce688226072998d17392f511b250ba
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Fri Sep 30 08:40:53 2022 -0400

    Replace anti-pattern of throwing RuntimeException with more precise
    runtime exceptions
---
 .../compress/archivers/zip/AsiExtraField.java      |   2 +-
 .../compress/archivers/zip/ExtraFieldUtils.java    |   6 +-
 .../compress/archivers/zip/GeneralPurposeBit.java  |   2 +-
 .../archivers/zip/ParallelScatterZipCreator.java   |  13 +--
 .../compress/archivers/zip/ZipArchiveEntry.java    |  36 ++++----
 .../commons/compress/archivers/zip/ZipLong.java    |   2 +-
 .../commons/compress/archivers/zip/ZipShort.java   |   2 +-
 .../pack200/Pack200CompressorInputStream.java      |   5 +-
 .../commons/compress/harmony/pack200/BandSet.java  |   4 +-
 .../commons/compress/harmony/pack200/BcBands.java  |   6 +-
 .../compress/harmony/pack200/ClassBands.java       |   8 +-
 .../harmony/pack200/NewAttributeBands.java         |   3 +-
 .../compress/harmony/pack200/PackingOptions.java   |   2 +-
 .../compress/harmony/pack200/PackingUtils.java     |   4 +-
 .../commons/compress/harmony/pack200/Segment.java  |  12 +--
 .../FileBasedScatterGatherBackingStore.java        |   3 +-
 .../apache/commons/compress/ArchiveReadTest.java   |   2 +-
 .../commons/compress/archivers/LongPathTest.java   |   2 +-
 .../compress/archivers/LongSymLinkTest.java        |   2 +-
 .../compress/archivers/zip/ZipFileTest.java        |  96 ++++++++++-----------
 .../harmony/unpack200/tests/Compress626Test.java   |  55 ++++++++++++
 .../compress/COMPRESS-626/compress-626-pack200.jar | Bin 0 -> 781 bytes
 22 files changed, 159 insertions(+), 108 deletions(-)

diff --git a/src/main/java/org/apache/commons/compress/archivers/zip/AsiExtraField.java b/src/main/java/org/apache/commons/compress/archivers/zip/AsiExtraField.java
index a487bc39..6f6a1b76 100644
--- a/src/main/java/org/apache/commons/compress/archivers/zip/AsiExtraField.java
+++ b/src/main/java/org/apache/commons/compress/archivers/zip/AsiExtraField.java
@@ -342,7 +342,7 @@ public class AsiExtraField implements ZipExtraField, UnixStat, Cloneable {
             return cloned;
         } catch (final CloneNotSupportedException cnfe) {
             // impossible
-            throw new RuntimeException(cnfe); //NOSONAR
+            throw new IllegalStateException(cnfe); //NOSONAR
         }
     }
 }
diff --git a/src/main/java/org/apache/commons/compress/archivers/zip/ExtraFieldUtils.java b/src/main/java/org/apache/commons/compress/archivers/zip/ExtraFieldUtils.java
index 89086283..699754b9 100644
--- a/src/main/java/org/apache/commons/compress/archivers/zip/ExtraFieldUtils.java
+++ b/src/main/java/org/apache/commons/compress/archivers/zip/ExtraFieldUtils.java
@@ -68,11 +68,11 @@ public class ExtraFieldUtils {
             final ZipExtraField ze = (ZipExtraField) c.newInstance();
             implementations.put(ze.getHeaderId(), c);
         } catch (final ClassCastException cc) { // NOSONAR
-            throw new RuntimeException(c + " doesn't implement ZipExtraField"); //NOSONAR
+            throw new IllegalArgumentException(c + " doesn't implement ZipExtraField"); //NOSONAR
         } catch (final InstantiationException ie) { // NOSONAR
-            throw new RuntimeException(c + " is not a concrete class"); //NOSONAR
+            throw new IllegalArgumentException(c + " is not a concrete class"); //NOSONAR
         } catch (final IllegalAccessException ie) { // NOSONAR
-            throw new RuntimeException(c + "'s no-arg constructor is not public"); //NOSONAR
+            throw new IllegalArgumentException(c + "'s no-arg constructor is not public"); //NOSONAR
         }
     }
 
diff --git a/src/main/java/org/apache/commons/compress/archivers/zip/GeneralPurposeBit.java b/src/main/java/org/apache/commons/compress/archivers/zip/GeneralPurposeBit.java
index e87f661e..9e00009e 100644
--- a/src/main/java/org/apache/commons/compress/archivers/zip/GeneralPurposeBit.java
+++ b/src/main/java/org/apache/commons/compress/archivers/zip/GeneralPurposeBit.java
@@ -239,7 +239,7 @@ public final class GeneralPurposeBit implements Cloneable {
             return super.clone();
         } catch (final CloneNotSupportedException ex) {
             // impossible
-            throw new RuntimeException("GeneralPurposeBit is not Cloneable?", ex); //NOSONAR
+            throw new IllegalStateException("GeneralPurposeBit is not Cloneable?", ex); //NOSONAR
         }
     }
 }
diff --git a/src/main/java/org/apache/commons/compress/archivers/zip/ParallelScatterZipCreator.java b/src/main/java/org/apache/commons/compress/archivers/zip/ParallelScatterZipCreator.java
index 5ed7eb34..99353dcd 100644
--- a/src/main/java/org/apache/commons/compress/archivers/zip/ParallelScatterZipCreator.java
+++ b/src/main/java/org/apache/commons/compress/archivers/zip/ParallelScatterZipCreator.java
@@ -17,12 +17,10 @@
  */
 package org.apache.commons.compress.archivers.zip;
 
-import org.apache.commons.compress.parallel.FileBasedScatterGatherBackingStore;
-import org.apache.commons.compress.parallel.InputStreamSupplier;
-import org.apache.commons.compress.parallel.ScatterGatherBackingStore;
-import org.apache.commons.compress.parallel.ScatterGatherBackingStoreSupplier;
+import static org.apache.commons.compress.archivers.zip.ZipArchiveEntryRequest.createZipArchiveEntryRequest;
 
 import java.io.IOException;
+import java.io.UncheckedIOException;
 import java.nio.file.Files;
 import java.nio.file.Path;
 import java.util.Deque;
@@ -36,7 +34,10 @@ import java.util.concurrent.TimeUnit;
 import java.util.concurrent.atomic.AtomicInteger;
 import java.util.zip.Deflater;
 
-import static org.apache.commons.compress.archivers.zip.ZipArchiveEntryRequest.createZipArchiveEntryRequest;
+import org.apache.commons.compress.parallel.FileBasedScatterGatherBackingStore;
+import org.apache.commons.compress.parallel.InputStreamSupplier;
+import org.apache.commons.compress.parallel.ScatterGatherBackingStore;
+import org.apache.commons.compress.parallel.ScatterGatherBackingStoreSupplier;
 
 /**
  * Creates a zip in parallel by using multiple threadlocal {@link ScatterZipOutputStream} instances.
@@ -88,7 +89,7 @@ public class ParallelScatterZipCreator {
                 streams.add(scatterStream);
                 return scatterStream;
             } catch (final IOException e) {
-                throw new RuntimeException(e); //NOSONAR
+                throw new UncheckedIOException(e); //NOSONAR
             }
         }
     };
diff --git a/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveEntry.java b/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveEntry.java
index a1c0f8a4..0186f4ab 100644
--- a/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveEntry.java
+++ b/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveEntry.java
@@ -696,16 +696,15 @@ public class ZipArchiveEntry extends java.util.zip.ZipEntry
      * @throws RuntimeException on error
      */
     @Override
-    public void setExtra(final byte[] extra) throws RuntimeException {
-        try {
-            final ZipExtraField[] local = ExtraFieldUtils.parse(extra, true, ExtraFieldParsingMode.BEST_EFFORT);
-            mergeExtraFields(local, true);
-        } catch (final ZipException e) {
-            // actually this is not possible as of Commons Compress 1.1
-            throw new RuntimeException("Error parsing extra fields for entry: " //NOSONAR
-                                       + getName() + " - " + e.getMessage(), e);
-        }
-    }
+	public void setExtra(final byte[] extra) throws RuntimeException {
+		try {
+			mergeExtraFields(ExtraFieldUtils.parse(extra, true, ExtraFieldParsingMode.BEST_EFFORT), true);
+		} catch (final ZipException e) {
+			// actually this is not possible as of Commons Compress 1.1
+			throw new IllegalArgumentException("Error parsing extra fields for entry: " // NOSONAR
+					+ getName() + " - " + e.getMessage(), e);
+		}
+	}
 
     /**
      * Unfortunately {@link java.util.zip.ZipOutputStream
@@ -721,15 +720,14 @@ public class ZipArchiveEntry extends java.util.zip.ZipEntry
      * Sets the central directory part of extra fields.
      * @param b an array of bytes to be parsed into extra fields
      */
-    public void setCentralDirectoryExtra(final byte[] b) {
-        try {
-            final ZipExtraField[] central = ExtraFieldUtils.parse(b, false, ExtraFieldParsingMode.BEST_EFFORT);
-            mergeExtraFields(central, false);
-        } catch (final ZipException e) {
-            // actually this is not possible as of Commons Compress 1.19
-            throw new RuntimeException(e.getMessage(), e); //NOSONAR
-        }
-    }
+	public void setCentralDirectoryExtra(final byte[] b) {
+		try {
+			mergeExtraFields(ExtraFieldUtils.parse(b, false, ExtraFieldParsingMode.BEST_EFFORT), false);
+		} catch (final ZipException e) {
+			// actually this is not possible as of Commons Compress 1.19
+			throw new IllegalArgumentException(e.getMessage(), e); // NOSONAR
+		}
+	}
 
     /**
      * Retrieves the extra data for the local file data.
diff --git a/src/main/java/org/apache/commons/compress/archivers/zip/ZipLong.java b/src/main/java/org/apache/commons/compress/archivers/zip/ZipLong.java
index cab0ecb1..0b179eff 100644
--- a/src/main/java/org/apache/commons/compress/archivers/zip/ZipLong.java
+++ b/src/main/java/org/apache/commons/compress/archivers/zip/ZipLong.java
@@ -205,7 +205,7 @@ public final class ZipLong implements Cloneable, Serializable {
             return super.clone();
         } catch (final CloneNotSupportedException cnfe) {
             // impossible
-            throw new RuntimeException(cnfe); //NOSONAR
+            throw new IllegalStateException(cnfe); //NOSONAR
         }
     }
 
diff --git a/src/main/java/org/apache/commons/compress/archivers/zip/ZipShort.java b/src/main/java/org/apache/commons/compress/archivers/zip/ZipShort.java
index 93d4bedc..3bba7d35 100644
--- a/src/main/java/org/apache/commons/compress/archivers/zip/ZipShort.java
+++ b/src/main/java/org/apache/commons/compress/archivers/zip/ZipShort.java
@@ -150,7 +150,7 @@ public final class ZipShort implements Cloneable, Serializable {
             return super.clone();
         } catch (final CloneNotSupportedException cnfe) {
             // impossible
-            throw new RuntimeException(cnfe); //NOSONAR
+            throw new IllegalStateException(cnfe); //NOSONAR
         }
     }
 
diff --git a/src/main/java/org/apache/commons/compress/compressors/pack200/Pack200CompressorInputStream.java b/src/main/java/org/apache/commons/compress/compressors/pack200/Pack200CompressorInputStream.java
index be555581..a9fdbf11 100644
--- a/src/main/java/org/apache/commons/compress/compressors/pack200/Pack200CompressorInputStream.java
+++ b/src/main/java/org/apache/commons/compress/compressors/pack200/Pack200CompressorInputStream.java
@@ -22,11 +22,12 @@ package org.apache.commons.compress.compressors.pack200;
 import java.io.File;
 import java.io.IOException;
 import java.io.InputStream;
+import java.io.UncheckedIOException;
 import java.util.Map;
 import java.util.jar.JarOutputStream;
-import org.apache.commons.compress.java.util.jar.Pack200;
 
 import org.apache.commons.compress.compressors.CompressorInputStream;
+import org.apache.commons.compress.java.util.jar.Pack200;
 import org.apache.commons.compress.utils.CloseShieldFilterInputStream;
 import org.apache.commons.compress.utils.IOUtils;
 
@@ -223,7 +224,7 @@ public class Pack200CompressorInputStream extends CompressorInputStream {
         try {
             streamBridge.getInput().mark(limit);
         } catch (final IOException ex) {
-            throw new RuntimeException(ex); //NOSONAR
+            throw new UncheckedIOException(ex); //NOSONAR
         }
     }
 
diff --git a/src/main/java/org/apache/commons/compress/harmony/pack200/BandSet.java b/src/main/java/org/apache/commons/compress/harmony/pack200/BandSet.java
index cf3758b3..96aa2415 100644
--- a/src/main/java/org/apache/commons/compress/harmony/pack200/BandSet.java
+++ b/src/main/java/org/apache/commons/compress/harmony/pack200/BandSet.java
@@ -586,7 +586,7 @@ public abstract class BandSet {
         for (int i = 0; i < array.length; i++) {
             array[i] = list.get(i).getIndex();
             if (array[i] < 0) {
-                throw new RuntimeException("Index should be > 0");
+                throw new IllegalArgumentException("Index should be > 0");
             }
         }
         return array;
@@ -604,7 +604,7 @@ public abstract class BandSet {
             final ConstantPoolEntry cpEntry = theList.get(j);
             array[j] = cpEntry == null ? 0 : cpEntry.getIndex() + 1;
             if (cpEntry != null && cpEntry.getIndex() < 0) {
-                throw new RuntimeException("Index should be > 0");
+                throw new IllegalArgumentException("Index should be > 0");
             }
         }
         return array;
diff --git a/src/main/java/org/apache/commons/compress/harmony/pack200/BcBands.java b/src/main/java/org/apache/commons/compress/harmony/pack200/BcBands.java
index 573931ca..c36c5ca2 100644
--- a/src/main/java/org/apache/commons/compress/harmony/pack200/BcBands.java
+++ b/src/main/java/org/apache/commons/compress/harmony/pack200/BcBands.java
@@ -221,7 +221,7 @@ public class BcBands extends BandSet {
         }
         if (renumberedOffset != 0) {
             if (renumberedOffset + 1 != bciRenumbering.size()) {
-                throw new RuntimeException("Mistake made with renumbering");
+                throw new IllegalStateException("Mistake made with renumbering");
             }
             for (int i = bcLabel.size() - 1; i >= 0; i--) {
                 final Object label = bcLabel.get(i);
@@ -309,7 +309,7 @@ public class BcBands extends BandSet {
 
     public void visitInsn(final int opcode) {
         if (opcode >= 202) {
-            throw new RuntimeException("Non-standard bytecode instructions not supported");
+            throw new IllegalArgumentException("Non-standard bytecode instructions not supported");
         }
         bcCodes.add(opcode);
         byteCodeOffset++;
@@ -363,7 +363,7 @@ public class BcBands extends BandSet {
                 bcCodes.add(236); // cldc
                 bcClassRef.add(constant);
             } else {
-                throw new RuntimeException("Constant should not be null");
+                throw new IllegalArgumentException("Constant should not be null");
             }
         } else {
             byteCodeOffset += 2;
diff --git a/src/main/java/org/apache/commons/compress/harmony/pack200/ClassBands.java b/src/main/java/org/apache/commons/compress/harmony/pack200/ClassBands.java
index e384ee75..3a830444 100644
--- a/src/main/java/org/apache/commons/compress/harmony/pack200/ClassBands.java
+++ b/src/main/java/org/apache/commons/compress/harmony/pack200/ClassBands.java
@@ -1012,7 +1012,7 @@ public class ClassBands extends BandSet {
                 return;
             }
         }
-        throw new RuntimeException("No suitable definition for " + attributeName);
+        throw new IllegalArgumentException("No suitable definition for " + attributeName);
     }
 
     public void addFieldAttribute(final NewAttribute attribute) {
@@ -1027,7 +1027,7 @@ public class ClassBands extends BandSet {
                 return;
             }
         }
-        throw new RuntimeException("No suitable definition for " + attributeName);
+        throw new IllegalArgumentException("No suitable definition for " + attributeName);
     }
 
     public void addMethodAttribute(final NewAttribute attribute) {
@@ -1042,7 +1042,7 @@ public class ClassBands extends BandSet {
                 return;
             }
         }
-        throw new RuntimeException("No suitable definition for " + attributeName);
+        throw new IllegalArgumentException("No suitable definition for " + attributeName);
     }
 
     public void addCodeAttribute(final NewAttribute attribute) {
@@ -1057,7 +1057,7 @@ public class ClassBands extends BandSet {
                 return;
             }
         }
-        throw new RuntimeException("No suitable definition for " + attributeName);
+        throw new IllegalArgumentException("No suitable definition for " + attributeName);
     }
 
     public void addMaxStack(final int maxStack, int maxLocals) {
diff --git a/src/main/java/org/apache/commons/compress/harmony/pack200/NewAttributeBands.java b/src/main/java/org/apache/commons/compress/harmony/pack200/NewAttributeBands.java
index 591ac530..d5bd9176 100644
--- a/src/main/java/org/apache/commons/compress/harmony/pack200/NewAttributeBands.java
+++ b/src/main/java/org/apache/commons/compress/harmony/pack200/NewAttributeBands.java
@@ -21,6 +21,7 @@ import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
 import java.io.StringReader;
+import java.io.UncheckedIOException;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.List;
@@ -808,7 +809,7 @@ public class NewAttributeBands extends BandSet {
             try {
                 result = result << 8 | stream.read();
             } catch (final IOException e) {
-                throw new RuntimeException("Error reading unknown attribute");
+                throw new UncheckedIOException("Error reading unknown attribute", e);
             }
         }
         // use casting to preserve sign
diff --git a/src/main/java/org/apache/commons/compress/harmony/pack200/PackingOptions.java b/src/main/java/org/apache/commons/compress/harmony/pack200/PackingOptions.java
index cda71f41..b6d37273 100644
--- a/src/main/java/org/apache/commons/compress/harmony/pack200/PackingOptions.java
+++ b/src/main/java/org/apache/commons/compress/harmony/pack200/PackingOptions.java
@@ -284,7 +284,7 @@ public class PackingOptions {
     public void setUnknownAttributeAction(final String unknownAttributeAction) {
         this.unknownAttributeAction = unknownAttributeAction;
         if (!PASS.equals(unknownAttributeAction) && !ERROR.equals(unknownAttributeAction) && !STRIP.equals(unknownAttributeAction)) {
-            throw new RuntimeException("Incorrect option for -U, " + unknownAttributeAction);
+            throw new IllegalArgumentException("Incorrect option for -U, " + unknownAttributeAction);
         }
     }
 
diff --git a/src/main/java/org/apache/commons/compress/harmony/pack200/PackingUtils.java b/src/main/java/org/apache/commons/compress/harmony/pack200/PackingUtils.java
index a187d24c..e9ad068c 100644
--- a/src/main/java/org/apache/commons/compress/harmony/pack200/PackingUtils.java
+++ b/src/main/java/org/apache/commons/compress/harmony/pack200/PackingUtils.java
@@ -191,14 +191,14 @@ public class PackingUtils {
         long size = jarEntry.getSize();
         if (size > Integer.MAX_VALUE) {
             // TODO: Should probably allow this
-            throw new RuntimeException("Large Class!");
+            throw new IllegalArgumentException("Large Class!");
         }
         if (size < 0) {
             size = 0;
         }
         final byte[] bytes = new byte[(int) size];
         if (inputStream.read(bytes) != size) {
-            throw new RuntimeException("Error reading from stream");
+            throw new IllegalArgumentException("Error reading from stream");
         }
         return bytes;
     }
diff --git a/src/main/java/org/apache/commons/compress/harmony/pack200/Segment.java b/src/main/java/org/apache/commons/compress/harmony/pack200/Segment.java
index fe8a7fd9..7e9e2ba0 100644
--- a/src/main/java/org/apache/commons/compress/harmony/pack200/Segment.java
+++ b/src/main/java/org/apache/commons/compress/harmony/pack200/Segment.java
@@ -229,7 +229,7 @@ public class Segment extends ClassVisitor {
             }
             classBands.addClassAttribute(newAttribute);
         } else {
-            throw new RuntimeException("Unexpected attribute encountered: " + attribute.type);
+            throw new IllegalArgumentException("Unexpected attribute encountered: " + attribute.type);
         }
     }
 
@@ -311,7 +311,7 @@ public class Segment extends ClassVisitor {
                     classBands.addMethodAttribute(newAttribute);
                 }
             } else {
-                throw new RuntimeException("Unexpected attribute encountered: " + attribute.type);
+                throw new IllegalArgumentException("Unexpected attribute encountered: " + attribute.type);
             }
         }
 
@@ -503,13 +503,13 @@ public class Segment extends ClassVisitor {
 
                 @Override
                 public AnnotationVisitor visitAnnotation(final String arg0, final String arg1) {
-                    throw new RuntimeException("Not yet supported");
+                    throw new UnsupportedOperationException("Not yet supported");
 //                    return null;
                 }
 
                 @Override
                 public AnnotationVisitor visitArray(final String arg0) {
-                    throw new RuntimeException("Not yet supported");
+                    throw new UnsupportedOperationException("Not yet supported");
 //                    return null;
                 }
 
@@ -596,7 +596,7 @@ public class Segment extends ClassVisitor {
 
         @Override
         public AnnotationVisitor visitAnnotation(final String arg0, final String arg1) {
-            throw new RuntimeException("Not yet supported");
+            throw new UnsupportedOperationException("Not yet supported");
         }
 
         @Override
@@ -660,7 +660,7 @@ public class Segment extends ClassVisitor {
                 }
                 classBands.addFieldAttribute(newAttribute);
             } else {
-                throw new RuntimeException("Unexpected attribute encountered: " + attribute.type);
+                throw new IllegalArgumentException("Unexpected attribute encountered: " + attribute.type);
             }
         }
 
diff --git a/src/main/java/org/apache/commons/compress/parallel/FileBasedScatterGatherBackingStore.java b/src/main/java/org/apache/commons/compress/parallel/FileBasedScatterGatherBackingStore.java
index 52a0de35..35f88aa4 100644
--- a/src/main/java/org/apache/commons/compress/parallel/FileBasedScatterGatherBackingStore.java
+++ b/src/main/java/org/apache/commons/compress/parallel/FileBasedScatterGatherBackingStore.java
@@ -22,6 +22,7 @@ import java.io.FileNotFoundException;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
+import java.io.UncheckedIOException;
 import java.nio.file.Files;
 import java.nio.file.Path;
 
@@ -54,7 +55,7 @@ public class FileBasedScatterGatherBackingStore implements ScatterGatherBackingS
             throw ex;
         } catch (final IOException ex) {
             // must convert exception to stay backwards compatible with Compress 1.10 to 1.13
-            throw new RuntimeException(ex); // NOSONAR
+            throw new UncheckedIOException(ex); // NOSONAR
         }
     }
 
diff --git a/src/test/java/org/apache/commons/compress/ArchiveReadTest.java b/src/test/java/org/apache/commons/compress/ArchiveReadTest.java
index 112826c9..44708348 100644
--- a/src/test/java/org/apache/commons/compress/ArchiveReadTest.java
+++ b/src/test/java/org/apache/commons/compress/ArchiveReadTest.java
@@ -54,7 +54,7 @@ public class ArchiveReadTest extends AbstractTestCase {
         try {
             ARCDIR = new File(CLASSLOADER.getResource("archives").toURI());
         } catch (final URISyntaxException e) {
-            throw new RuntimeException(e);
+            throw new AssertionError(e);
         }
     }
 
diff --git a/src/test/java/org/apache/commons/compress/archivers/LongPathTest.java b/src/test/java/org/apache/commons/compress/archivers/LongPathTest.java
index d0ee6759..c6174ca7 100644
--- a/src/test/java/org/apache/commons/compress/archivers/LongPathTest.java
+++ b/src/test/java/org/apache/commons/compress/archivers/LongPathTest.java
@@ -59,7 +59,7 @@ public class LongPathTest extends AbstractTestCase {
         try {
             ARCDIR = new File(CLASSLOADER.getResource("longpath").toURI());
         } catch (final URISyntaxException e) {
-            throw new RuntimeException(e);
+            throw new AssertionError(e);
         }
     }
 
diff --git a/src/test/java/org/apache/commons/compress/archivers/LongSymLinkTest.java b/src/test/java/org/apache/commons/compress/archivers/LongSymLinkTest.java
index c513b1ef..21306daf 100644
--- a/src/test/java/org/apache/commons/compress/archivers/LongSymLinkTest.java
+++ b/src/test/java/org/apache/commons/compress/archivers/LongSymLinkTest.java
@@ -59,7 +59,7 @@ public class LongSymLinkTest extends AbstractTestCase {
         try {
             ARCDIR = new File(CLASSLOADER.getResource("longsymlink").toURI());
         } catch (final URISyntaxException e) {
-            throw new RuntimeException(e);
+            throw new AssertionError(e);
         }
     }
 
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 9b46c62f..5a543413 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
@@ -854,57 +854,51 @@ public class ZipFileTest {
         }
     }
 
-    private void assertAllReadMethods(final byte[] expected, final ZipFile zipFile, final ZipArchiveEntry entry) {
-        // simple IOUtil read
-        try (InputStream stream = zf.getInputStream(entry)) {
-            final byte[] full = IOUtils.toByteArray(stream);
-            assertArrayEquals(expected, full);
-        }
-        catch (final IOException ex) {
-            throw new RuntimeException(ex);
-        }
-
-        // big buffer at the beginning and then chunks by IOUtils read
-        try (InputStream stream = zf.getInputStream(entry)) {
-            byte[] full;
-            final byte[] bytes = new byte[0x40000];
-            final int read = stream.read(bytes);
-            if (read < 0) {
-                full = ByteUtils.EMPTY_BYTE_ARRAY;
-            }
-            else {
-                full = readStreamRest(bytes, read, stream);
-            }
-            assertArrayEquals(expected, full);
-        }
-        catch (final IOException ex) {
-            throw new RuntimeException(ex);
-        }
-
-        // small chunk / single byte and big buffer then
-        try (InputStream stream = zf.getInputStream(entry)) {
-            byte[] full;
-            final int single = stream.read();
-            if (single < 0) {
-                full = ByteUtils.EMPTY_BYTE_ARRAY;
-            }
-            else {
-                final byte[] big = new byte[0x40000];
-                big[0] = (byte)single;
-                final int read = stream.read(big, 1, big.length-1);
-                if (read < 0) {
-                    full = new byte[]{ (byte)single };
-                }
-                else {
-                    full = readStreamRest(big, read+1, stream);
-                }
-            }
-            assertArrayEquals(expected, full);
-        }
-        catch (final IOException ex) {
-            throw new RuntimeException(ex);
-        }
-    }
+	private void assertAllReadMethods(final byte[] expected, final ZipFile zipFile, final ZipArchiveEntry entry) {
+		// simple IOUtil read
+		try (InputStream stream = zf.getInputStream(entry)) {
+			final byte[] full = IOUtils.toByteArray(stream);
+			assertArrayEquals(expected, full);
+		} catch (final IOException ex) {
+			throw new AssertionError(ex);
+		}
+
+		// big buffer at the beginning and then chunks by IOUtils read
+		try (InputStream stream = zf.getInputStream(entry)) {
+			byte[] full;
+			final byte[] bytes = new byte[0x40000];
+			final int read = stream.read(bytes);
+			if (read < 0) {
+				full = ByteUtils.EMPTY_BYTE_ARRAY;
+			} else {
+				full = readStreamRest(bytes, read, stream);
+			}
+			assertArrayEquals(expected, full);
+		} catch (final IOException ex) {
+			throw new AssertionError(ex);
+		}
+
+		// small chunk / single byte and big buffer then
+		try (InputStream stream = zf.getInputStream(entry)) {
+			byte[] full;
+			final int single = stream.read();
+			if (single < 0) {
+				full = ByteUtils.EMPTY_BYTE_ARRAY;
+			} else {
+				final byte[] big = new byte[0x40000];
+				big[0] = (byte) single;
+				final int read = stream.read(big, 1, big.length - 1);
+				if (read < 0) {
+					full = new byte[] { (byte) single };
+				} else {
+					full = readStreamRest(big, read + 1, stream);
+				}
+			}
+			assertArrayEquals(expected, full);
+		} catch (final IOException ex) {
+			throw new AssertionError(ex);
+		}
+	}
 
     /**
      * Utility to append the rest of the stream to already read data.
diff --git a/src/test/java/org/apache/commons/compress/harmony/unpack200/tests/Compress626Test.java b/src/test/java/org/apache/commons/compress/harmony/unpack200/tests/Compress626Test.java
new file mode 100644
index 00000000..690cb6ef
--- /dev/null
+++ b/src/test/java/org/apache/commons/compress/harmony/unpack200/tests/Compress626Test.java
@@ -0,0 +1,55 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+package org.apache.commons.compress.harmony.unpack200.tests;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.nio.file.Files;
+import java.nio.file.Paths;
+import java.util.jar.JarOutputStream;
+
+import org.apache.commons.compress.harmony.pack200.AttributeDefinitionBands;
+import org.apache.commons.compress.harmony.pack200.CPUTF8;
+import org.apache.commons.compress.harmony.pack200.NewAttributeBands;
+import org.apache.commons.compress.java.util.jar.Pack200;
+import org.apache.commons.io.output.NullOutputStream;
+import org.junit.Ignore;
+import org.junit.jupiter.api.Disabled;
+import org.junit.jupiter.api.Test;
+
+@Disabled @Ignore
+public class Compress626Test {
+
+	@Test
+    public void test() throws Exception {
+		CPUTF8 name = new CPUTF8("");
+		CPUTF8 layout = new CPUTF8("[");
+        new NewAttributeBands(1, null, null,
+                new AttributeDefinitionBands.AttributeDefinition(35, AttributeDefinitionBands.CONTEXT_CLASS, name, layout)
+        );
+    }
+
+	@Test
+	public void testJar() throws IOException {
+		try (InputStream inputStream = Files.newInputStream(
+				Paths.get("src/test/resources/org/apache/commons/compress/COMPRESS-626/compress-626-pack200.jar"));
+				JarOutputStream out = new JarOutputStream(NullOutputStream.NULL_OUTPUT_STREAM);) {
+			Pack200.newUnpacker().unpack(inputStream, out);
+		}
+	}
+}
diff --git a/src/test/resources/org/apache/commons/compress/COMPRESS-626/compress-626-pack200.jar b/src/test/resources/org/apache/commons/compress/COMPRESS-626/compress-626-pack200.jar
new file mode 100644
index 00000000..4c234830
Binary files /dev/null and b/src/test/resources/org/apache/commons/compress/COMPRESS-626/compress-626-pack200.jar differ