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 d85b3d19 ClassDumper.dump() should not call the input stream it didn't
open; fixes IOException when calling DumpClass.main(ClassDumper.java:351).
d85b3d19 is described below
commit d85b3d19bbdf11893d3b1d8984202e321c11e08e
Author: Gary Gregory <[email protected]>
AuthorDate: Mon Jan 12 17:13:19 2026 -0500
ClassDumper.dump() should not call the input stream it didn't open;
fixes IOException when calling DumpClass.main(ClassDumper.java:351).
For example:
Exception in thread "main" java.io.IOException: closed
at
javax.imageio.stream.ImageInputStreamImpl.checkClosed(ImageInputStreamImpl.java:110)
at
javax.imageio.stream.ImageInputStreamImpl.close(ImageInputStreamImpl.java:857)
at
javax.imageio.stream.FileImageInputStream.close(FileImageInputStream.java:151)
at DumpClass.main(ClassDumper.java:351)
---
src/changes/changes.xml | 1 +
src/examples/ClassDumper.java | 51 +++++++++++++++----------------------------
2 files changed, 18 insertions(+), 34 deletions(-)
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 38f549f3..012930ef 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -73,6 +73,7 @@ The <action> type attribute can be add,update,fix,remove.
<action type="fix" dev="ggregory" due-to="Gary Gregory,
Stanislav Fort">Code.Code(int, int, DataInput, ConstantPool) now throws a
ClassFormatException if the code array is greater than the JVM specification
allows.</action>
<action type="fix" dev="ggregory" due-to="Gary Gregory,
Stanislav Fort">Code.Code(int, int, int, int, byte[], CodeException[],
Attribute[], ConstantPool) now throws a ClassFormatException if the code array
is greater than the JVM specification allows.</action>
<action type="fix" dev="ggregory" due-to="Gary
Gregory">Code.setCode(byte[]) now throws a ClassFormatException if the code
array is greater than the JVM specification allows.</action>
+ <action type="fix" dev="ggregory" due-to="Gary
Gregory">ClassDumper.dump() should not call the input stream it didn't open;
fixes IOException when calling DumpClass.main(ClassDumper.java:351).</action>
<!-- ADD -->
<action type="add" dev="ggregory" due-to="Gary
Gregory">Add Const.MAJOR_26.</action>
<action type="add" dev="ggregory" due-to="Gary
Gregory">Add Const.MINOR_26.</action>
diff --git a/src/examples/ClassDumper.java b/src/examples/ClassDumper.java
index e5bc82fb..194fcc8a 100644
--- a/src/examples/ClassDumper.java
+++ b/src/examples/ClassDumper.java
@@ -72,33 +72,22 @@ final class ClassDumper {
* @throws ClassFormatException
*/
public void dump() throws IOException, ClassFormatException {
- try {
- // Check magic tag of class file
- processID();
- // Get compiler version
- processVersion();
- // process constant pool entries
- processConstantPool();
- // Get class information
- processClassInfo();
- // Get interface information, that is, implemented interfaces
- processInterfaces();
- // process class fields, that is, the variables of the class
- processFields();
- // process class methods, that is, the functions in the class
- processMethods();
- // process class attributes
- processAttributes();
- } finally {
- // Processed everything of interest, so close the file
- try {
- if (file != null) {
- file.close();
- }
- } catch (final IOException ioe) {
- // ignore close exceptions
- }
- }
+ // Check magic tag of class file
+ processID();
+ // Get compiler version
+ processVersion();
+ // process constant pool entries
+ processConstantPool();
+ // Get class information
+ processClassInfo();
+ // Get interface information, that is, implemented interfaces
+ processInterfaces();
+ // process class fields, that is, the variables of the class
+ processFields();
+ // process class methods, that is, the functions in the class
+ processMethods();
+ // process class attributes
+ processAttributes();
}
/**
@@ -343,18 +332,12 @@ final class ClassDumper {
final class DumpClass {
public static void main(final String[] args) throws IOException {
-
if (args.length != 1) {
throw new IllegalArgumentException("Require file name as only
argument");
}
-
try (FileImageInputStream file = new FileImageInputStream(new
File(args[0]))) {
-
- final ClassDumper cd = new ClassDumper(file, args[0]);
- cd.dump();
+ new ClassDumper(file, args[0]).dump();
}
-
System.out.printf("End of Class Dump%n");
-
}
}