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 2643070b86ce1890bf87b5ae15947036235da6d7 Author: Gary Gregory <garydgreg...@gmail.com> AuthorDate: Thu Apr 10 10:31:05 2025 -0400 Some org.apache.commons.compress.harmony.unpack200 methods now throws Pack200Exception instead of Error on some bad inputs and states - Bump org.apache.commons.compress.harmony.unpack200.SegmentConstantPool.getClassPoolEntry(String) now throws Pack200Exception instead of Error on some bad inputs and states. - Bump org.apache.commons.compress.harmony.unpack200.bytecode.ByteCode.extractOperands(OperandManager, Segment, int) now throws Pack200Exception instead of Error on some bad inputs and states. - Bump org.apache.commons.compress.harmony.unpack200.bytecode.forms.ByteCodeForm.setByteCodeOperands(ByteCode, OperandManager, int) now throws Pack200Exception instead of Error on some bad inputs and states. - Bump org.apache.commons.compress.harmony.unpack200.bytecode.CodeAttribute.CodeAttribute(int, int, byte[], Segment, OperandManager, List) now throws Pack200Exception instead of Error on some bad inputs and states. - Bump org.apache.commons.compress.harmony.unpack200.bytecode.forms.IMethodRefForm.setByteCodeOperands(ByteCode, OperandManager, int) now throws Pack200Exception instead of Error on some bad inputs and states. - Bump org.apache.commons.compress.harmony.unpack200.bytecode.forms.MultiANewArrayForm.setByteCodeOperands(ByteCode, OperandManager, int) now throws Pack200Exception instead of Error on some bad inputs and states. - Bump org.apache.commons.compress.harmony.unpack200.bytecode.forms.NewClassRefForm.setByteCodeOperands(ByteCode, OperandManager, int) now throws Pack200Exception instead of Error on some bad inputs and states. - Bump org.apache.commons.compress.harmony.unpack200.bytecode.forms.ReferenceForm.setByteCodeOperands(ByteCode, OperandManager, int) now throws Pack200Exception instead of Error on some bad inputs and states. --- src/changes/changes.xml | 8 ++++++++ .../harmony/unpack200/SegmentConstantPool.java | 21 +++++++-------------- .../harmony/unpack200/bytecode/ByteCode.java | 6 +++--- .../harmony/unpack200/bytecode/CodeAttribute.java | 3 ++- .../unpack200/bytecode/forms/ByteCodeForm.java | 6 ++++-- .../unpack200/bytecode/forms/IMethodRefForm.java | 3 ++- .../bytecode/forms/MultiANewArrayForm.java | 4 ++-- .../unpack200/bytecode/forms/NewClassRefForm.java | 2 +- .../unpack200/bytecode/forms/ReferenceForm.java | 2 +- .../harmony/unpack200/CodeAttributeTest.java | 9 +++++---- 10 files changed, 35 insertions(+), 29 deletions(-) diff --git a/src/changes/changes.xml b/src/changes/changes.xml index bac61cda0..91690ba0b 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -75,6 +75,14 @@ The <action> type attribute can be add,update,fix,remove. <action type="fix" dev="ggregory" due-to="Gary Gregory">org.apache.commons.compress.harmony.unpack200.SegmentConstantPool.getInitMethodPoolEntry(int, long, String) now throws Pack200Exception instead of Error and does better range checking of the index argument.</action> <action type="fix" dev="ggregory" due-to="Gary Gregory">org.apache.commons.compress.harmony.unpack200.SegmentConstantPool.getInitMethodPoolEntry(int, long, String) now throws Pack200Exception instead of Error on bad constant pool type input.</action> <action type="fix" dev="ggregory" due-to="Gary Gregory">org.apache.commons.compress.harmony.unpack200.SegmentConstantPool.getClassSpecificPoolEntry(int, long, String) now throws Pack200Exception instead of Error on bad constant pool type input.</action> + <action type="fix" dev="ggregory" due-to="Gary Gregory">org.apache.commons.compress.harmony.unpack200.SegmentConstantPool.getClassPoolEntry(String) now throws Pack200Exception instead of Error on some bad inputs and states.</action> + <action type="fix" dev="ggregory" due-to="Gary Gregory">org.apache.commons.compress.harmony.unpack200.bytecode.ByteCode.extractOperands(OperandManager, Segment, int) now throws Pack200Exception instead of Error on some bad inputs and states.</action> + <action type="fix" dev="ggregory" due-to="Gary Gregory">org.apache.commons.compress.harmony.unpack200.bytecode.forms.ByteCodeForm.setByteCodeOperands(ByteCode, OperandManager, int) now throws Pack200Exception instead of Error on some bad inputs and states.</action> + <action type="fix" dev="ggregory" due-to="Gary Gregory">org.apache.commons.compress.harmony.unpack200.bytecode.CodeAttribute.CodeAttribute(int, int, byte[], Segment, OperandManager, List) now throws Pack200Exception instead of Error on some bad inputs and states.</action> + <action type="fix" dev="ggregory" due-to="Gary Gregory">org.apache.commons.compress.harmony.unpack200.bytecode.forms.IMethodRefForm.setByteCodeOperands(ByteCode, OperandManager, int) now throws Pack200Exception instead of Error on some bad inputs and states.</action> + <action type="fix" dev="ggregory" due-to="Gary Gregory">org.apache.commons.compress.harmony.unpack200.bytecode.forms.MultiANewArrayForm.setByteCodeOperands(ByteCode, OperandManager, int) now throws Pack200Exception instead of Error on some bad inputs and states.</action> + <action type="fix" dev="ggregory" due-to="Gary Gregory">org.apache.commons.compress.harmony.unpack200.bytecode.forms.NewClassRefForm.setByteCodeOperands(ByteCode, OperandManager, int) now throws Pack200Exception instead of Error on some bad inputs and states.</action> + <action type="fix" dev="ggregory" due-to="Gary Gregory">org.apache.commons.compress.harmony.unpack200.bytecode.forms.ReferenceForm.setByteCodeOperands(ByteCode, OperandManager, int) now throws Pack200Exception instead of Error on some bad inputs and states.</action> <!-- ADD --> <action type="add" dev="ggregory" due-to="Gary Gregory">Add GzipParameters.getModificationInstant().</action> <action type="add" dev="ggregory" due-to="Gary Gregory">Add GzipParameters.setModificationInstant(Instant).</action> diff --git a/src/main/java/org/apache/commons/compress/harmony/unpack200/SegmentConstantPool.java b/src/main/java/org/apache/commons/compress/harmony/unpack200/SegmentConstantPool.java index c0e85fe92..f72902cfa 100644 --- a/src/main/java/org/apache/commons/compress/harmony/unpack200/SegmentConstantPool.java +++ b/src/main/java/org/apache/commons/compress/harmony/unpack200/SegmentConstantPool.java @@ -166,18 +166,11 @@ public SegmentConstantPool(final CpBands bands) { * * @param name Class name to look for (form: java/lang/Object) * @return CPClass for that class name, or null if not found. + * @throws Pack200Exception if a type is not supported or an index not in the range [0, {@link Integer#MAX_VALUE}]. */ - public ConstantPoolEntry getClassPoolEntry(final String name) { - final String[] classes = bands.getCpClass(); - final int index = matchSpecificPoolEntryIndex(classes, name, 0); - if (index == -1) { - return null; - } - try { - return getConstantPoolEntry(CP_CLASS, index); - } catch (final Pack200Exception ex) { - throw new Error("Error getting class pool entry"); - } + public ConstantPoolEntry getClassPoolEntry(final String name) throws Pack200Exception { + final int index = matchSpecificPoolEntryIndex(bands.getCpClass(), name, 0); + return index == -1 ? null : getConstantPoolEntry(CP_CLASS, index); } /** @@ -188,7 +181,7 @@ public ConstantPoolEntry getClassPoolEntry(final String name) { * @param desiredIndex index of the constant pool. * @param desiredClassName class to use to generate a subset of the pool. * @return ConstantPoolEntry - * @throws Pack200Exception if support for a type is not supported or the index not in the range [0, {@link Integer#MAX_VALUE}]. + * @throws Pack200Exception if a type is not supported or an index not in the range [0, {@link Integer#MAX_VALUE}]. */ public ConstantPoolEntry getClassSpecificPoolEntry(final int cp, final long desiredIndex, final String desiredClassName) throws Pack200Exception { final String[] array; @@ -214,7 +207,7 @@ public ConstantPoolEntry getClassSpecificPoolEntry(final int cp, final long desi * @param type Constant pool type. * @param index Index into a specific constant pool. * @return a constant pool entry. - * @throws Pack200Exception if support for a type is not supported or the index not in the range [0, {@link Integer#MAX_VALUE}]. + * @throws Pack200Exception if a type is not supported or the index not in the range [0, {@link Integer#MAX_VALUE}]. */ public ConstantPoolEntry getConstantPoolEntry(final int type, final long index) throws Pack200Exception { if (index == -1) { @@ -263,7 +256,7 @@ public ConstantPoolEntry getConstantPoolEntry(final int type, final long index) * @param value index of {@code init} method. * @param desiredClassName String class name of the {@code init} method. * @return CPMethod {@code init} method. - * @throws Pack200Exception if support for a type is not supported or the index not in the range [0, {@link Integer#MAX_VALUE}]. + * @throws Pack200Exception if a type is not supported or an index not in the range [0, {@link Integer#MAX_VALUE}]. */ public ConstantPoolEntry getInitMethodPoolEntry(final int cp, final long value, final String desiredClassName) throws Pack200Exception { if (cp != CP_METHOD) { diff --git a/src/main/java/org/apache/commons/compress/harmony/unpack200/bytecode/ByteCode.java b/src/main/java/org/apache/commons/compress/harmony/unpack200/bytecode/ByteCode.java index f0b79efea..0bc8b96b9 100644 --- a/src/main/java/org/apache/commons/compress/harmony/unpack200/bytecode/ByteCode.java +++ b/src/main/java/org/apache/commons/compress/harmony/unpack200/bytecode/ByteCode.java @@ -21,6 +21,7 @@ import java.io.DataOutputStream; import java.io.IOException; +import org.apache.commons.compress.harmony.pack200.Pack200Exception; import org.apache.commons.compress.harmony.unpack200.Segment; import org.apache.commons.compress.harmony.unpack200.bytecode.forms.ByteCodeForm; @@ -83,13 +84,12 @@ public boolean equals(final Object obj) { return this == obj; } - public void extractOperands(final OperandManager operandManager, final Segment segment, final int codeLength) { + public void extractOperands(final OperandManager operandManager, final Segment segment, final int codeLength) throws Pack200Exception { // Given an OperandTable, figure out which operands // the receiver needs and stuff them in operands. // Later on the operands can be rewritten (But that's // later, not now). - final ByteCodeForm currentByteCodeForm = getByteCodeForm(); - currentByteCodeForm.setByteCodeOperands(this, operandManager, codeLength); + getByteCodeForm().setByteCodeOperands(this, operandManager, codeLength); } protected ByteCodeForm getByteCodeForm() { diff --git a/src/main/java/org/apache/commons/compress/harmony/unpack200/bytecode/CodeAttribute.java b/src/main/java/org/apache/commons/compress/harmony/unpack200/bytecode/CodeAttribute.java index e180b3383..2995187b0 100644 --- a/src/main/java/org/apache/commons/compress/harmony/unpack200/bytecode/CodeAttribute.java +++ b/src/main/java/org/apache/commons/compress/harmony/unpack200/bytecode/CodeAttribute.java @@ -23,6 +23,7 @@ import java.util.ArrayList; import java.util.List; +import org.apache.commons.compress.harmony.pack200.Pack200Exception; import org.apache.commons.compress.harmony.unpack200.Segment; public class CodeAttribute extends BCIRenumberedAttribute { @@ -44,7 +45,7 @@ public static void setAttributeName(final CPUTF8 attributeName) { public int maxStack; public CodeAttribute(final int maxStack, final int maxLocals, final byte[] codePacked, final Segment segment, final OperandManager operandManager, - final List<ExceptionTableEntry> exceptionTable) { + final List<ExceptionTableEntry> exceptionTable) throws Pack200Exception { super(attributeName); this.maxLocals = maxLocals; this.maxStack = maxStack; diff --git a/src/main/java/org/apache/commons/compress/harmony/unpack200/bytecode/forms/ByteCodeForm.java b/src/main/java/org/apache/commons/compress/harmony/unpack200/bytecode/forms/ByteCodeForm.java index c78a21cce..26f318faa 100644 --- a/src/main/java/org/apache/commons/compress/harmony/unpack200/bytecode/forms/ByteCodeForm.java +++ b/src/main/java/org/apache/commons/compress/harmony/unpack200/bytecode/forms/ByteCodeForm.java @@ -22,6 +22,7 @@ import java.util.HashMap; import java.util.Map; +import org.apache.commons.compress.harmony.pack200.Pack200Exception; import org.apache.commons.compress.harmony.unpack200.bytecode.ByteCode; import org.apache.commons.compress.harmony.unpack200.bytecode.CodeAttribute; import org.apache.commons.compress.harmony.unpack200.bytecode.OperandManager; @@ -468,14 +469,15 @@ public int operandLength() { } /** - * When passed a byteCode, an OperandTable and a SegmentConstantPool, this method will set the rewrite of the byteCode appropriately. + * Sets the rewrite of the byteCode. * * @param byteCode ByteCode to be updated (!) * @param operandManager OperandTable from which to draw info * @param codeLength Length of bytes (excluding this bytecode) from the beginning of the method. Used in calculating padding for some variable-length * bytecodes (such as lookupswitch, tableswitch). + * @throws Pack200Exception if a type is not supported or an index not in the range [0, {@link Integer#MAX_VALUE}]. */ - public abstract void setByteCodeOperands(ByteCode byteCode, OperandManager operandManager, int codeLength); + public abstract void setByteCodeOperands(ByteCode byteCode, OperandManager operandManager, int codeLength) throws Pack200Exception; @Override public String toString() { diff --git a/src/main/java/org/apache/commons/compress/harmony/unpack200/bytecode/forms/IMethodRefForm.java b/src/main/java/org/apache/commons/compress/harmony/unpack200/bytecode/forms/IMethodRefForm.java index 4e47c4873..754d0ebb0 100644 --- a/src/main/java/org/apache/commons/compress/harmony/unpack200/bytecode/forms/IMethodRefForm.java +++ b/src/main/java/org/apache/commons/compress/harmony/unpack200/bytecode/forms/IMethodRefForm.java @@ -18,6 +18,7 @@ */ package org.apache.commons.compress.harmony.unpack200.bytecode.forms; +import org.apache.commons.compress.harmony.pack200.Pack200Exception; import org.apache.commons.compress.harmony.unpack200.SegmentConstantPool; import org.apache.commons.compress.harmony.unpack200.bytecode.ByteCode; import org.apache.commons.compress.harmony.unpack200.bytecode.CPInterfaceMethodRef; @@ -57,7 +58,7 @@ protected int getPoolID() { * org.apache.commons.compress.harmony.unpack200.Segment) */ @Override - public void setByteCodeOperands(final ByteCode byteCode, final OperandManager operandManager, final int codeLength) { + public void setByteCodeOperands(final ByteCode byteCode, final OperandManager operandManager, final int codeLength) throws Pack200Exception { super.setByteCodeOperands(byteCode, operandManager, codeLength); final int count = ((CPInterfaceMethodRef) byteCode.getNestedClassFileEntries()[0]).invokeInterfaceCount(); byteCode.getRewrite()[3] = count; diff --git a/src/main/java/org/apache/commons/compress/harmony/unpack200/bytecode/forms/MultiANewArrayForm.java b/src/main/java/org/apache/commons/compress/harmony/unpack200/bytecode/forms/MultiANewArrayForm.java index d59a13f1a..014658261 100644 --- a/src/main/java/org/apache/commons/compress/harmony/unpack200/bytecode/forms/MultiANewArrayForm.java +++ b/src/main/java/org/apache/commons/compress/harmony/unpack200/bytecode/forms/MultiANewArrayForm.java @@ -18,6 +18,7 @@ */ package org.apache.commons.compress.harmony.unpack200.bytecode.forms; +import org.apache.commons.compress.harmony.pack200.Pack200Exception; import org.apache.commons.compress.harmony.unpack200.bytecode.ByteCode; import org.apache.commons.compress.harmony.unpack200.bytecode.OperandManager; @@ -47,11 +48,10 @@ public MultiANewArrayForm(final int opcode, final String name, final int[] rewri * org.apache.commons.compress.harmony.unpack200.SegmentConstantPool) */ @Override - public void setByteCodeOperands(final ByteCode byteCode, final OperandManager operandManager, final int codeLength) { + public void setByteCodeOperands(final ByteCode byteCode, final OperandManager operandManager, final int codeLength) throws Pack200Exception { // multianewarray has a class ref and a dimension. // The superclass handles the class ref. super.setByteCodeOperands(byteCode, operandManager, codeLength); - // We have to handle the dimension. final int dimension = operandManager.nextByte(); byteCode.setOperandByte(dimension, 2); diff --git a/src/main/java/org/apache/commons/compress/harmony/unpack200/bytecode/forms/NewClassRefForm.java b/src/main/java/org/apache/commons/compress/harmony/unpack200/bytecode/forms/NewClassRefForm.java index 8e1e4544a..2d0ae5349 100644 --- a/src/main/java/org/apache/commons/compress/harmony/unpack200/bytecode/forms/NewClassRefForm.java +++ b/src/main/java/org/apache/commons/compress/harmony/unpack200/bytecode/forms/NewClassRefForm.java @@ -49,7 +49,7 @@ public NewClassRefForm(final int opcode, final String name, final int[] rewrite) * .compress.harmony.unpack200.bytecode.ByteCode, org.apache.commons.compress.harmony.unpack200.bytecode.OperandManager) */ @Override - public void setByteCodeOperands(final ByteCode byteCode, final OperandManager operandManager, final int codeLength) { + public void setByteCodeOperands(final ByteCode byteCode, final OperandManager operandManager, final int codeLength) throws Pack200Exception { final int offset = getOffset(operandManager); if (offset == 0) { // Use current class diff --git a/src/main/java/org/apache/commons/compress/harmony/unpack200/bytecode/forms/ReferenceForm.java b/src/main/java/org/apache/commons/compress/harmony/unpack200/bytecode/forms/ReferenceForm.java index 7e25eeac8..808b521ae 100644 --- a/src/main/java/org/apache/commons/compress/harmony/unpack200/bytecode/forms/ReferenceForm.java +++ b/src/main/java/org/apache/commons/compress/harmony/unpack200/bytecode/forms/ReferenceForm.java @@ -54,7 +54,7 @@ public ReferenceForm(final int opcode, final String name, final int[] rewrite) { * org.apache.commons.compress.harmony.unpack200.Segment) */ @Override - public void setByteCodeOperands(final ByteCode byteCode, final OperandManager operandManager, final int codeLength) { + public void setByteCodeOperands(final ByteCode byteCode, final OperandManager operandManager, final int codeLength) throws Pack200Exception { final int offset = getOffset(operandManager); try { setNestedEntries(byteCode, operandManager, offset); diff --git a/src/test/java/org/apache/commons/compress/harmony/unpack200/CodeAttributeTest.java b/src/test/java/org/apache/commons/compress/harmony/unpack200/CodeAttributeTest.java index a5819fca4..bfe8e4ccf 100644 --- a/src/test/java/org/apache/commons/compress/harmony/unpack200/CodeAttributeTest.java +++ b/src/test/java/org/apache/commons/compress/harmony/unpack200/CodeAttributeTest.java @@ -23,6 +23,7 @@ import java.util.ArrayList; import java.util.List; +import org.apache.commons.compress.harmony.pack200.Pack200Exception; import org.apache.commons.compress.harmony.unpack200.bytecode.CPFieldRef; import org.apache.commons.compress.harmony.unpack200.bytecode.CPMethodRef; import org.apache.commons.compress.harmony.unpack200.bytecode.CPString; @@ -41,7 +42,7 @@ public class CodeAttributeTest { public class MockCodeAttribute extends CodeAttribute { public MockCodeAttribute(final int maxStack, final int maxLocals, final byte[] codePacked, final Segment segment, final OperandManager operandManager, - final List<ExceptionTableEntry> exceptionTable) { + final List<ExceptionTableEntry> exceptionTable) throws Pack200Exception { super(maxStack, maxLocals, codePacked, segment, operandManager, exceptionTable); } @@ -140,7 +141,7 @@ protected int matchSpecificPoolEntryIndex(final String[] nameArray, final String }; @Test - public void testLength() { + public void testLength() throws Pack200Exception { final OperandManager operandManager = new MockOperandManager(); operandManager.setSegment(segment); operandManager.setCurrentClass("java/lang/Foo"); @@ -158,7 +159,7 @@ public void testLength() { } @Test - public void testMixedByteCodes() { + public void testMixedByteCodes() throws Pack200Exception { final OperandManager operandManager = new MockOperandManager(); operandManager.setSegment(segment); operandManager.setCurrentClass("java/lang/Foo"); @@ -180,7 +181,7 @@ public void testMixedByteCodes() { } @Test - public void testSingleByteCodes() { + public void testSingleByteCodes() throws Pack200Exception { final OperandManager operandManager = new MockOperandManager(); operandManager.setSegment(segment); operandManager.setCurrentClass("java/lang/Foo");