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-bcel.git
The following commit(s) were added to refs/heads/master by this push:
new ed34bb8e Internal refactoring
ed34bb8e is described below
commit ed34bb8e82dfacd7873909358e7f5dc0c0003607
Author: Gary Gregory <[email protected]>
AuthorDate: Sat Jan 17 08:50:12 2026 -0500
Internal refactoring
---
.../org/apache/bcel/classfile/ClassParser.java | 18 ++++++++----
.../org/apache/bcel/classfile/ExceptionTable.java | 6 +---
.../java/org/apache/bcel/classfile/Module.java | 33 ++++++++++------------
.../org/apache/bcel/classfile/ModuleExports.java | 15 ++++------
.../org/apache/bcel/classfile/ModuleOpens.java | 15 ++++------
.../org/apache/bcel/classfile/ModulePackages.java | 10 ++-----
.../org/apache/bcel/classfile/ModuleProvides.java | 13 ++++-----
.../org/apache/bcel/classfile/NestMembers.java | 10 ++-----
8 files changed, 52 insertions(+), 68 deletions(-)
diff --git a/src/main/java/org/apache/bcel/classfile/ClassParser.java
b/src/main/java/org/apache/bcel/classfile/ClassParser.java
index 3e1a981c..4cbb23b0 100644
--- a/src/main/java/org/apache/bcel/classfile/ClassParser.java
+++ b/src/main/java/org/apache/bcel/classfile/ClassParser.java
@@ -19,6 +19,7 @@
package org.apache.bcel.classfile;
import java.io.BufferedInputStream;
+import java.io.DataInput;
import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.IOException;
@@ -41,6 +42,16 @@ import org.apache.commons.io.IOUtils;
public final class ClassParser {
private static final int BUFSIZE = 8192;
+
+ static int[] readU2U2Table(final DataInput dataInput) throws IOException {
+ final int count = dataInput.readUnsignedShort();
+ final int[] table = new int[count];
+ for (int i = 0; i < count; i++) {
+ table[i] = dataInput.readUnsignedShort();
+ }
+ return table;
+ }
+
private DataInputStream dataInputStream;
private final boolean fileOwned;
private final String fileName;
@@ -55,6 +66,7 @@ public final class ClassParser {
private Field[] fields; // class fields, that is, its variables
private Method[] methods; // methods defined in the class
private Attribute[] attributes; // attributes defined in the class
+
private final boolean isZip; // Loaded from ZIP file
/**
@@ -248,11 +260,7 @@ public final class ClassParser {
* @throws ClassFormatException if a class is malformed or cannot be
interpreted as a class file
*/
private void readInterfaces() throws IOException, ClassFormatException {
- final int interfacesCount = dataInputStream.readUnsignedShort();
- interfaces = new int[interfacesCount];
- for (int i = 0; i < interfacesCount; i++) {
- interfaces[i] = dataInputStream.readUnsignedShort();
- }
+ interfaces = readU2U2Table(dataInputStream);
}
/**
diff --git a/src/main/java/org/apache/bcel/classfile/ExceptionTable.java
b/src/main/java/org/apache/bcel/classfile/ExceptionTable.java
index 25f9458e..481065ec 100644
--- a/src/main/java/org/apache/bcel/classfile/ExceptionTable.java
+++ b/src/main/java/org/apache/bcel/classfile/ExceptionTable.java
@@ -70,11 +70,7 @@ public final class ExceptionTable extends Attribute {
*/
ExceptionTable(final int nameIndex, final int length, final DataInput
input, final ConstantPool constantPool) throws IOException {
this(nameIndex, length, (int[]) null, constantPool);
- final int exceptionCount = input.readUnsignedShort();
- exceptionIndexTable = new int[exceptionCount];
- for (int i = 0; i < exceptionCount; i++) {
- exceptionIndexTable[i] = input.readUnsignedShort();
- }
+ exceptionIndexTable = ClassParser.readU2U2Table(input);
}
/**
diff --git a/src/main/java/org/apache/bcel/classfile/Module.java
b/src/main/java/org/apache/bcel/classfile/Module.java
index d11dfba7..b3ae79f6 100644
--- a/src/main/java/org/apache/bcel/classfile/Module.java
+++ b/src/main/java/org/apache/bcel/classfile/Module.java
@@ -66,45 +66,42 @@ public final class Module extends Attribute {
*
* @param nameIndex Index in constant pool
* @param length Content length in bytes
- * @param input Input stream
+ * @param dataInput Input stream
* @param constantPool Array of constants
* @throws IOException if an I/O error occurs.
*/
- Module(final int nameIndex, final int length, final DataInput input, final
ConstantPool constantPool) throws IOException {
+ Module(final int nameIndex, final int length, final DataInput dataInput,
final ConstantPool constantPool) throws IOException {
super(Const.ATTR_MODULE, nameIndex, length, constantPool);
- moduleNameIndex = input.readUnsignedShort();
- moduleFlags = input.readUnsignedShort();
- moduleVersionIndex = input.readUnsignedShort();
+ moduleNameIndex = dataInput.readUnsignedShort();
+ moduleFlags = dataInput.readUnsignedShort();
+ moduleVersionIndex = dataInput.readUnsignedShort();
- final int requiresCount = input.readUnsignedShort();
+ final int requiresCount = dataInput.readUnsignedShort();
requiresTable = new ModuleRequires[requiresCount];
for (int i = 0; i < requiresCount; i++) {
- requiresTable[i] = new ModuleRequires(input);
+ requiresTable[i] = new ModuleRequires(dataInput);
}
- final int exportsCount = input.readUnsignedShort();
+ final int exportsCount = dataInput.readUnsignedShort();
exportsTable = new ModuleExports[exportsCount];
for (int i = 0; i < exportsCount; i++) {
- exportsTable[i] = new ModuleExports(input);
+ exportsTable[i] = new ModuleExports(dataInput);
}
- final int opensCount = input.readUnsignedShort();
+ final int opensCount = dataInput.readUnsignedShort();
opensTable = new ModuleOpens[opensCount];
for (int i = 0; i < opensCount; i++) {
- opensTable[i] = new ModuleOpens(input);
+ opensTable[i] = new ModuleOpens(dataInput);
}
- usesCount = input.readUnsignedShort();
- usesIndex = new int[usesCount];
- for (int i = 0; i < usesCount; i++) {
- usesIndex[i] = input.readUnsignedShort();
- }
+ usesIndex = ClassParser.readU2U2Table(dataInput);
+ usesCount = usesIndex.length;
- final int providesCount = input.readUnsignedShort();
+ final int providesCount = dataInput.readUnsignedShort();
providesTable = new ModuleProvides[providesCount];
for (int i = 0; i < providesCount; i++) {
- providesTable[i] = new ModuleProvides(input);
+ providesTable[i] = new ModuleProvides(dataInput);
}
}
diff --git a/src/main/java/org/apache/bcel/classfile/ModuleExports.java
b/src/main/java/org/apache/bcel/classfile/ModuleExports.java
index 9c2ac30f..0e4271af 100644
--- a/src/main/java/org/apache/bcel/classfile/ModuleExports.java
+++ b/src/main/java/org/apache/bcel/classfile/ModuleExports.java
@@ -46,17 +46,14 @@ public final class ModuleExports implements Cloneable, Node
{
/**
* Constructs object from file stream.
*
- * @param file Input stream
+ * @param dataInput Input stream
* @throws IOException if an I/O Exception occurs in readUnsignedShort
*/
- ModuleExports(final DataInput file) throws IOException {
- exportsIndex = file.readUnsignedShort();
- exportsFlags = file.readUnsignedShort();
- exportsToCount = file.readUnsignedShort();
- exportsToIndex = new int[exportsToCount];
- for (int i = 0; i < exportsToCount; i++) {
- exportsToIndex[i] = file.readUnsignedShort();
- }
+ ModuleExports(final DataInput dataInput) throws IOException {
+ exportsIndex = dataInput.readUnsignedShort();
+ exportsFlags = dataInput.readUnsignedShort();
+ exportsToIndex = ClassParser.readU2U2Table(dataInput);
+ exportsToCount = exportsToIndex.length;
}
/**
diff --git a/src/main/java/org/apache/bcel/classfile/ModuleOpens.java
b/src/main/java/org/apache/bcel/classfile/ModuleOpens.java
index ab11d3ba..a9f2eadf 100644
--- a/src/main/java/org/apache/bcel/classfile/ModuleOpens.java
+++ b/src/main/java/org/apache/bcel/classfile/ModuleOpens.java
@@ -46,17 +46,14 @@ public final class ModuleOpens implements Cloneable, Node {
/**
* Constructs object from file stream.
*
- * @param file Input stream
+ * @param dataInput Input stream
* @throws IOException if an I/O Exception occurs in readUnsignedShort
*/
- ModuleOpens(final DataInput file) throws IOException {
- opensIndex = file.readUnsignedShort();
- opensFlags = file.readUnsignedShort();
- opensToCount = file.readUnsignedShort();
- opensToIndex = new int[opensToCount];
- for (int i = 0; i < opensToCount; i++) {
- opensToIndex[i] = file.readUnsignedShort();
- }
+ ModuleOpens(final DataInput dataInput) throws IOException {
+ opensIndex = dataInput.readUnsignedShort();
+ opensFlags = dataInput.readUnsignedShort();
+ opensToIndex = ClassParser.readU2U2Table(dataInput);
+ opensToCount = opensToIndex.length;
}
/**
diff --git a/src/main/java/org/apache/bcel/classfile/ModulePackages.java
b/src/main/java/org/apache/bcel/classfile/ModulePackages.java
index 7159960e..2222ad0c 100644
--- a/src/main/java/org/apache/bcel/classfile/ModulePackages.java
+++ b/src/main/java/org/apache/bcel/classfile/ModulePackages.java
@@ -43,17 +43,13 @@ public final class ModulePackages extends Attribute {
*
* @param nameIndex Index in constant pool
* @param length Content length in bytes
- * @param input Input stream
+ * @param dataInput Input stream
* @param constantPool Array of constants
* @throws IOException if an I/O error occurs.
*/
- ModulePackages(final int nameIndex, final int length, final DataInput
input, final ConstantPool constantPool) throws IOException {
+ ModulePackages(final int nameIndex, final int length, final DataInput
dataInput, final ConstantPool constantPool) throws IOException {
this(nameIndex, length, (int[]) null, constantPool);
- final int packageCount = input.readUnsignedShort();
- packageIndexTable = new int[packageCount];
- for (int i = 0; i < packageCount; i++) {
- packageIndexTable[i] = input.readUnsignedShort();
- }
+ packageIndexTable = ClassParser.readU2U2Table(dataInput);
}
/**
diff --git a/src/main/java/org/apache/bcel/classfile/ModuleProvides.java
b/src/main/java/org/apache/bcel/classfile/ModuleProvides.java
index 6eef0e12..cb77080f 100644
--- a/src/main/java/org/apache/bcel/classfile/ModuleProvides.java
+++ b/src/main/java/org/apache/bcel/classfile/ModuleProvides.java
@@ -49,16 +49,13 @@ public final class ModuleProvides implements Cloneable,
Node {
/**
* Constructs object from file stream.
*
- * @param file Input stream
+ * @param dataInput Input stream
* @throws IOException if an I/O Exception occurs in readUnsignedShort
*/
- ModuleProvides(final DataInput file) throws IOException {
- providesIndex = file.readUnsignedShort();
- providesWithCount = file.readUnsignedShort();
- providesWithIndex = new int[providesWithCount];
- for (int i = 0; i < providesWithCount; i++) {
- providesWithIndex[i] = file.readUnsignedShort();
- }
+ ModuleProvides(final DataInput dataInput) throws IOException {
+ providesIndex = dataInput.readUnsignedShort();
+ providesWithIndex = ClassParser.readU2U2Table(dataInput);
+ providesWithCount = providesWithIndex.length;
}
/**
diff --git a/src/main/java/org/apache/bcel/classfile/NestMembers.java
b/src/main/java/org/apache/bcel/classfile/NestMembers.java
index 35525cb2..249a8cbe 100644
--- a/src/main/java/org/apache/bcel/classfile/NestMembers.java
+++ b/src/main/java/org/apache/bcel/classfile/NestMembers.java
@@ -44,17 +44,13 @@ public final class NestMembers extends Attribute {
*
* @param nameIndex Index in constant pool
* @param length Content length in bytes
- * @param input Input stream
+ * @param dataInput Input stream
* @param constantPool Array of constants
* @throws IOException if an I/O error occurs.
*/
- NestMembers(final int nameIndex, final int length, final DataInput input,
final ConstantPool constantPool) throws IOException {
+ NestMembers(final int nameIndex, final int length, final DataInput
dataInput, final ConstantPool constantPool) throws IOException {
this(nameIndex, length, (int[]) null, constantPool);
- final int classCount = input.readUnsignedShort();
- classes = new int[classCount];
- for (int i = 0; i < classCount; i++) {
- classes[i] = input.readUnsignedShort();
- }
+ classes = ClassParser.readU2U2Table(dataInput);
}
/**