This is an automated email from the ASF dual-hosted git repository.
garydgregory 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 17ce90728 Remove Error rethrow in pack200 ReferenceForm and
NewClassRefForm (#805)
17ce90728 is described below
commit 17ce90728476f64d095f59cacf45c20ef3ade216
Author: KALI 834X <[email protected]>
AuthorDate: Sun Aug 23 01:03:44 2026 +0530
Remove Error rethrow in pack200 ReferenceForm and NewClassRefForm (#805)
---
.../unpack200/bytecode/forms/NewClassRefForm.java | 10 ++----
.../unpack200/bytecode/forms/ReferenceForm.java | 6 +---
.../harmony/unpack200/CodeAttributeTest.java | 38 ++++++++++++++++++++++
3 files changed, 42 insertions(+), 12 deletions(-)
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 ddd57ee9a..29d2fad50 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
@@ -61,13 +61,9 @@ public void setByteCodeOperands(final ByteCode byteCode,
final OperandManager op
byteCode.setNestedPositions(new int[][] { { 0, 2 } });
} else {
// Look up the class in the classpool
- try {
- // Parent takes care of subtracting one from offset
- // to adjust for 1-based global pool
- setNestedEntries(byteCode, operandManager, offset);
- } catch (final Pack200Exception ex) {
- throw new Error("Got a pack200 exception. What to do?");
- }
+ // Parent takes care of subtracting one from offset
+ // to adjust for 1-based global pool
+ setNestedEntries(byteCode, operandManager, offset);
}
operandManager.setNewClass(((CPClass)
byteCode.getNestedClassFileEntries()[0]).getName());
}
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 da164d3ba..0960d04d3 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
@@ -69,11 +69,7 @@ public ReferenceForm(final int opcode, final String name,
final int[] rewrite) {
@Override
public void setByteCodeOperands(final ByteCode byteCode, final
OperandManager operandManager, final int codeLength) throws Pack200Exception {
final int offset = getOffset(operandManager);
- try {
- setNestedEntries(byteCode, operandManager, offset);
- } catch (final Pack200Exception ex) {
- throw new Error("Got a pack200 exception. What to do?");
- }
+ 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 c2714f245..7baecec6e 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
@@ -19,6 +19,7 @@
package org.apache.commons.compress.harmony.unpack200;
import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
import java.util.ArrayList;
import java.util.List;
@@ -140,6 +141,33 @@ protected int matchSpecificPoolEntryIndex(final String[]
nameArray, final String
-49, // return 4
};
+ private OperandManager newOperandManager(final int[] bcClassRef, final
int[] bcIMethodRef) {
+ final OperandManager operandManager = new OperandManager(new int[] {},
// bcCaseCount
+ new int[] {}, // bcCaseValues
+ new int[] {}, // bcByte
+ new int[] {}, // bcShort
+ new int[] {}, // bcLocal
+ new int[] {}, // bcLabel
+ new int[] {}, // bcIntRef
+ new int[] {}, // bcFloatRef
+ new int[] {}, // bcLongRef
+ new int[] {}, // bcDoubleRef
+ new int[] {}, // bcStringRef
+ bcClassRef, // bcClassRef
+ new int[] {}, // bcFieldRef
+ new int[] {}, // bcMethodRef
+ bcIMethodRef, // bcIMethodRef
+ new int[] {}, // bcThisField
+ new int[] {}, // bcSuperField
+ new int[] {}, // bcThisMethod
+ new int[] {}, // bcSuperMethod
+ new int[] {} // bcInitRef
+ , null);
+ operandManager.setSegment(segment);
+ operandManager.setCurrentClass("java/lang/Foo");
+ return operandManager;
+ }
+
@Test
void testLength() throws Pack200Exception {
final OperandManager operandManager = new MockOperandManager();
@@ -180,6 +208,16 @@ void testMixedByteCodes() throws Pack200Exception {
}
}
+ @Test
+ void testNegativeReferenceIndex() {
+ // invokeinterface with a negative bc_imethodref operand
+ assertThrows(Pack200Exception.class, () -> new CodeAttribute(1, 1, new
byte[] { (byte) 185 }, segment, newOperandManager(new int[] {}, new int[] { -2
}),
+ new ArrayList<>()));
+ // new with a negative bc_classref operand
+ assertThrows(Pack200Exception.class, () -> new CodeAttribute(1, 1, new
byte[] { (byte) 187 }, segment, newOperandManager(new int[] { -2 }, new int[]
{}),
+ new ArrayList<>()));
+ }
+
@Test
void testSingleByteCodes() throws Pack200Exception {
final OperandManager operandManager = new MockOperandManager();