diff --git a/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/Const.java b/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/Const.java
index bca72ab3f95..c6b97db142e 100644
--- a/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/Const.java
+++ b/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/Const.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2017, 2023, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2017, 2025, Oracle and/or its affiliates. All rights reserved.
*/
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
@@ -26,12 +26,12 @@ import java.util.Collections;
* Constants for the project, mostly defined in the JVM specification.
*
* @since 6.0 (intended to replace the Constants interface)
- * @LastModified: Feb 2023
+ * @LastModified: Sept 2025
*/
public final class Const {
/**
- * Java class file format Magic number (0xCAFEBABE)
+ * Java class file format Magic number: {@value}.
*
* @see The ClassFile Structure
* in The Java Virtual Machine Specification
@@ -39,201 +39,201 @@ public final class Const {
public static final int JVM_CLASSFILE_MAGIC = 0xCAFEBABE;
/**
- * Major version number of class files for Java 1.1.
+ * Major version number of class files for Java 1.1: {@value}.
*
* @see #MINOR_1_1
*/
public static final short MAJOR_1_1 = 45;
/**
- * Minor version number of class files for Java 1.1.
+ * Minor version number of class files for Java 1.1: {@value}.
*
* @see #MAJOR_1_1
*/
public static final short MINOR_1_1 = 3;
/**
- * Major version number of class files for Java 1.2.
+ * Major version number of class files for Java 1.2: {@value}.
*
* @see #MINOR_1_2
*/
public static final short MAJOR_1_2 = 46;
/**
- * Minor version number of class files for Java 1.2.
+ * Minor version number of class files for Java 1.2: {@value}.
*
* @see #MAJOR_1_2
*/
public static final short MINOR_1_2 = 0;
/**
- * Major version number of class files for Java 1.2.
+ * Major version number of class files for Java 1.2: {@value}.
*
* @see #MINOR_1_2
*/
public static final short MAJOR_1_3 = 47;
/**
- * Minor version number of class files for Java 1.3.
+ * Minor version number of class files for Java 1.3: {@value}.
*
* @see #MAJOR_1_3
*/
public static final short MINOR_1_3 = 0;
/**
- * Major version number of class files for Java 1.3.
+ * Major version number of class files for Java 1.3: {@value}.
*
* @see #MINOR_1_3
*/
public static final short MAJOR_1_4 = 48;
/**
- * Minor version number of class files for Java 1.4.
+ * Minor version number of class files for Java 1.4: {@value}.
*
* @see #MAJOR_1_4
*/
public static final short MINOR_1_4 = 0;
/**
- * Major version number of class files for Java 1.4.
+ * Major version number of class files for Java 1.4: {@value}.
*
* @see #MINOR_1_4
*/
public static final short MAJOR_1_5 = 49;
/**
- * Minor version number of class files for Java 1.5.
+ * Minor version number of class files for Java 1.5: {@value}.
*
* @see #MAJOR_1_5
*/
public static final short MINOR_1_5 = 0;
/**
- * Major version number of class files for Java 1.6.
+ * Major version number of class files for Java 1.6: {@value}.
*
* @see #MINOR_1_6
*/
public static final short MAJOR_1_6 = 50;
/**
- * Minor version number of class files for Java 1.6.
+ * Minor version number of class files for Java 1.6: {@value}.
*
* @see #MAJOR_1_6
*/
public static final short MINOR_1_6 = 0;
/**
- * Major version number of class files for Java 1.7.
+ * Major version number of class files for Java 1.7: {@value}.
*
* @see #MINOR_1_7
*/
public static final short MAJOR_1_7 = 51;
/**
- * Minor version number of class files for Java 1.7.
+ * Minor version number of class files for Java 1.7: {@value}.
*
* @see #MAJOR_1_7
*/
public static final short MINOR_1_7 = 0;
/**
- * Major version number of class files for Java 1.8.
+ * Major version number of class files for Java 1.8: {@value}.
*
* @see #MINOR_1_8
*/
public static final short MAJOR_1_8 = 52;
/**
- * Minor version number of class files for Java 1.8.
+ * Minor version number of class files for Java 1.8: {@value}.
*
* @see #MAJOR_1_8
*/
public static final short MINOR_1_8 = 0;
/**
- * Major version number of class files for Java 9.
+ * Major version number of class files for Java 9: {@value}.
*
* @see #MINOR_9
*/
public static final short MAJOR_9 = 53;
/**
- * Minor version number of class files for Java 9.
+ * Minor version number of class files for Java 9: {@value}.
*
* @see #MAJOR_9
*/
public static final short MINOR_9 = 0;
/**
- * @deprecated Use {@link #MAJOR_9} instead
+ * @deprecated Use {@link #MAJOR_9} ({@value}) instead.
*/
@Deprecated
public static final short MAJOR_1_9 = MAJOR_9;
/**
- * @deprecated Use {@link #MINOR_9} instead
+ * @deprecated Use {@link #MINOR_9} ({@value}) instead.
*/
@Deprecated
public static final short MINOR_1_9 = MINOR_9;
/**
- * Major version number of class files for Java 10.
+ * Major version number of class files for Java 10: {@value}.
*
* @see #MINOR_10
*/
public static final short MAJOR_10 = 54;
/**
- * Minor version number of class files for Java 10.
+ * Minor version number of class files for Java 10: {@value}.
*
* @see #MAJOR_10
*/
public static final short MINOR_10 = 0;
/**
- * Major version number of class files for Java 11.
+ * Major version number of class files for Java 11: {@value}.
*
* @see #MINOR_11
*/
public static final short MAJOR_11 = 55;
/**
- * Minor version number of class files for Java 11.
+ * Minor version number of class files for Java 11: {@value}.
*
* @see #MAJOR_11
*/
public static final short MINOR_11 = 0;
/**
- * Major version number of class files for Java 12.
+ * Major version number of class files for Java 12: {@value}.
*
* @see #MINOR_12
*/
public static final short MAJOR_12 = 56;
/**
- * Minor version number of class files for Java 12.
+ * Minor version number of class files for Java 12: {@value}.
*
* @see #MAJOR_12
*/
public static final short MINOR_12 = 0;
/**
- * Major version number of class files for Java 13.
+ * Major version number of class files for Java 13: {@value}.
*
* @see #MINOR_13
*/
public static final short MAJOR_13 = 57;
/**
- * Minor version number of class files for Java 13.
+ * Minor version number of class files for Java 13: {@value}.
*
* @see #MAJOR_13
*/
public static final short MINOR_13 = 0;
/**
- * Minor version number of class files for Java 14.
+ * Minor version number of class files for Java 14: {@value}.
*
* @see #MAJOR_14
* @since 6.4.0
@@ -241,7 +241,7 @@ public final class Const {
public static final short MINOR_14 = 0;
/**
- * Minor version number of class files for Java 15.
+ * Minor version number of class files for Java 15: {@value}.
*
* @see #MAJOR_15
* @since 6.6.0
@@ -249,7 +249,7 @@ public final class Const {
public static final short MINOR_15 = 0;
/**
- * Minor version number of class files for Java 16.
+ * Minor version number of class files for Java 16: {@value}.
*
* @see #MAJOR_16
* @since 6.6.0
@@ -257,7 +257,7 @@ public final class Const {
public static final short MINOR_16 = 0;
/**
- * Minor version number of class files for Java 17.
+ * Minor version number of class files for Java 17: {@value}.
*
* @see #MAJOR_17
* @since 6.6.0
@@ -265,7 +265,7 @@ public final class Const {
public static final short MINOR_17 = 0;
/**
- * Minor version number of class files for Java 18.
+ * Minor version number of class files for Java 18: {@value}.
*
* @see #MAJOR_18
* @since 6.6.0
@@ -273,7 +273,7 @@ public final class Const {
public static final short MINOR_18 = 0;
/**
- * Minor version number of class files for Java 19.
+ * Minor version number of class files for Java 19: {@value}.
*
* @see #MAJOR_19
* @since 6.6.0
@@ -281,7 +281,47 @@ public final class Const {
public static final short MINOR_19 = 0;
/**
- * Major version number of class files for Java 14.
+ * Minor version number of class files for Java 20: {@value}.
+ *
+ * @see #MAJOR_20
+ * @since 6.8.0
+ */
+ public static final short MINOR_20 = 0;
+
+ /**
+ * Minor version number of class files for Java 21: {@value}.
+ *
+ * @see #MAJOR_21
+ * @since 6.8.0
+ */
+ public static final short MINOR_21 = 0;
+
+ /**
+ * Minor version number of class files for Java 22: {@value}.
+ *
+ * @see #MAJOR_22
+ * @since 6.10.0
+ */
+ public static final short MINOR_22 = 0;
+
+ /**
+ * Minor version number of class files for Java 23: {@value}.
+ *
+ * @see #MAJOR_23
+ * @since 6.10.0
+ */
+ public static final short MINOR_23 = 0;
+
+ /**
+ * Minor version number of class files for Java 24: {@value}.
+ *
+ * @see #MAJOR_24
+ * @since 6.10.0
+ */
+ public static final short MINOR_24 = 0;
+
+ /**
+ * Major version number of class files for Java 14: {@value}.
*
* @see #MINOR_14
* @since 6.4.0
@@ -289,7 +329,7 @@ public final class Const {
public static final short MAJOR_14 = 58;
/**
- * Major version number of class files for Java 15.
+ * Major version number of class files for Java 15: {@value}.
*
* @see #MINOR_15
* @since 6.6.0
@@ -297,7 +337,7 @@ public final class Const {
public static final short MAJOR_15 = 59;
/**
- * Major version number of class files for Java 16.
+ * Major version number of class files for Java 16: {@value}.
*
* @see #MINOR_16
* @since 6.6.0
@@ -305,7 +345,7 @@ public final class Const {
public static final short MAJOR_16 = 60;
/**
- * Major version number of class files for Java 17.
+ * Major version number of class files for Java 17: {@value}.
*
* @see #MINOR_17
* @since 6.6.0
@@ -313,7 +353,7 @@ public final class Const {
public static final short MAJOR_17 = 61;
/**
- * Major version number of class files for Java 18.
+ * Major version number of class files for Java 18: {@value}.
*
* @see #MINOR_18
* @since 6.6.0
@@ -321,7 +361,7 @@ public final class Const {
public static final short MAJOR_18 = 62;
/**
- * Major version number of class files for Java 19.
+ * Major version number of class files for Java 19: {@value}.
*
* @see #MINOR_19
* @since 6.6.0
@@ -329,31 +369,71 @@ public final class Const {
public static final short MAJOR_19 = 63;
/**
- * Default major version number. Class file is for Java 1.1.
+ * Major version number of class files for Java 20: {@value}.
+ *
+ * @see #MINOR_20
+ * @since 6.8.0
+ */
+ public static final short MAJOR_20 = 64;
+
+ /**
+ * Major version number of class files for Java 21: {@value}.
+ *
+ * @see #MINOR_21
+ * @since 6.8.0
+ */
+ public static final short MAJOR_21 = 65;
+
+ /**
+ * Major version number of class files for Java 22: {@value}.
+ *
+ * @see #MINOR_22
+ * @since 6.10.0
+ */
+ public static final short MAJOR_22 = 66;
+
+ /**
+ * Major version number of class files for Java 23: {@value}.
+ *
+ * @see #MINOR_23
+ * @since 6.10.0
+ */
+ public static final short MAJOR_23 = 67;
+
+ /**
+ * Major version number of class files for Java 24: {@value}.
+ *
+ * @see #MINOR_24
+ * @since 6.10.0
+ */
+ public static final short MAJOR_24 = 68;
+
+ /**
+ * Default major version number. Class file is for Java 1.1: {@value}.
*
* @see #MAJOR_1_1
*/
public static final short MAJOR = MAJOR_1_1;
/**
- * Default major version number. Class file is for Java 1.1.
+ * Default major version number. Class file is for Java 1.1: {@value}.
*
* @see #MAJOR_1_1
*/
public static final short MINOR = MINOR_1_1;
/**
- * Maximum value for an unsigned short.
+ * Maximum value for an unsigned short: {@value}.
*/
public static final int MAX_SHORT = 65535; // 2^16 - 1
/**
- * Maximum value for an unsigned byte.
+ * Maximum value for an unsigned byte: {@value}.
*/
public static final int MAX_BYTE = 255; // 2^8 - 1
/**
- * One of the access flags for fields, methods, or classes.
+ * One of the access flags for fields, methods, or classes: {@value}.
*
* @see Flag definitions for
* Classes in the Java Virtual Machine Specification (Java SE 9 Edition).
@@ -367,140 +447,140 @@ public final class Const {
public static final short ACC_PUBLIC = 0x0001;
/**
- * One of the access flags for fields, methods, or classes.
+ * One of the access flags for fields, methods, or classes: {@value}.
*
* @see #ACC_PUBLIC
*/
public static final short ACC_PRIVATE = 0x0002;
/**
- * One of the access flags for fields, methods, or classes.
+ * One of the access flags for fields, methods, or classes: {@value}.
*
* @see #ACC_PUBLIC
*/
public static final short ACC_PROTECTED = 0x0004;
/**
- * One of the access flags for fields, methods, or classes.
+ * One of the access flags for fields, methods, or classes: {@value}.
*
* @see #ACC_PUBLIC
*/
public static final short ACC_STATIC = 0x0008;
/**
- * One of the access flags for fields, methods, or classes.
+ * One of the access flags for fields, methods, or classes: {@value}.
*
* @see #ACC_PUBLIC
*/
public static final short ACC_FINAL = 0x0010;
/**
- * One of the access flags for the Module attribute.
+ * One of the access flags for the Module attribute: {@value}.
*
* @see #ACC_PUBLIC
*/
public static final short ACC_OPEN = 0x0020;
/**
- * One of the access flags for classes.
+ * One of the access flags for classes: {@value}.
*
* @see #ACC_PUBLIC
*/
public static final short ACC_SUPER = 0x0020;
/**
- * One of the access flags for methods.
+ * One of the access flags for methods: {@value}.
*
* @see #ACC_PUBLIC
*/
public static final short ACC_SYNCHRONIZED = 0x0020;
/**
- * One of the access flags for the Module attribute.
+ * One of the access flags for the Module attribute: {@value}.
*
* @see #ACC_PUBLIC
*/
public static final short ACC_TRANSITIVE = 0x0020;
/**
- * One of the access flags for methods.
+ * One of the access flags for methods: {@value}.
*
* @see #ACC_PUBLIC
*/
public static final short ACC_BRIDGE = 0x0040;
/**
- * One of the access flags for the Module attribute.
+ * One of the access flags for the Module attribute: {@value}.
*
* @see #ACC_PUBLIC
*/
public static final short ACC_STATIC_PHASE = 0x0040;
/**
- * One of the access flags for fields.
+ * One of the access flags for fields: {@value}.
*
* @see #ACC_PUBLIC
*/
public static final short ACC_VOLATILE = 0x0040;
/**
- * One of the access flags for fields.
+ * One of the access flags for fields: {@value}.
*
* @see #ACC_PUBLIC
*/
public static final short ACC_TRANSIENT = 0x0080;
/**
- * One of the access flags for methods.
+ * One of the access flags for methods: {@value}.
*
* @see #ACC_PUBLIC
*/
public static final short ACC_VARARGS = 0x0080;
/**
- * One of the access flags for methods.
+ * One of the access flags for methods: {@value}.
*
* @see #ACC_PUBLIC
*/
public static final short ACC_NATIVE = 0x0100;
/**
- * One of the access flags for classes.
+ * One of the access flags for classes: {@value}.
*
* @see #ACC_PUBLIC
*/
public static final short ACC_INTERFACE = 0x0200;
/**
- * One of the access flags for methods or classes.
+ * One of the access flags for methods or classes: {@value}.
*
* @see #ACC_PUBLIC
*/
public static final short ACC_ABSTRACT = 0x0400;
/**
- * One of the access flags for methods.
+ * One of the access flags for methods: {@value}.
*
* @see #ACC_PUBLIC
*/
public static final short ACC_STRICT = 0x0800;
/**
- * One of the access flags for fields, methods, classes, MethodParameter attribute, or Module attribute.
+ * One of the access flags for fields, methods, classes, MethodParameter attribute, or Module attribute: {@value}.
*
* @see #ACC_PUBLIC
*/
public static final short ACC_SYNTHETIC = 0x1000;
/**
- * One of the access flags for classes.
+ * One of the access flags for classes: {@value}.
*
* @see #ACC_PUBLIC
*/
public static final short ACC_ANNOTATION = 0x2000;
/**
- * One of the access flags for fields or classes.
+ * One of the access flags for fields or classes: {@value}.
*
* @see #ACC_PUBLIC
*/
@@ -508,21 +588,21 @@ public final class Const {
// Applies to classes compiled by new compilers only
/**
- * One of the access flags for MethodParameter or Module attributes.
+ * One of the access flags for MethodParameter or Module attributes: {@value}.
*
* @see #ACC_PUBLIC
*/
public static final short ACC_MANDATED = (short) 0x8000;
/**
- * One of the access flags for classes.
+ * One of the access flags for classes: {@value}.
*
* @see #ACC_PUBLIC
*/
public static final short ACC_MODULE = (short) 0x8000;
/**
- * One of the access flags for fields, methods, or classes.
+ * One of the access flags for fields, methods, or classes: {@value}.
*
* @see #ACC_PUBLIC
* @deprecated Use {@link #MAX_ACC_FLAG_I}
@@ -531,7 +611,7 @@ public final class Const {
public static final short MAX_ACC_FLAG = ACC_ENUM;
/**
- * One of the access flags for fields, methods, or classes. ACC_MODULE is negative as a short.
+ * One of the access flags for fields, methods, or classes. ACC_MODULE is negative as a short: {@value}.
*
* @see #ACC_PUBLIC
* @since 6.4.0
@@ -553,7 +633,7 @@ public final class Const {
public static final int ACCESS_NAMES_LENGTH = ACCESS_NAMES.length;
/**
- * Marks a constant pool entry as type UTF-8.
+ * Marks a constant pool entry as type UTF-8: {@value}.
*
* @see The Constant Pool in The
* Java Virtual Machine Specification
@@ -566,7 +646,7 @@ public final class Const {
*/
/**
- * Marks a constant pool entry as type Integer.
+ * Marks a constant pool entry as type Integer: {@value}.
*
* @see The Constant Pool in The
* Java Virtual Machine Specification
@@ -574,7 +654,7 @@ public final class Const {
public static final byte CONSTANT_Integer = 3;
/**
- * Marks a constant pool entry as type Float.
+ * Marks a constant pool entry as type Float: {@value}.
*
* @see The Constant Pool in The
* Java Virtual Machine Specification
@@ -582,7 +662,7 @@ public final class Const {
public static final byte CONSTANT_Float = 4;
/**
- * Marks a constant pool entry as type Long.
+ * Marks a constant pool entry as type Long: {@value}.
*
* @see The Constant Pool in The
* Java Virtual Machine Specification
@@ -590,7 +670,7 @@ public final class Const {
public static final byte CONSTANT_Long = 5;
/**
- * Marks a constant pool entry as type Double.
+ * Marks a constant pool entry as type Double: {@value}.
*
* @see The Constant Pool in The
* Java Virtual Machine Specification
@@ -598,7 +678,7 @@ public final class Const {
public static final byte CONSTANT_Double = 6;
/**
- * Marks a constant pool entry as a Class
+ * Marks a constant pool entry as a Class: {@value}.
*
* @see The Constant Pool in The
* Java Virtual Machine Specification
@@ -606,7 +686,7 @@ public final class Const {
public static final byte CONSTANT_Class = 7;
/**
- * Marks a constant pool entry as a Field Reference.
+ * Marks a constant pool entry as a Field Reference: {@value}.
*
* @see The Constant Pool in The
* Java Virtual Machine Specification
@@ -614,7 +694,7 @@ public final class Const {
public static final byte CONSTANT_Fieldref = 9;
/**
- * Marks a constant pool entry as type String
+ * Marks a constant pool entry as type String: {@value}.
*
* @see The Constant Pool in The
* Java Virtual Machine Specification
@@ -622,7 +702,7 @@ public final class Const {
public static final byte CONSTANT_String = 8;
/**
- * Marks a constant pool entry as a Method Reference.
+ * Marks a constant pool entry as a Method Reference: {@value}.
*
* @see The Constant Pool in The
* Java Virtual Machine Specification
@@ -630,7 +710,7 @@ public final class Const {
public static final byte CONSTANT_Methodref = 10;
/**
- * Marks a constant pool entry as an Interface Method Reference.
+ * Marks a constant pool entry as an Interface Method Reference: {@value}.
*
* @see The Constant Pool in The
* Java Virtual Machine Specification
@@ -638,7 +718,7 @@ public final class Const {
public static final byte CONSTANT_InterfaceMethodref = 11;
/**
- * Marks a constant pool entry as a name and type.
+ * Marks a constant pool entry as a name and type: {@value}.
*
* @see The Constant Pool in The
* Java Virtual Machine Specification
@@ -646,7 +726,7 @@ public final class Const {
public static final byte CONSTANT_NameAndType = 12;
/**
- * Marks a constant pool entry as a Method Handle.
+ * Marks a constant pool entry as a Method Handle: {@value}.
*
* @see The Constant Pool in The
* Java Virtual Machine Specification
@@ -654,7 +734,7 @@ public final class Const {
public static final byte CONSTANT_MethodHandle = 15;
/**
- * Marks a constant pool entry as a Method Type.
+ * Marks a constant pool entry as a Method Type: {@value}.
*
* @see The Constant Pool in The
* Java Virtual Machine Specification
@@ -662,16 +742,16 @@ public final class Const {
public static final byte CONSTANT_MethodType = 16;
/**
- * Marks a constant pool entry as dynamically computed.
+ * Marks a constant pool entry as dynamically computed: {@value}.
*
- * @see Change request for JEP
- * 309
+ * @see The Constant Pool in The
+ * Java Virtual Machine Specification
* @since 6.3
*/
public static final byte CONSTANT_Dynamic = 17;
/**
- * Marks a constant pool entry as an Invoke Dynamic
+ * Marks a constant pool entry as an Invoke Dynamic: {@value}.
*
* @see The Constant Pool in The
* Java Virtual Machine Specification
@@ -679,7 +759,7 @@ public final class Const {
public static final byte CONSTANT_InvokeDynamic = 18;
/**
- * Marks a constant pool entry as a Module Reference.
+ * Marks a constant pool entry as a Module Reference: {@value}.
*
* @see The Constant Pool in The
* Java Virtual Machine Specification
@@ -688,7 +768,7 @@ public final class Const {
public static final byte CONSTANT_Module = 19;
/**
- * Marks a constant pool entry as a Package Reference.
+ * Marks a constant pool entry as a Package Reference: {@value}.
*
* @see The Constant Pool in The
* Java Virtual Machine Specification
@@ -705,23 +785,23 @@ public final class Const {
/**
* The name of the static initializer, also called "class initialization method" or "interface
- * initialization method". This is "<clinit>".
+ * initialization method". This is {@value}.
*/
public static final String STATIC_INITIALIZER_NAME = "
+ * One of the limitations of the Java Virtual Machine. Note vmspec2 page 152 ("Limitations") says:
+ *
+ * The entry in the Limitations section has been removed from later versions of the specification; it is not present in the Java SE 8 edition.
+ * "The amount of code per non-native, non-abstract method is limited to 65536 bytes by the sizes of the indices in the exception_table of the Code
+ * attribute (4.7.3), in the LineNumberTable attribute (4.7.8), and in the LocalVariableTable attribute (4.7.9)." However this should be taken as an
+ * upper limit rather than the defined maximum. On page 134 (4.8.1 Static Constants) of the same spec, it says: "The value of the code_length item must be
+ * less than 65536."
+ *
* Here is a sample Maven invocation with caching disabled: @@ -58,11 +58,11 @@ import com.sun.org.apache.bcel.internal.Const; * * * @see Constant - * @LastModified: Feb 2023 + * @LastModified: Sept 2025 */ public final class ConstantUtf8 extends Constant { - private static class Cache { + private static final class Cache { private static final boolean BCEL_STATISTICS = false; private static final int MAX_ENTRIES = 20000; @@ -82,7 +82,7 @@ public final class ConstantUtf8 extends Constant { private static final int MAX_ENTRY_SIZE = 200; static boolean isEnabled() { - return Cache.MAX_ENTRIES > 0 && MAX_ENTRY_SIZE > 0; + return MAX_ENTRIES > 0 && MAX_ENTRY_SIZE > 0; } } @@ -117,6 +117,11 @@ public final class ConstantUtf8 extends Constant { hits = considered = skipped = created = 0; } + // Avoid Spotbugs complaint about Write to static field + private static void countCreated() { + created++; + } + /** * Gets a new or cached instance of the given value. *
@@ -203,7 +208,7 @@ public final class ConstantUtf8 extends Constant {
ConstantUtf8(final DataInput dataInput) throws IOException {
super(Const.CONSTANT_Utf8);
value = dataInput.readUTF();
- created++;
+ countCreated();
}
/**
@@ -212,7 +217,7 @@ public final class ConstantUtf8 extends Constant {
public ConstantUtf8(final String value) {
super(Const.CONSTANT_Utf8);
this.value = Objects.requireNonNull(value, "value");
- created++;
+ countCreated();
}
/**
diff --git a/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/classfile/ConstantValue.java b/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/classfile/ConstantValue.java
index 311e9a33fa3..143c2a25544 100644
--- a/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/classfile/ConstantValue.java
+++ b/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/classfile/ConstantValue.java
@@ -56,7 +56,7 @@ public final class ConstantValue extends Attribute {
}
/**
- * Construct object from input stream.
+ * Constructs object from input stream.
*
* @param nameIndex Name index in constant pool
* @param length Content length in bytes
diff --git a/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/classfile/Deprecated.java b/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/classfile/Deprecated.java
index 90841d96081..c561afe33c5 100644
--- a/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/classfile/Deprecated.java
+++ b/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/classfile/Deprecated.java
@@ -59,7 +59,7 @@ public final class Deprecated extends Attribute {
}
/**
- * Construct object from input stream.
+ * Constructs object from input stream.
*
* @param nameIndex Index in constant pool to CONSTANT_Utf8
* @param length Content length in bytes
diff --git a/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/classfile/DescendingVisitor.java b/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/classfile/DescendingVisitor.java
index 3c475891acd..934b608d6ac 100644
--- a/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/classfile/DescendingVisitor.java
+++ b/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/classfile/DescendingVisitor.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2013, 2017, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013, 2025, Oracle and/or its affiliates. All rights reserved.
*/
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
@@ -22,12 +22,13 @@ package com.sun.org.apache.bcel.internal.classfile;
import java.util.Objects;
import java.util.Stack;
import java.util.stream.Stream;
+import jdk.xml.internal.Utils;
/**
- * Traverses a JavaClass with another Visitor object 'piggy-backed' that is
- * applied to all components of a JavaClass object. I.e. this class supplies the
- * traversal strategy, other classes can make use of it.
+ * Traverses a JavaClass with another Visitor object 'piggy-backed' that is applied to all components of a JavaClass
+ * object. I.e. this class supplies the traversal strategy, other classes can make use of it.
*
+ * @LastModified: Sept 2025
*/
public class DescendingVisitor implements Visitor {
private final JavaClass clazz;
@@ -46,7 +47,7 @@ public class DescendingVisitor implements Visitor {
}
private
+ * Implements {@link Node} as of 6.7.0. + *
* * @see The class File Format : * The MethodParameters Attribute @@ -46,7 +49,7 @@ public class MethodParameter implements Cloneable, Node { } /** - * Construct object from input stream. + * Constructs an instance from a DataInput. * * @param input Input stream * @throws IOException if an I/O error occurs. @@ -75,7 +78,7 @@ public class MethodParameter implements Cloneable, Node { } /** - * Dump object to file stream on binary format. + * Dumps object to file stream on binary format. * * @param file Output file stream * @throws IOException if an I/O error occurs. @@ -94,7 +97,10 @@ public class MethodParameter implements Cloneable, Node { } /** - * Returns the name of the parameter. + * Gets the name of the parameter. + * + * @param constantPool The pool to query. + * @return Constant from the given pool. */ public String getParameterName(final ConstantPool constantPool) { if (nameIndex == 0) { diff --git a/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/classfile/MethodParameters.java b/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/classfile/MethodParameters.java index 5b5d1d77f6f..2f5bffd8d3c 100644 --- a/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/classfile/MethodParameters.java +++ b/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/classfile/MethodParameters.java @@ -42,13 +42,12 @@ public class MethodParameters extends Attribute implements Iterable
@@ -46,14 +46,14 @@ import com.sun.org.apache.bcel.internal.util.Args;
* @see Code
* @see StackMapEntry
* @see StackMapType
- * @LastModified: Oct 2020
+ * @LastModified: Sept 2025
*/
public final class StackMap extends Attribute {
private StackMapEntry[] table; // Table of stack map entries
/**
- * Construct object from input stream.
+ * Constructs object from input stream.
*
* @param nameIndex Index of name
* @param length Content length in bytes
diff --git a/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/classfile/StackMapEntry.java b/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/classfile/StackMapEntry.java
index 110e30392ab..015083dd066 100644
--- a/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/classfile/StackMapEntry.java
+++ b/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/classfile/StackMapEntry.java
@@ -59,7 +59,7 @@ public final class StackMapEntry implements Node, Cloneable {
private ConstantPool constantPool;
/**
- * Construct object from input stream.
+ * Constructs object from input stream.
*
* @param dataInput Input stream
* @throws IOException if an I/O error occurs.
@@ -75,9 +75,7 @@ public final class StackMapEntry implements Node, Cloneable {
} else if (frameType == Const.SAME_LOCALS_1_STACK_ITEM_FRAME_EXTENDED) {
byteCodeOffset = dataInput.readUnsignedShort();
typesOfStackItems = new StackMapType[] { new StackMapType(dataInput, constantPool) };
- } else if (frameType >= Const.CHOP_FRAME && frameType <= Const.CHOP_FRAME_MAX) {
- byteCodeOffset = dataInput.readUnsignedShort();
- } else if (frameType == Const.SAME_FRAME_EXTENDED) {
+ } else if (frameType >= Const.CHOP_FRAME && frameType <= Const.CHOP_FRAME_MAX || frameType == Const.SAME_FRAME_EXTENDED) {
byteCodeOffset = dataInput.readUnsignedShort();
} else if (frameType >= Const.APPEND_FRAME && frameType <= Const.APPEND_FRAME_MAX) {
byteCodeOffset = dataInput.readUnsignedShort();
@@ -167,7 +165,7 @@ public final class StackMapEntry implements Node, Cloneable {
try {
e = (StackMapEntry) clone();
} catch (final CloneNotSupportedException ex) {
- throw new Error("Clone Not Supported");
+ throw new UnsupportedOperationException("Clone Not Supported", ex);
}
e.typesOfLocals = new StackMapType[typesOfLocals.length];
@@ -190,9 +188,7 @@ public final class StackMapEntry implements Node, Cloneable {
} else if (frameType == Const.SAME_LOCALS_1_STACK_ITEM_FRAME_EXTENDED) {
file.writeShort(byteCodeOffset);
typesOfStackItems[0].dump(file);
- } else if (frameType >= Const.CHOP_FRAME && frameType <= Const.CHOP_FRAME_MAX) {
- file.writeShort(byteCodeOffset);
- } else if (frameType == Const.SAME_FRAME_EXTENDED) {
+ } else if (frameType >= Const.CHOP_FRAME && frameType <= Const.CHOP_FRAME_MAX || frameType == Const.SAME_FRAME_EXTENDED) {
file.writeShort(byteCodeOffset);
} else if (frameType >= Const.APPEND_FRAME && frameType <= Const.APPEND_FRAME_MAX) {
file.writeShort(byteCodeOffset);
@@ -232,7 +228,6 @@ public final class StackMapEntry implements Node, Cloneable {
/**
* Calculate stack map entry size
- *
*/
int getMapEntrySize() {
if (frameType >= Const.SAME_FRAME && frameType <= Const.SAME_FRAME_MAX) {
diff --git a/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/classfile/StackMapType.java b/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/classfile/StackMapType.java
index 4575b31dfce..b93066d53b7 100644
--- a/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/classfile/StackMapType.java
+++ b/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/classfile/StackMapType.java
@@ -34,9 +34,9 @@ import com.sun.org.apache.bcel.internal.Const;
* @see StackMap
* @see Const
*/
-public final class StackMapType implements Cloneable {
+public final class StackMapType implements Node, Cloneable {
- public static final StackMapType[] EMPTY_ARRAY = {}; // must be public because BCELifier code generator writes calls to it
+ public static final StackMapType[] EMPTY_ARRAY = {}; // BCELifier code generator writes calls to constructor translating null to EMPTY_ARRAY
private byte type;
private int index = -1; // Index to CONSTANT_Class or offset
@@ -53,7 +53,7 @@ public final class StackMapType implements Cloneable {
}
/**
- * Construct object from file stream.
+ * Constructs object from file stream.
*
* @param file Input stream
* @throws IOException if an I/O error occurs.
@@ -66,6 +66,18 @@ public final class StackMapType implements Cloneable {
this.constantPool = constantPool;
}
+ /**
+ * Called by objects that are traversing the nodes of the tree implicitly defined by the contents of a Java class.
+ * I.e., the hierarchy of methods, fields, attributes, etc. spawns a tree of objects.
+ *
+ * @param v Visitor object
+ * @since 6.8.0
+ */
+ @Override
+ public void accept(final Visitor v) {
+ v.visitStackMapType(this);
+ }
+
private byte checkType(final byte type) {
if (type < Const.ITEM_Bogus || type > Const.ITEM_NewObject) {
throw new ClassFormatException("Illegal type for StackMapType: " + type);
@@ -98,6 +110,15 @@ public final class StackMapType implements Cloneable {
}
}
+ /**
+ * Gets the class name of this StackMapType from the constant pool at index position.
+ * @return the fully qualified name of the class for this StackMapType.
+ * @since 6.8.0
+ */
+ public String getClassName() {
+ return constantPool.constantToString(index, Const.CONSTANT_Class);
+ }
+
/**
* @return Constant pool used by this object.
*/
@@ -129,7 +150,7 @@ public final class StackMapType implements Cloneable {
if (index < 0) {
return ", class=";
}
- return ", class=" + constantPool.constantToString(index, Const.CONSTANT_Class);
+ return ", class=" + getClassName();
}
if (type == Const.ITEM_NewObject) {
return ", offset=" + index;
diff --git a/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/classfile/Synthetic.java b/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/classfile/Synthetic.java
index 3683fd6437e..c7fef8fcebc 100644
--- a/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/classfile/Synthetic.java
+++ b/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/classfile/Synthetic.java
@@ -52,7 +52,7 @@ public final class Synthetic extends Attribute {
}
/**
- * Construct object from input stream.
+ * Constructs object from input stream.
*
* @param nameIndex Index in constant pool to CONSTANT_Utf8
* @param length Content length in bytes
diff --git a/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/classfile/Utility.java b/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/classfile/Utility.java
index 12dbbe4828a..6967dcefd94 100644
--- a/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/classfile/Utility.java
+++ b/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/classfile/Utility.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2017, 2023, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2017, 2025, Oracle and/or its affiliates. All rights reserved.
*/
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
@@ -43,7 +43,7 @@ import com.sun.org.apache.bcel.internal.util.ByteSequence;
/**
* Utility functions that do not really belong to any class in particular.
*
- * @LastModified: Feb 2023
+ * @LastModified: Sept 2025
*/
// @since 6.0 methods are no longer final
public abstract class Utility {
@@ -51,7 +51,7 @@ public abstract class Utility {
/**
* Decode characters into bytes. Used by decode()
*/
- private static class JavaReader extends FilterReader {
+ private static final class JavaReader extends FilterReader {
public JavaReader(final Reader in) {
super(in);
@@ -88,10 +88,10 @@ public abstract class Utility {
}
/**
- * Encode bytes into valid java identifier characters. Used by
+ * Encode bytes into valid Java identifier characters. Used by
* encode()
*/
- private static class JavaWriter extends FilterWriter {
+ private static final class JavaWriter extends FilterWriter {
public JavaWriter(final Writer out) {
super(out);
@@ -437,7 +437,9 @@ public abstract class Utility {
case Const.NEW:
case Const.CHECKCAST:
buf.append("\t");
- //$FALL-THROUGH$
+ index = bytes.readUnsignedShort();
+ buf.append("\t<").append(constantPool.constantToString(index, Const.CONSTANT_Class)).append(">").append(verbose ? " (" + index + ")" : "");
+ break;
case Const.INSTANCEOF:
index = bytes.readUnsignedShort();
buf.append("\t<").append(constantPool.constantToString(index, Const.CONSTANT_Class)).append(">").append(verbose ? " (" + index + ")" : "");
@@ -864,7 +866,7 @@ public abstract class Utility {
// Skip any type arguments to read argument declarations between '(' and ')'
index = signature.indexOf('(') + 1;
if (index <= 0) {
- throw new ClassFormatException("Invalid method signature: " + signature);
+ throw new InvalidMethodSignatureException(signature);
}
while (signature.charAt(index) != ')') {
vec.add(typeSignatureToString(signature.substring(index), chopit));
@@ -872,7 +874,7 @@ public abstract class Utility {
index += unwrap(CONSUMER_CHARS); // update position
}
} catch (final StringIndexOutOfBoundsException e) { // Should never occur
- throw new ClassFormatException("Invalid method signature: " + signature, e);
+ throw new InvalidMethodSignatureException(signature, e);
}
return vec.toArray(Const.EMPTY_STRING_ARRAY);
}
@@ -903,11 +905,11 @@ public abstract class Utility {
// Read return type after ')'
index = signature.lastIndexOf(')') + 1;
if (index <= 0) {
- throw new ClassFormatException("Invalid method signature: " + signature);
+ throw new InvalidMethodSignatureException(signature);
}
type = typeSignatureToString(signature.substring(index), chopit);
} catch (final StringIndexOutOfBoundsException e) { // Should never occur
- throw new ClassFormatException("Invalid method signature: " + signature, e);
+ throw new InvalidMethodSignatureException(signature, e);
}
return type;
}
@@ -959,7 +961,7 @@ public abstract class Utility {
// Skip any type arguments to read argument declarations between '(' and ')'
index = signature.indexOf('(') + 1;
if (index <= 0) {
- throw new ClassFormatException("Invalid method signature: " + signature);
+ throw new InvalidMethodSignatureException(signature);
}
while (signature.charAt(index) != ')') {
final String paramType = typeSignatureToString(signature.substring(index), chopit);
@@ -985,7 +987,7 @@ public abstract class Utility {
// Read return type after ')'
type = typeSignatureToString(signature.substring(index), chopit);
} catch (final StringIndexOutOfBoundsException e) { // Should never occur
- throw new ClassFormatException("Invalid method signature: " + signature, e);
+ throw new InvalidMethodSignatureException(signature, e);
}
// ignore any throws information in the signature
if (buf.length() > 1) {
@@ -1172,7 +1174,7 @@ public abstract class Utility {
type = typeParams + typeSignaturesToString(signature.substring(index), chopit, ')');
index += unwrap(CONSUMER_CHARS); // update position
// add return type
- type = type + typeSignatureToString(signature.substring(index), chopit);
+ type += typeSignatureToString(signature.substring(index), chopit);
index += unwrap(CONSUMER_CHARS); // update position
// ignore any throws information in the signature
return type;
@@ -1237,12 +1239,12 @@ public abstract class Utility {
int index;
try {
if (signature.charAt(0) != '(') {
- throw new ClassFormatException("Invalid method signature: " + signature);
+ throw new InvalidMethodSignatureException(signature);
}
index = signature.lastIndexOf(')') + 1;
return typeOfSignature(signature.substring(index));
} catch (final StringIndexOutOfBoundsException e) {
- throw new ClassFormatException("Invalid method signature: " + signature, e);
+ throw new InvalidMethodSignatureException(signature, e);
}
}
@@ -1286,10 +1288,10 @@ public abstract class Utility {
case '*':
return typeOfSignature(signature.substring(1));
default:
- throw new ClassFormatException("Invalid method signature: " + signature);
+ throw new InvalidMethodSignatureException(signature);
}
} catch (final StringIndexOutOfBoundsException e) {
- throw new ClassFormatException("Invalid method signature: " + signature, e);
+ throw new InvalidMethodSignatureException(signature, e);
}
}
@@ -1469,8 +1471,8 @@ public abstract class Utility {
} else {
type.append(typeSignatureToString(signature.substring(consumedChars), chopit));
// update our consumed count by the number of characters the for type argument
- consumedChars = unwrap(Utility.CONSUMER_CHARS) + consumedChars;
- wrap(Utility.CONSUMER_CHARS, consumedChars);
+ consumedChars = unwrap(CONSUMER_CHARS) + consumedChars;
+ wrap(CONSUMER_CHARS, consumedChars);
}
// are there more TypeArguments?
@@ -1490,8 +1492,8 @@ public abstract class Utility {
} else {
type.append(typeSignatureToString(signature.substring(consumedChars), chopit));
// update our consumed count by the number of characters the for type argument
- consumedChars = unwrap(Utility.CONSUMER_CHARS) + consumedChars;
- wrap(Utility.CONSUMER_CHARS, consumedChars);
+ consumedChars = unwrap(CONSUMER_CHARS) + consumedChars;
+ wrap(CONSUMER_CHARS, consumedChars);
}
}
@@ -1508,14 +1510,14 @@ public abstract class Utility {
// update our consumed count by the number of characters the for type argument
// note that this count includes the "L" we added, but that is ok
// as it accounts for the "." we didn't consume
- consumedChars = unwrap(Utility.CONSUMER_CHARS) + consumedChars;
- wrap(Utility.CONSUMER_CHARS, consumedChars);
+ consumedChars = unwrap(CONSUMER_CHARS) + consumedChars;
+ wrap(CONSUMER_CHARS, consumedChars);
return type.toString();
}
if (signature.charAt(consumedChars) != ';') {
throw new ClassFormatException("Invalid signature: " + signature);
}
- wrap(Utility.CONSUMER_CHARS, consumedChars + 1); // remove final ";"
+ wrap(CONSUMER_CHARS, consumedChars + 1); // remove final ";"
return type.toString();
}
case 'S':
@@ -1536,9 +1538,9 @@ public abstract class Utility {
// The rest of the string denotes a ''
type = typeSignatureToString(signature.substring(n), chopit);
// corrected concurrent private static field acess
- // Utility.consumed_chars += consumed_chars; is replaced by:
- final int temp = unwrap(Utility.CONSUMER_CHARS) + consumedChars;
- wrap(Utility.CONSUMER_CHARS, temp);
+ // consumed_chars += consumed_chars; is replaced by:
+ final int temp = unwrap(CONSUMER_CHARS) + consumedChars;
+ wrap(CONSUMER_CHARS, temp);
return type + brackets.toString();
}
case 'V':
@@ -1552,11 +1554,11 @@ public abstract class Utility {
}
private static int unwrap(final ThreadLocal tl) {
- return tl.get();
+ return tl.get().intValue();
}
private static void wrap(final ThreadLocal tl, final int value) {
- tl.set(value);
+ tl.set(Integer.valueOf(value));
}
}
diff --git a/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/classfile/Visitor.java b/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/classfile/Visitor.java
index 74cb8400d3e..1f6fe9c96ee 100644
--- a/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/classfile/Visitor.java
+++ b/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/classfile/Visitor.java
@@ -217,11 +217,32 @@ public interface Visitor {
*/
void visitParameterAnnotation(ParameterAnnotations obj);
+
/**
* @since 6.0
*/
void visitParameterAnnotationEntry(ParameterAnnotationEntry obj);
+ /**
+ * Visits a {@link Record} object.
+ *
+ * @param obj Record to visit
+ * @since 6.9.0
+ */
+ default void visitRecord(final Record obj) {
+ // empty
+ }
+
+ /**
+ * Visits a {@link RecordComponentInfo} object.
+ *
+ * @param record component to visit
+ * @since 6.9.0
+ */
+ default void visitRecordComponent(final RecordComponentInfo record) {
+ // noop
+ }
+
void visitSignature(Signature obj);
void visitSourceFile(SourceFile obj);
@@ -230,7 +251,18 @@ public interface Visitor {
void visitStackMapEntry(StackMapEntry obj);
+ /**
+ * Visits a {@link StackMapType} object.
+ *
+ * @param obj object to visit
+ * @since 6.8.0
+ */
+ default void visitStackMapType(final StackMapType obj) {
+ // empty
+ }
+
void visitSynthetic(Synthetic obj);
void visitUnknown(Unknown obj);
+
}
diff --git a/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/classfile/package-info.java b/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/classfile/package-info.java
new file mode 100644
index 00000000000..4e8d383bcab
--- /dev/null
+++ b/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/classfile/package-info.java
@@ -0,0 +1,25 @@
+/*
+ * reserved comment block
+ * DO NOT REMOVE OR ALTER!
+ */
+/*
+ * 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.
+ */
+
+/**
+ * Classes that describe the structure of a Java class file and a class file parser.
+ */
+package com.sun.org.apache.bcel.internal.classfile;
diff --git a/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/generic/ARRAYLENGTH.java b/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/generic/ARRAYLENGTH.java
index 2d7188e9174..db756700085 100644
--- a/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/generic/ARRAYLENGTH.java
+++ b/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/generic/ARRAYLENGTH.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2017, 2023, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2017, 2025, Oracle and/or its affiliates. All rights reserved.
*/
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
@@ -28,12 +28,12 @@ import com.sun.org.apache.bcel.internal.ExceptionConst;
*
* Stack: ..., arrayref -> ..., length
*
- * @LastModified: Feb 2023
+ * @LastModified: Sept 2025
*/
public class ARRAYLENGTH extends Instruction implements ExceptionThrower, StackProducer, StackConsumer /* since 6.0 */ {
/**
- * Get length of array
+ * Gets length of array
*/
public ARRAYLENGTH() {
super(com.sun.org.apache.bcel.internal.Const.ARRAYLENGTH, (short) 1);
diff --git a/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/generic/ATHROW.java b/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/generic/ATHROW.java
index bb2e953f850..07171fefde1 100644
--- a/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/generic/ATHROW.java
+++ b/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/generic/ATHROW.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2017, 2020, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2017, 2025, Oracle and/or its affiliates. All rights reserved.
*/
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
@@ -28,8 +28,10 @@ import com.sun.org.apache.bcel.internal.ExceptionConst;
*
* Stack: ..., objectref -> objectref
*
+ *
+ * @LastModified: Sept 2025
*/
-public class ATHROW extends Instruction implements UnconditionalBranch, ExceptionThrower {
+public class ATHROW extends Instruction implements UnconditionalBranch, ExceptionThrower, StackConsumer {
/**
* Throw exception
@@ -48,6 +50,7 @@ public class ATHROW extends Instruction implements UnconditionalBranch, Exceptio
public void accept(final Visitor v) {
v.visitUnconditionalBranch(this);
v.visitExceptionThrower(this);
+ v.visitStackConsumer(this);
v.visitATHROW(this);
}
diff --git a/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/generic/AnnotationEntryGen.java b/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/generic/AnnotationEntryGen.java
index ea01a837175..0fad6ea7389 100644
--- a/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/generic/AnnotationEntryGen.java
+++ b/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/generic/AnnotationEntryGen.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2017, 2020, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2017, 2025, Oracle and/or its affiliates. All rights reserved.
*/
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
@@ -28,6 +28,7 @@ import java.io.DataOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
+import java.util.stream.Collectors;
import com.sun.org.apache.bcel.internal.classfile.AnnotationEntry;
import com.sun.org.apache.bcel.internal.classfile.Attribute;
@@ -37,10 +38,11 @@ import com.sun.org.apache.bcel.internal.classfile.RuntimeInvisibleAnnotations;
import com.sun.org.apache.bcel.internal.classfile.RuntimeInvisibleParameterAnnotations;
import com.sun.org.apache.bcel.internal.classfile.RuntimeVisibleAnnotations;
import com.sun.org.apache.bcel.internal.classfile.RuntimeVisibleParameterAnnotations;
+import jdk.xml.internal.Utils;
/**
* @since 6.0
- * @LastModified: Jan 2020
+ * @LastModified: Sept 2025
*/
public class AnnotationEntryGen {
@@ -53,7 +55,7 @@ public class AnnotationEntryGen {
* @param annotationEntryGens An array of AnnotationGen objects
*/
static Attribute[] getAnnotationAttributes(final ConstantPoolGen cp, final AnnotationEntryGen[] annotationEntryGens) {
- if (annotationEntryGens.length == 0) {
+ if (annotationEntryGens == null && annotationEntryGens.length == 0) {
return Attribute.EMPTY_ARRAY;
}
@@ -255,11 +257,7 @@ public class AnnotationEntryGen {
}
private List copyValues(final ElementValuePair[] in, final ConstantPoolGen cpool, final boolean copyPoolEntries) {
- final List out = new ArrayList<>();
- for (final ElementValuePair nvp : in) {
- out.add(new ElementValuePairGen(nvp, cpool, copyPoolEntries));
- }
- return out;
+ return Utils.streamOfIfNonNull(in).map(nvp -> new ElementValuePairGen(nvp, cpool, copyPoolEntries)).collect(Collectors.toList());
}
public void dump(final DataOutputStream dos) throws IOException {
@@ -286,18 +284,20 @@ public class AnnotationEntryGen {
}
public final String getTypeName() {
- return getTypeSignature();// BCELBUG: Should I use this instead?
+ return getTypeSignature(); // BCELBUG: Should I use this instead?
// Utility.signatureToString(getTypeSignature());
}
public final String getTypeSignature() {
- // ConstantClass c = (ConstantClass)cpool.getConstant(typeIndex);
+ // ConstantClass c = (ConstantClass) cpool.getConstant(typeIndex);
final ConstantUtf8 utf8 = (ConstantUtf8) cpool.getConstant(typeIndex/* c.getNameIndex() */);
return utf8.getBytes();
}
/**
- * Returns list of ElementNameValuePair objects
+ * Returns list of ElementNameValuePair objects.
+ *
+ * @return list of ElementNameValuePair objects.
*/
public List getValues() {
return evs;
diff --git a/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/generic/ArrayElementValueGen.java b/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/generic/ArrayElementValueGen.java
index 71374877efe..59b774a9afc 100644
--- a/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/generic/ArrayElementValueGen.java
+++ b/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/generic/ArrayElementValueGen.java
@@ -1,6 +1,5 @@
/*
- * reserved comment block
- * DO NOT REMOVE OR ALTER!
+ * Copyright (c) 2021, 2025, Oracle and/or its affiliates. All rights reserved.
*/
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
@@ -25,12 +24,15 @@ import java.io.DataOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
+import java.util.stream.Collectors;
import com.sun.org.apache.bcel.internal.classfile.ArrayElementValue;
import com.sun.org.apache.bcel.internal.classfile.ElementValue;
+import jdk.xml.internal.Utils;
/**
* @since 6.0
+ * @LastModified: Sept 2025
*/
public class ArrayElementValueGen extends ElementValueGen {
// J5TODO: Should we make this an array or a list? A list would be easier to
@@ -46,7 +48,7 @@ public class ArrayElementValueGen extends ElementValueGen {
evalues = new ArrayList<>();
final ElementValue[] in = value.getElementValuesArray();
for (final ElementValue element : in) {
- evalues.add(ElementValueGen.copy(element, cpool, copyPoolEntries));
+ evalues.add(copy(element, cpool, copyPoolEntries));
}
}
@@ -55,15 +57,12 @@ public class ArrayElementValueGen extends ElementValueGen {
evalues = new ArrayList<>();
}
- public ArrayElementValueGen(final int type, final ElementValue[] datums, final ConstantPoolGen cpool) {
+ public ArrayElementValueGen(final int type, final ElementValue[] elementValues, final ConstantPoolGen cpool) {
super(type, cpool);
if (type != ARRAY) {
throw new IllegalArgumentException("Only element values of type array can be built with this ctor - type specified: " + type);
}
- this.evalues = new ArrayList<>();
- for (final ElementValue datum : datums) {
- evalues.add(ElementValueGen.copy(datum, cpool, true));
- }
+ this.evalues = Utils.streamOfIfNonNull(elementValues).map(e -> copy(e, cpool, true)).collect(Collectors.toList());
}
public void addElement(final ElementValueGen gen) {
diff --git a/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/generic/ArrayType.java b/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/generic/ArrayType.java
index 138999ebe90..78a676e875e 100644
--- a/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/generic/ArrayType.java
+++ b/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/generic/ArrayType.java
@@ -1,6 +1,5 @@
/*
- * reserved comment block
- * DO NOT REMOVE OR ALTER!
+ * Copyright (c) 2019, 2025, Oracle and/or its affiliates. All rights reserved.
*/
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
@@ -24,6 +23,8 @@ import com.sun.org.apache.bcel.internal.Const;
/**
* Denotes array type, such as int[][]
+ *
+ * @LastModified: Sept 2025
*/
public final class ArrayType extends ReferenceType {
@@ -43,7 +44,7 @@ public final class ArrayType extends ReferenceType {
/**
* Convenience constructor for reference array type, e.g. Object[]
*
- * @param className complete name of class (java.lang.String, e.g.)
+ * @param className complete name of class ({@link String}, for example)
* @param dimensions array dimensions
*/
public ArrayType(final String className, final int dimensions) {
@@ -56,6 +57,7 @@ public final class ArrayType extends ReferenceType {
* @param type type of array (may be an array itself)
* @param dimensions array dimensions
*/
+ @SuppressWarnings("deprecation") //signature
public ArrayType(final Type type, final int dimensions) {
super(Const.T_ARRAY, "");
if (dimensions < 1 || dimensions > Const.MAX_BYTE) {
@@ -79,7 +81,7 @@ public final class ArrayType extends ReferenceType {
buf.append('[');
}
buf.append(basicType.getSignature());
- super.setSignature(buf.toString());
+ this.signature = buf.toString();
}
/**
diff --git a/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/generic/BranchHandle.java b/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/generic/BranchHandle.java
index 91ab9ac5463..f489f9a7658 100644
--- a/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/generic/BranchHandle.java
+++ b/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/generic/BranchHandle.java
@@ -63,7 +63,7 @@ public final class BranchHandle extends InstructionHandle {
}
/**
- * Set new contents. Old instruction is disposed and may not be used anymore.
+ * Sets new contents. Old instruction is disposed and may not be used anymore.
*/
@Override // This is only done in order to apply the additional type check; could be merged with super impl.
public void setInstruction(final Instruction i) { // TODO could be package-protected?
diff --git a/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/generic/CPInstruction.java b/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/generic/CPInstruction.java
index 1dfd244141a..ff45e5cde93 100644
--- a/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/generic/CPInstruction.java
+++ b/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/generic/CPInstruction.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2017, 2020, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2017, 2025, Oracle and/or its affiliates. All rights reserved.
*/
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
@@ -35,7 +35,7 @@ import com.sun.org.apache.bcel.internal.util.ByteSequence;
* @see LDC
* @see INVOKEVIRTUAL
*
- * @LastModified: Jan 2020
+ * @LastModified: Sept 2025
*/
public abstract class CPInstruction extends Instruction implements TypedInstruction, IndexedInstruction {
@@ -104,7 +104,7 @@ public abstract class CPInstruction extends Instruction implements TypedInstruct
}
/**
- * Set the index to constant pool.
+ * Sets the index to constant pool.
*
* @param index in constant pool.
*/
diff --git a/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/generic/ClassElementValueGen.java b/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/generic/ClassElementValueGen.java
index 1c1c032dbd5..8e024eebaa4 100644
--- a/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/generic/ClassElementValueGen.java
+++ b/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/generic/ClassElementValueGen.java
@@ -48,12 +48,12 @@ public class ClassElementValueGen extends ElementValueGen {
}
protected ClassElementValueGen(final int typeIdx, final ConstantPoolGen cpool) {
- super(ElementValueGen.CLASS, cpool);
+ super(CLASS, cpool);
this.idx = typeIdx;
}
public ClassElementValueGen(final ObjectType t, final ConstantPoolGen cpool) {
- super(ElementValueGen.CLASS, cpool);
+ super(CLASS, cpool);
// this.idx = cpool.addClass(t);
idx = cpool.addUtf8(t.getSignature());
}
@@ -67,9 +67,9 @@ public class ClassElementValueGen extends ElementValueGen {
public String getClassString() {
final ConstantUtf8 cu8 = (ConstantUtf8) getConstantPool().getConstant(idx);
return cu8.getBytes();
- // ConstantClass c = (ConstantClass)getConstantPool().getConstant(idx);
+ // ConstantClass c = (ConstantClass) getConstantPool().getConstant(idx);
// ConstantUtf8 utf8 =
- // (ConstantUtf8)getConstantPool().getConstant(c.getNameIndex());
+ // (ConstantUtf8) getConstantPool().getConstant(c.getNameIndex());
// return utf8.getBytes();
}
diff --git a/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/generic/ClassGen.java b/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/generic/ClassGen.java
index acaf4519567..debf930fe90 100644
--- a/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/generic/ClassGen.java
+++ b/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/generic/ClassGen.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2017, 2023, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2017, 2025, Oracle and/or its affiliates. All rights reserved.
*/
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
@@ -40,40 +40,37 @@ import com.sun.org.apache.bcel.internal.classfile.Utility;
import com.sun.org.apache.bcel.internal.util.BCELComparator;
/**
- * Template class for building up a java class. May be initialized with an existing java class (file).
+ * Template class for building up a java class. May be initialized with an existing Java class (file).
*
* @see JavaClass
- * @LastModified: Feb 2023
+ * @LastModified: Sept 2025
*/
public class ClassGen extends AccessFlags implements Cloneable {
- private static BCELComparator bcelComparator = new BCELComparator() {
+ private static BCELComparator bcelComparator = new BCELComparator() {
@Override
- public boolean equals(final Object o1, final Object o2) {
- final ClassGen THIS = (ClassGen) o1;
- final ClassGen THAT = (ClassGen) o2;
- return Objects.equals(THIS.getClassName(), THAT.getClassName());
+ public boolean equals(final ClassGen a, final ClassGen b) {
+ return a == b || a != null && b != null && Objects.equals(a.getClassName(), b.getClassName());
}
@Override
- public int hashCode(final Object o) {
- final ClassGen THIS = (ClassGen) o;
- return THIS.getClassName().hashCode();
+ public int hashCode(final ClassGen o) {
+ return o != null ? Objects.hashCode(o.getClassName()) : 0;
}
};
/**
* @return Comparison strategy object
*/
- public static BCELComparator getComparator() {
+ public static BCELComparator getComparator() {
return bcelComparator;
}
/**
* @param comparator Comparison strategy object
*/
- public static void setComparator(final BCELComparator comparator) {
+ public static void setComparator(final BCELComparator comparator) {
bcelComparator = comparator;
}
@@ -101,7 +98,7 @@ public class ClassGen extends AccessFlags implements Cloneable {
private List observers;
/**
- * Initialize with existing class.
+ * Constructs a new instance from an existing class.
*
* @param clazz JavaClass object (e.g. read from file)
*/
@@ -118,15 +115,26 @@ public class ClassGen extends AccessFlags implements Cloneable {
final Attribute[] attributes = clazz.getAttributes();
// J5TODO: Could make unpacking lazy, done on first reference
final AnnotationEntryGen[] annotations = unpackAnnotations(attributes);
- Collections.addAll(interfaceList, clazz.getInterfaceNames());
- for (final Attribute attribute : attributes) {
- if (!(attribute instanceof Annotations)) {
- addAttribute(attribute);
+ final String[] interfaceNames = clazz.getInterfaceNames();
+ if (interfaceNames != null) {
+ Collections.addAll(interfaceList, interfaceNames);
+ }
+ if (attributes != null) {
+ for (final Attribute attribute : attributes) {
+ if (!(attribute instanceof Annotations)) {
+ addAttribute(attribute);
+ }
}
}
Collections.addAll(annotationList, annotations);
- Collections.addAll(methodList, clazz.getMethods());
- Collections.addAll(fieldList, clazz.getFields());
+ final Method[] methods = clazz.getMethods();
+ if (methods != null) {
+ Collections.addAll(methodList, methods);
+ }
+ final Field[] fields = clazz.getFields();
+ if (fields != null) {
+ Collections.addAll(fieldList, fields);
+ }
}
/**
@@ -242,7 +250,7 @@ public class ClassGen extends AccessFlags implements Cloneable {
try {
return super.clone();
} catch (final CloneNotSupportedException e) {
- throw new Error("Clone Not Supported"); // never happens
+ throw new UnsupportedOperationException("Clone Not Supported", e); // never happens
}
}
@@ -282,7 +290,7 @@ public class ClassGen extends AccessFlags implements Cloneable {
*/
@Override
public boolean equals(final Object obj) {
- return bcelComparator.equals(this, obj);
+ return obj instanceof ClassGen && bcelComparator.equals(this, (ClassGen) obj);
}
// J5TODO: Should we make calling unpackAnnotations() lazy and put it in here?
@@ -379,7 +387,7 @@ public class ClassGen extends AccessFlags implements Cloneable {
}
/**
- * Return value as defined by given BCELComparator strategy. By default return the hashcode of the class name.
+ * Return value as defined by given BCELComparator strategy. By default return the hash code of the class name.
*
* @see Object#hashCode()
*/
@@ -478,7 +486,7 @@ public class ClassGen extends AccessFlags implements Cloneable {
}
/**
- * Set major version number of class file, default value is 45 (JDK 1.1)
+ * Sets major version number of class file, default value is 45 (JDK 1.1)
*
* @param major major version number
*/
@@ -492,11 +500,13 @@ public class ClassGen extends AccessFlags implements Cloneable {
public void setMethods(final Method[] methods) {
methodList.clear();
- Collections.addAll(methodList, methods);
+ if (methods != null) {
+ Collections.addAll(methodList, methods);
+ }
}
/**
- * Set minor version number of class file, default value is 3 (JDK 1.1)
+ * Sets minor version number of class file, default value is 3 (JDK 1.1)
*
* @param minor minor version number
*/
@@ -515,17 +525,19 @@ public class ClassGen extends AccessFlags implements Cloneable {
}
/**
- * Look for attributes representing annotations and unpack them.
+ * Unpacks attributes representing annotations.
*/
- private AnnotationEntryGen[] unpackAnnotations(final Attribute[] attrs) {
+ private AnnotationEntryGen[] unpackAnnotations(final Attribute[] attributes) {
final List annotationGenObjs = new ArrayList<>();
- for (final Attribute attr : attrs) {
- if (attr instanceof RuntimeVisibleAnnotations) {
- final RuntimeVisibleAnnotations rva = (RuntimeVisibleAnnotations) attr;
- rva.forEach(a -> annotationGenObjs.add(new AnnotationEntryGen(a, getConstantPool(), false)));
- } else if (attr instanceof RuntimeInvisibleAnnotations) {
- final RuntimeInvisibleAnnotations ria = (RuntimeInvisibleAnnotations) attr;
- ria.forEach(a -> annotationGenObjs.add(new AnnotationEntryGen(a, getConstantPool(), false)));
+ if (attributes != null) {
+ for (final Attribute attr : attributes) {
+ if (attr instanceof RuntimeVisibleAnnotations) {
+ final RuntimeVisibleAnnotations rva = (RuntimeVisibleAnnotations) attr;
+ rva.forEach(a -> annotationGenObjs.add(new AnnotationEntryGen(a, getConstantPool(), false)));
+ } else if (attr instanceof RuntimeInvisibleAnnotations) {
+ final RuntimeInvisibleAnnotations ria = (RuntimeInvisibleAnnotations) attr;
+ ria.forEach(a -> annotationGenObjs.add(new AnnotationEntryGen(a, getConstantPool(), false)));
+ }
}
}
return annotationGenObjs.toArray(AnnotationEntryGen.EMPTY_ARRAY);
diff --git a/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/generic/CodeExceptionGen.java b/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/generic/CodeExceptionGen.java
index fa660954d15..2518131ccee 100644
--- a/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/generic/CodeExceptionGen.java
+++ b/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/generic/CodeExceptionGen.java
@@ -63,7 +63,7 @@ public final class CodeExceptionGen implements InstructionTargeter, Cloneable {
try {
return super.clone();
} catch (final CloneNotSupportedException e) {
- throw new Error("Clone Not Supported"); // never happens
+ throw new UnsupportedOperationException("Clone Not Supported", e); // never happens
}
}
@@ -81,7 +81,7 @@ public final class CodeExceptionGen implements InstructionTargeter, Cloneable {
}
/**
- * Get CodeException object.
+ * Gets CodeException object.
*
* This relies on that the instruction list has already been dumped to byte code or that the 'setPositions' methods
* has been called for the instruction list.
@@ -120,7 +120,7 @@ public final class CodeExceptionGen implements InstructionTargeter, Cloneable {
}
/*
- * Set end of handler
+ * Sets end of handler
*
* @param endPc End of handled region (inclusive)
*/
@@ -130,7 +130,7 @@ public final class CodeExceptionGen implements InstructionTargeter, Cloneable {
}
/*
- * Set handler code
+ * Sets handler code
*
* @param handlerPc Start of handler
*/
@@ -140,7 +140,7 @@ public final class CodeExceptionGen implements InstructionTargeter, Cloneable {
}
/*
- * Set start of handler
+ * Sets start of handler
*
* @param startPc Start of handled region (inclusive)
*/
diff --git a/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/generic/ElementValuePairGen.java b/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/generic/ElementValuePairGen.java
index bdc9c517a86..878f392b6b7 100644
--- a/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/generic/ElementValuePairGen.java
+++ b/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/generic/ElementValuePairGen.java
@@ -44,7 +44,7 @@ public class ElementValuePairGen {
// Could assert nvp.getNameString() points to the same thing as
// constantPoolGen.getConstant(nvp.getNameIndex())
// if
- // (!nvp.getNameString().equals(((ConstantUtf8)constantPoolGen.getConstant(nvp.getNameIndex())).getBytes()))
+ // (!nvp.getNameString().equals(((ConstantUtf8) constantPoolGen.getConstant(nvp.getNameIndex())).getBytes()))
// {
// throw new IllegalArgumentException("envp buggered");
// }
@@ -86,7 +86,7 @@ public class ElementValuePairGen {
}
public final String getNameString() {
- // ConstantString cu8 = (ConstantString)constantPoolGen.getConstant(nameIdx);
+ // ConstantString cu8 = (ConstantString) constantPoolGen.getConstant(nameIdx);
return ((ConstantUtf8) constantPoolGen.getConstant(nameIdx)).getBytes();
}
diff --git a/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/generic/EnumElementValueGen.java b/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/generic/EnumElementValueGen.java
index 95ac794f2d7..95c00ed3813 100644
--- a/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/generic/EnumElementValueGen.java
+++ b/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/generic/EnumElementValueGen.java
@@ -40,10 +40,8 @@ public class EnumElementValueGen extends ElementValueGen {
public EnumElementValueGen(final EnumElementValue value, final ConstantPoolGen cpool, final boolean copyPoolEntries) {
super(ENUM_CONSTANT, cpool);
if (copyPoolEntries) {
- typeIdx = cpool.addUtf8(value.getEnumTypeString());// was
- // addClass(value.getEnumTypeString());
- valueIdx = cpool.addUtf8(value.getEnumValueString()); // was
- // addString(value.getEnumValueString());
+ typeIdx = cpool.addUtf8(value.getEnumTypeString()); // was addClass(value.getEnumTypeString());
+ valueIdx = cpool.addUtf8(value.getEnumValueString()); // was addString(value.getEnumValueString());
} else {
typeIdx = value.getTypeIndex();
valueIdx = value.getValueIndex();
@@ -55,7 +53,7 @@ public class EnumElementValueGen extends ElementValueGen {
* This ctor is used for deserialization
*/
protected EnumElementValueGen(final int typeIdx, final int valueIdx, final ConstantPoolGen cpool) {
- super(ElementValueGen.ENUM_CONSTANT, cpool);
+ super(ENUM_CONSTANT, cpool);
if (super.getElementValueType() != ENUM_CONSTANT) {
throw new IllegalArgumentException("Only element values of type enum can be built with this ctor - type specified: " + super.getElementValueType());
}
@@ -64,9 +62,9 @@ public class EnumElementValueGen extends ElementValueGen {
}
public EnumElementValueGen(final ObjectType t, final String value, final ConstantPoolGen cpool) {
- super(ElementValueGen.ENUM_CONSTANT, cpool);
- typeIdx = cpool.addUtf8(t.getSignature());// was addClass(t);
- valueIdx = cpool.addUtf8(value);// was addString(value);
+ super(ENUM_CONSTANT, cpool);
+ typeIdx = cpool.addUtf8(t.getSignature()); // was addClass(t);
+ valueIdx = cpool.addUtf8(value); // was addString(value);
}
@Override
@@ -90,9 +88,9 @@ public class EnumElementValueGen extends ElementValueGen {
public String getEnumTypeString() {
// Constant cc = getConstantPool().getConstant(typeIdx);
// ConstantClass cu8 =
- // (ConstantClass)getConstantPool().getConstant(typeIdx);
+ // (ConstantClass) getConstantPool().getConstant(typeIdx);
// return
- // ((ConstantUtf8)getConstantPool().getConstant(cu8.getNameIndex())).getBytes();
+ // ((ConstantUtf8) getConstantPool().getConstant(cu8.getNameIndex())).getBytes();
return ((ConstantUtf8) getConstantPool().getConstant(typeIdx)).getBytes();
// return Utility.signatureToString(cu8.getBytes());
}
@@ -100,9 +98,9 @@ public class EnumElementValueGen extends ElementValueGen {
public String getEnumValueString() {
return ((ConstantUtf8) getConstantPool().getConstant(valueIdx)).getBytes();
// ConstantString cu8 =
- // (ConstantString)getConstantPool().getConstant(valueIdx);
+ // (ConstantString) getConstantPool().getConstant(valueIdx);
// return
- // ((ConstantUtf8)getConstantPool().getConstant(cu8.getStringIndex())).getBytes();
+ // ((ConstantUtf8) getConstantPool().getConstant(cu8.getStringIndex())).getBytes();
}
public int getTypeIndex() {
@@ -118,8 +116,8 @@ public class EnumElementValueGen extends ElementValueGen {
final ConstantUtf8 cu8 = (ConstantUtf8) getConstantPool().getConstant(valueIdx);
return cu8.getBytes();
// ConstantString cu8 =
- // (ConstantString)getConstantPool().getConstant(valueIdx);
+ // (ConstantString) getConstantPool().getConstant(valueIdx);
// return
- // ((ConstantUtf8)getConstantPool().getConstant(cu8.getStringIndex())).getBytes();
+ // ((ConstantUtf8) getConstantPool().getConstant(cu8.getStringIndex())).getBytes();
}
}
diff --git a/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/generic/ExceptionThrower.java b/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/generic/ExceptionThrower.java
index 86a0cad256c..2a488c85ede 100644
--- a/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/generic/ExceptionThrower.java
+++ b/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/generic/ExceptionThrower.java
@@ -23,7 +23,7 @@ package com.sun.org.apache.bcel.internal.generic;
/**
* Denote an instruction that may throw a run-time or a linking exception (or both) during execution. This is not quite
- * the truth as such; because all instructions may throw an java.lang.VirtualMachineError. These exceptions are omitted.
+ * the truth as such; because all instructions may throw a {@link VirtualMachineError}. These exceptions are omitted.
*
* The Lava Language Specification specifies exactly which RUN-TIME and which LINKING exceptions each
* instruction may throw which is reflected by the implementers. Due to the structure of the JVM specification, it may
diff --git a/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/generic/FieldGen.java b/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/generic/FieldGen.java
index 9d1f4d41d93..30786370d29 100644
--- a/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/generic/FieldGen.java
+++ b/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/generic/FieldGen.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2017, 2021, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2017, 2025, Oracle and/or its affiliates. All rights reserved.
*/
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
@@ -40,37 +40,34 @@ import com.sun.org.apache.bcel.internal.util.BCELComparator;
* to a field (which must of course be compatible with to the declared type).
*
* @see Field
- * @LastModified: May 2021
+ * @LastModified: Sept 2025
*/
public class FieldGen extends FieldGenOrMethodGen {
- private static BCELComparator bcelComparator = new BCELComparator() {
+ private static BCELComparator bcelComparator = new BCELComparator() {
@Override
- public boolean equals(final Object o1, final Object o2) {
- final FieldGen THIS = (FieldGen) o1;
- final FieldGen THAT = (FieldGen) o2;
- return Objects.equals(THIS.getName(), THAT.getName()) && Objects.equals(THIS.getSignature(), THAT.getSignature());
+ public boolean equals(final FieldGen a, final FieldGen b) {
+ return a == b || a != null && b != null && Objects.equals(a.getName(), b.getName()) && Objects.equals(a.getSignature(), b.getSignature());
}
@Override
- public int hashCode(final Object o) {
- final FieldGen THIS = (FieldGen) o;
- return THIS.getSignature().hashCode() ^ THIS.getName().hashCode();
+ public int hashCode(final FieldGen o) {
+ return o != null ? Objects.hash(o.getSignature(), o.getName()) : 0;
}
};
/**
- * @return Comparison strategy object
+ * @return Comparison strategy object.
*/
- public static BCELComparator getComparator() {
+ public static BCELComparator getComparator() {
return bcelComparator;
}
/**
- * @param comparator Comparison strategy object
+ * @param comparator Comparison strategy object.
*/
- public static void setComparator(final BCELComparator comparator) {
+ public static void setComparator(final BCELComparator comparator) {
bcelComparator = comparator;
}
@@ -81,8 +78,8 @@ public class FieldGen extends FieldGenOrMethodGen {
/**
* Instantiate from existing field.
*
- * @param field Field object
- * @param cp constant pool (must contain the same entries as the field's constant pool)
+ * @param field Field object.
+ * @param cp constant pool (must contain the same entries as the field's constant pool).
*/
public FieldGen(final Field field, final ConstantPoolGen cp) {
this(field.getAccessFlags(), Type.getType(field.getSignature()), field.getName(), cp);
@@ -187,11 +184,11 @@ public class FieldGen extends FieldGenOrMethodGen {
*/
@Override
public boolean equals(final Object obj) {
- return bcelComparator.equals(this, obj);
+ return obj instanceof FieldGen && bcelComparator.equals(this, (FieldGen) obj);
}
/**
- * Get field object after having set up all necessary values.
+ * Gets field object after having set up all necessary values.
*/
public Field getField() {
final String signature = getSignature();
@@ -207,10 +204,7 @@ public class FieldGen extends FieldGenOrMethodGen {
}
public String getInitValue() {
- if (value != null) {
- return value.toString();
- }
- return null;
+ return Objects.toString(value, null);
}
@Override
@@ -219,7 +213,7 @@ public class FieldGen extends FieldGenOrMethodGen {
}
/**
- * Return value as defined by given BCELComparator strategy. By default return the hashcode of the field's name XOR
+ * Return value as defined by given BCELComparator strategy. By default return the hash code of the field's name XOR
* signature.
*
* @see Object#hashCode()
@@ -295,7 +289,7 @@ public class FieldGen extends FieldGenOrMethodGen {
}
/**
- * Set (optional) initial value of field, otherwise it will be set to null/0/false by the JVM automatically.
+ * Sets (optional) initial value of field, otherwise it will be set to null/0/false by the JVM automatically.
*/
public void setInitValue(final String str) {
checkType(ObjectType.getInstance("java.lang.String"));
diff --git a/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/generic/FieldGenOrMethodGen.java b/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/generic/FieldGenOrMethodGen.java
index 6555392e9d4..bc1fbc8627e 100644
--- a/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/generic/FieldGenOrMethodGen.java
+++ b/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/generic/FieldGenOrMethodGen.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2017, 2021, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2017, 2025, Oracle and/or its affiliates. All rights reserved.
*/
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
@@ -30,7 +30,7 @@ import com.sun.org.apache.bcel.internal.classfile.Attribute;
/**
* Super class for FieldGen and MethodGen objects, since they have some methods in common!
*
- * @LastModified: May 2021
+ * @LastModified: Sept 2025
*/
public abstract class FieldGenOrMethodGen extends AccessFlags implements NamedAndTyped, Cloneable {
@@ -67,8 +67,10 @@ public abstract class FieldGenOrMethodGen extends AccessFlags implements NamedAn
super(accessFlags);
}
- protected void addAll(final Attribute[] attrs) {
- Collections.addAll(attributeList, attrs);
+ protected void addAll(final Attribute[] attributes) {
+ if (attributes != null) {
+ Collections.addAll(attributeList, attributes);
+ }
}
/**
@@ -93,7 +95,7 @@ public abstract class FieldGenOrMethodGen extends AccessFlags implements NamedAn
try {
return super.clone();
} catch (final CloneNotSupportedException e) {
- throw new Error("Clone Not Supported"); // never happens
+ throw new UnsupportedOperationException("Clone Not Supported", e); // never happens
}
}
diff --git a/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/generic/FieldOrMethod.java b/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/generic/FieldOrMethod.java
index 1c646f48292..87ba4cb913e 100644
--- a/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/generic/FieldOrMethod.java
+++ b/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/generic/FieldOrMethod.java
@@ -53,7 +53,6 @@ public abstract class FieldOrMethod extends CPInstruction implements LoadClass {
* generated by Java 1.5, this answer is sometimes wrong (e.g., if the "clone()" method is called on an
* array). A better idea is to use the {@link #getReferenceType(ConstantPoolGen)} method, which correctly
* distinguishes between class types and array types.
- *
*/
@Deprecated
public String getClassName(final ConstantPoolGen cpg) {
@@ -89,6 +88,9 @@ public abstract class FieldOrMethod extends CPInstruction implements LoadClass {
if (rt instanceof ObjectType) {
return (ObjectType) rt;
}
+ if (rt instanceof ArrayType) {
+ return Type.OBJECT;
+ }
throw new ClassGenException(rt.getClass().getCanonicalName() + " " + rt.getSignature() + " does not represent an ObjectType");
}
diff --git a/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/generic/ICONST.java b/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/generic/ICONST.java
index 5effd7edcd9..b3eb14a9ddf 100644
--- a/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/generic/ICONST.java
+++ b/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/generic/ICONST.java
@@ -25,7 +25,6 @@ package com.sun.org.apache.bcel.internal.generic;
*
* Stack: ... -> ...,
*
- *
*/
public class ICONST extends Instruction implements ConstantPushInstruction {
diff --git a/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/generic/INVOKEDYNAMIC.java b/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/generic/INVOKEDYNAMIC.java
index 2865a158de2..998d072e067 100644
--- a/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/generic/INVOKEDYNAMIC.java
+++ b/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/generic/INVOKEDYNAMIC.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2017, 2023, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2017, 2025, Oracle and/or its affiliates. All rights reserved.
*/
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
@@ -37,7 +37,7 @@ import com.sun.org.apache.bcel.internal.util.ByteSequence;
* @see The
* invokedynamic instruction in The Java Virtual Machine Specification
* @since 6.0
- * @LastModified: Feb 2023
+ * @LastModified: Sept 2025
*/
public class INVOKEDYNAMIC extends InvokeInstruction {
@@ -104,11 +104,11 @@ public class INVOKEDYNAMIC extends InvokeInstruction {
}
/**
- * Since InvokeDynamic doesn't refer to a reference type, just return java.lang.Object, as that is the only type we can
+ * Since InvokeDynamic doesn't refer to a reference type, just return {@link Object}, as that is the only type we can
* say for sure the reference will be.
*
* @param cpg the ConstantPoolGen used to create the instruction
- * @return an ObjectType for java.lang.Object
+ * @return an ObjectType for {@link Object}
* @since 6.1
*/
@Override
diff --git a/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/generic/Instruction.java b/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/generic/Instruction.java
index 16c8e2444b4..a7124409f12 100644
--- a/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/generic/Instruction.java
+++ b/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/generic/Instruction.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2017, 2023, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2017, 2025, Oracle and/or its affiliates. All rights reserved.
*/
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
@@ -29,7 +29,7 @@ import com.sun.org.apache.bcel.internal.util.ByteSequence;
/**
* Abstract super class for all Java byte codes.
*
- * @LastModified: Feb 2023
+ * @LastModified: Sept 2025
*/
public abstract class Instruction implements Cloneable {
@@ -461,7 +461,7 @@ public abstract class Instruction implements Cloneable {
public Instruction copy() {
Instruction i = null;
// "Constant" instruction, no need to duplicate
- if (InstructionConst.getInstruction(this.getOpcode()) != null) {
+ if (InstructionConst.getInstruction(getOpcode()) != null) {
i = this;
} else {
try {
diff --git a/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/generic/InstructionConst.java b/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/generic/InstructionConst.java
index 439268e35eb..7b95bfc99b1 100644
--- a/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/generic/InstructionConst.java
+++ b/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/generic/InstructionConst.java
@@ -170,7 +170,7 @@ public final class InstructionConst {
public static final LocalVariableInstruction ISTORE_2 = new ISTORE(2);
/**
- * Get object via its opcode, for immutable instructions like branch instructions entries are set to null.
+ * Gets object via its opcode, for immutable instructions like branch instructions entries are set to null.
*/
static final Instruction[] INSTRUCTIONS = new Instruction[256];
diff --git a/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/generic/InstructionFactory.java b/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/generic/InstructionFactory.java
index 5e9220354c3..3c4b3e9f9da 100644
--- a/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/generic/InstructionFactory.java
+++ b/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/generic/InstructionFactory.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2017, 2023, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2017, 2025, Oracle and/or its affiliates. All rights reserved.
*/
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
@@ -30,11 +30,11 @@ import com.sun.org.apache.bcel.internal.Const;
*
* @see Const
* @see InstructionConst
- * @LastModified: Feb 2023
+ * @LastModified: Sept 2025
*/
public class InstructionFactory {
- private static class MethodObject {
+ private static final class MethodObject {
final Type[] argTypes;
final Type resultType;
@@ -53,10 +53,12 @@ public class InstructionFactory {
private static final String FQCN_STRING_BUFFER = "java.lang.StringBuffer";
- // N.N. These must agree with the order of Constants.T_CHAR through T_LONG
- private static final String[] shortNames = {"C", "F", "D", "B", "S", "I", "L"};
+ /**
+ * These must agree with the order of Constants.T_CHAR through T_LONG.
+ */
+ private static final String[] SHORT_NAMES = {"C", "F", "D", "B", "S", "I", "L"};
- private static final MethodObject[] appendMethodObjects = {
+ private static final MethodObject[] APPEND_METHOD_OBJECTS = {
new MethodObject(FQCN_STRING_BUFFER, APPEND, Type.STRINGBUFFER, new Type[] { Type.STRING }),
new MethodObject(FQCN_STRING_BUFFER, APPEND, Type.STRINGBUFFER, new Type[] { Type.OBJECT }), null, null, // indices 2, 3
new MethodObject(FQCN_STRING_BUFFER, APPEND, Type.STRINGBUFFER, new Type[] { Type.BOOLEAN }),
@@ -484,7 +486,7 @@ public class InstructionFactory {
public Instruction createAppend(final Type type) {
final byte t = type.getType();
if (isString(type)) {
- return createInvoke(appendMethodObjects[0], Const.INVOKEVIRTUAL);
+ return createInvoke(APPEND_METHOD_OBJECTS[0], Const.INVOKEVIRTUAL);
}
switch (t) {
case Const.T_BOOLEAN:
@@ -495,10 +497,10 @@ public class InstructionFactory {
case Const.T_SHORT:
case Const.T_INT:
case Const.T_LONG:
- return createInvoke(appendMethodObjects[t], Const.INVOKEVIRTUAL);
+ return createInvoke(APPEND_METHOD_OBJECTS[t], Const.INVOKEVIRTUAL);
case Const.T_ARRAY:
case Const.T_OBJECT:
- return createInvoke(appendMethodObjects[1], Const.INVOKEVIRTUAL);
+ return createInvoke(APPEND_METHOD_OBJECTS[1], Const.INVOKEVIRTUAL);
default:
throw new IllegalArgumentException("No append for this type? " + type);
}
@@ -515,7 +517,7 @@ public class InstructionFactory {
if (dest == Const.T_LONG && (src == Const.T_CHAR || src == Const.T_BYTE || src == Const.T_SHORT)) {
src = Const.T_INT;
}
- final String name = "com.sun.org.apache.bcel.internal.generic." + shortNames[src - Const.T_CHAR] + "2" + shortNames[dest - Const.T_CHAR];
+ final String name = "com.sun.org.apache.bcel.internal.generic." + SHORT_NAMES[src - Const.T_CHAR] + "2" + SHORT_NAMES[dest - Const.T_CHAR];
Instruction i = null;
try {
i = (Instruction) Class.forName(name).getDeclaredConstructor().newInstance();;
@@ -642,8 +644,10 @@ public class InstructionFactory {
int index;
int nargs = 0;
final String signature = Type.getMethodSignature(retType, argTypes);
- for (final Type argType : argTypes) {
- nargs += argType.getSize();
+ if (argTypes != null) {
+ for (final Type argType : argTypes) {
+ nargs += argType.getSize();
+ }
}
if (useInterface) {
index = cp.addInterfaceMethodref(className, name, signature);
diff --git a/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/generic/InstructionHandle.java b/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/generic/InstructionHandle.java
index 5e962354d16..2c94b770265 100644
--- a/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/generic/InstructionHandle.java
+++ b/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/generic/InstructionHandle.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2017, 2021, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2017, 2025, Oracle and/or its affiliates. All rights reserved.
*/
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
@@ -38,7 +38,7 @@ import com.sun.org.apache.bcel.internal.classfile.Utility;
* @see Instruction
* @see BranchHandle
* @see InstructionList
- * @LastModified: May 2021
+ * @LastModified: Sept 2025
*/
public class InstructionHandle {
@@ -118,7 +118,7 @@ public class InstructionHandle {
if (targeters == null) {
targeters = new HashSet<>();
}
- // if(!targeters.contains(t))
+ // if (!targeters.contains(t))
targeters.add(t);
}
@@ -135,15 +135,12 @@ public class InstructionHandle {
}
/**
- * Get attribute of an instruction handle.
+ * Gets attribute of an instruction handle.
*
* @param key the key object to store/retrieve the attribute
*/
public Object getAttribute(final Object key) {
- if (attributes != null) {
- return attributes.get(key);
- }
- return null;
+ return attributes != null ? attributes.get(key) : null;
}
/**
@@ -247,7 +244,7 @@ public class InstructionHandle {
}
/**
- * Set the position, i.e., the byte code offset of the contained instruction.
+ * Sets the position, i.e., the byte code offset of the contained instruction.
*/
void setPosition(final int pos) {
i_position = pos;
diff --git a/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/generic/InstructionList.java b/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/generic/InstructionList.java
index 7ffc3a8228e..579efc9fe3b 100644
--- a/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/generic/InstructionList.java
+++ b/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/generic/InstructionList.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2017, 2023, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2017, 2025, Oracle and/or its affiliates. All rights reserved.
*/
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
@@ -33,6 +33,7 @@ import java.util.NoSuchElementException;
import com.sun.org.apache.bcel.internal.Const;
import com.sun.org.apache.bcel.internal.classfile.Constant;
import com.sun.org.apache.bcel.internal.util.ByteSequence;
+import jdk.xml.internal.Utils;
/**
* This class is a container for a list of Instruction objects. Instructions can be
@@ -46,7 +47,7 @@ import com.sun.org.apache.bcel.internal.util.ByteSequence;
* @see Instruction
* @see InstructionHandle
* @see BranchHandle
- * @LastModified: Feb 2023
+ * @LastModified: Sept 2025
*/
public class InstructionList implements Iterable {
@@ -60,23 +61,25 @@ public class InstructionList implements Iterable {
* @return target position's instruction handle if available
*/
public static InstructionHandle findHandle(final InstructionHandle[] ihs, final int[] pos, final int count, final int target) {
- int l = 0;
- int r = count - 1;
- /*
- * Do a binary search since the pos array is orderd.
- */
- do {
- final int i = l + r >>> 1;
- final int j = pos[i];
- if (j == target) {
- return ihs[i];
- }
- if (target < j) {
- r = i - 1;
- } else {
- l = i + 1;
- }
- } while (l <= r);
+ if (ihs != null && pos != null) {
+ int l = 0;
+ int r = count - 1;
+ /*
+ * Do a binary search since the pos array is orderd.
+ */
+ do {
+ final int i = l + r >>> 1;
+ final int j = pos[i];
+ if (j == target) {
+ return ihs[i];
+ }
+ if (target < j) {
+ r = i - 1;
+ } else {
+ l = i + 1;
+ }
+ } while (l <= r);
+ }
return null;
}
@@ -513,7 +516,7 @@ public class InstructionList implements Iterable {
}
/**
- * Get instruction handle for instruction at byte code position pos. This only works properly, if the list is freshly
+ * Gets instruction handle for instruction at byte code position pos. This only works properly, if the list is freshly
* initialized from a byte array or setPositions() has been called before this method.
*
* @param pos byte code position to search for
@@ -605,7 +608,7 @@ public class InstructionList implements Iterable {
}
/**
- * Get positions (offsets) of all instructions in the list. This relies on that the list has been freshly created from
+ * Gets positions (offsets) of all instructions in the list. This relies on that the list has been freshly created from
* an byte code array, or that setPositions() has been called. Otherwise this may be inaccurate.
*
* @return array containing all instruction's offset in byte code
@@ -959,7 +962,7 @@ public class InstructionList implements Iterable {
* @see MethodGen
*/
public void redirectExceptionHandlers(final CodeExceptionGen[] exceptions, final InstructionHandle oldTarget, final InstructionHandle newTarget) {
- for (final CodeExceptionGen exception : exceptions) {
+ Utils.streamOfIfNonNull(exceptions).forEach(exception -> {
if (exception.getStartPC() == oldTarget) {
exception.setStartPC(newTarget);
}
@@ -969,7 +972,7 @@ public class InstructionList implements Iterable {
if (exception.getHandlerPC() == oldTarget) {
exception.setHandlerPC(newTarget);
}
- }
+ });
}
/**
@@ -981,16 +984,14 @@ public class InstructionList implements Iterable {
* @see MethodGen
*/
public void redirectLocalVariables(final LocalVariableGen[] lg, final InstructionHandle oldTarget, final InstructionHandle newTarget) {
- for (final LocalVariableGen element : lg) {
- final InstructionHandle start = element.getStart();
- final InstructionHandle end = element.getEnd();
- if (start == oldTarget) {
+ Utils.streamOfIfNonNull(lg).forEach(element -> {
+ if (element.getStart() == oldTarget) {
element.setStart(newTarget);
}
- if (end == oldTarget) {
+ if (element.getEnd() == oldTarget) {
element.setEnd(newTarget);
}
- }
+ });
}
/**
@@ -1120,7 +1121,7 @@ public class InstructionList implements Iterable {
ih.setPosition(index);
pos[count++] = index;
/*
- * Get an estimate about how many additional bytes may be added, because BranchInstructions may have variable length
+ * Gets an estimate about how many additional bytes may be added, because BranchInstructions may have variable length
* depending on the target offset (short vs. int) or alignment issues (TABLESWITCH and LOOKUPSWITCH).
*/
switch (i.getOpcode()) {
@@ -1132,11 +1133,14 @@ public class InstructionList implements Iterable {
case Const.LOOKUPSWITCH:
maxAdditionalBytes += 3;
break;
+ default:
+ // TODO should this be an error?
+ break;
}
index += i.getLength();
}
/*
- * Pass 2: Expand the variable-length (Branch)Instructions depending on the target offset (short or int) and ensure that
+ * Pass 2: Expand the variable-length (Branch) Instructions depending on the target offset (short or int) and ensure that
* branch targets are within this list.
*/
for (InstructionHandle ih = start; ih != null; ih = ih.getNext()) {
@@ -1152,8 +1156,7 @@ public class InstructionList implements Iterable {
pos[count++] = index;
index += i.getLength();
}
- bytePositions = new int[count]; // Trim to proper size
- System.arraycopy(pos, 0, bytePositions, 0, count);
+ bytePositions = Arrays.copyOfRange(pos, 0, count); // Trim to proper size
}
/**
diff --git a/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/generic/InstructionTargeter.java b/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/generic/InstructionTargeter.java
index 5146408ef49..0681476b5ee 100644
--- a/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/generic/InstructionTargeter.java
+++ b/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/generic/InstructionTargeter.java
@@ -22,7 +22,7 @@
package com.sun.org.apache.bcel.internal.generic;
/**
- * Denote that a class targets InstructionHandles within an InstructionList. Namely the following implementers:
+ * Denotes that a class targets InstructionHandles within an InstructionList.
*
* @see BranchHandle
* @see LocalVariableGen
@@ -33,9 +33,12 @@ public interface InstructionTargeter {
// static final InstructionTargeter[] EMPTY_ARRAY = new InstructionTargeter[0];
/**
- * Checks whether this targeter targets the specified instruction handle.
+ * Tests whether this targeter targets the specified instruction handle.
+ *
+ * @param instructionHandle the instruction handle to test.
+ * @return whether this targeter targets the specified instruction handle.
*/
- boolean containsTarget(InstructionHandle ih);
+ boolean containsTarget(InstructionHandle instructionHandle);
/**
* Replaces the target of this targeter from this old handle to the new handle.
diff --git a/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/generic/LCMP.java b/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/generic/LCMP.java
index c517b492f0a..188ac95f6ef 100644
--- a/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/generic/LCMP.java
+++ b/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/generic/LCMP.java
@@ -27,7 +27,6 @@ package com.sun.org.apache.bcel.internal.generic;
*
* Stack: ..., value1.word1, value1.word2, value2.word1, value2.word2 -> ..., result <= -1, 0, 1>
*
- *
*/
public class LCMP extends Instruction implements TypedInstruction, StackProducer, StackConsumer {
diff --git a/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/generic/LDC.java b/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/generic/LDC.java
index d95bade23bd..13ca0a84cfa 100644
--- a/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/generic/LDC.java
+++ b/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/generic/LDC.java
@@ -94,6 +94,8 @@ public class LDC extends CPInstruction implements PushInstruction, ExceptionThro
return Type.INT;
case com.sun.org.apache.bcel.internal.Const.CONSTANT_Class:
return Type.CLASS;
+ case com.sun.org.apache.bcel.internal.Const.CONSTANT_Dynamic:
+ return Type.OBJECT;
default: // Never reached
throw new IllegalArgumentException("Unknown or invalid constant type at " + super.getIndex());
}
@@ -113,7 +115,10 @@ public class LDC extends CPInstruction implements PushInstruction, ExceptionThro
case com.sun.org.apache.bcel.internal.Const.CONSTANT_Class:
final int nameIndex = ((com.sun.org.apache.bcel.internal.classfile.ConstantClass) c).getNameIndex();
c = cpg.getConstantPool().getConstant(nameIndex);
- return Type.getType(((com.sun.org.apache.bcel.internal.classfile.ConstantUtf8) c).getBytes());
+ return Type.getType(Type.internalTypeNameToSignature(((com.sun.org.apache.bcel.internal.classfile.ConstantUtf8) c).getBytes()));
+ case com.sun.org.apache.bcel.internal.Const.CONSTANT_Dynamic:
+ // Really not sure what to return here, maybe a BootstrapMethod instance but how do we get it?
+ return c;
default: // Never reached
throw new IllegalArgumentException("Unknown or invalid constant type at " + super.getIndex());
}
@@ -129,7 +134,7 @@ public class LDC extends CPInstruction implements PushInstruction, ExceptionThro
}
/**
- * Set the index to constant pool and adjust size.
+ * Sets the index to constant pool and adjust size.
*/
@Override
public final void setIndex(final int index) {
diff --git a/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/generic/LineNumberGen.java b/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/generic/LineNumberGen.java
index 3773c21e7b3..68bb2abf513 100644
--- a/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/generic/LineNumberGen.java
+++ b/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/generic/LineNumberGen.java
@@ -54,7 +54,7 @@ public class LineNumberGen implements InstructionTargeter, Cloneable {
try {
return super.clone();
} catch (final CloneNotSupportedException e) {
- throw new Error("Clone Not Supported"); // never happens
+ throw new UnsupportedOperationException("Clone Not Supported", e); // never happens
}
}
@@ -71,7 +71,7 @@ public class LineNumberGen implements InstructionTargeter, Cloneable {
}
/**
- * Get LineNumber attribute.
+ * Gets LineNumber attribute.
*
* This relies on that the instruction list has already been dumped to byte code or that the 'setPositions' methods
* has been called for the instruction list.
diff --git a/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/generic/LocalVariableGen.java b/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/generic/LocalVariableGen.java
index 830564d42c9..71cfa0cf1c2 100644
--- a/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/generic/LocalVariableGen.java
+++ b/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/generic/LocalVariableGen.java
@@ -85,7 +85,7 @@ public class LocalVariableGen implements InstructionTargeter, NamedAndTyped, Clo
try {
return super.clone();
} catch (final CloneNotSupportedException e) {
- throw new Error("Clone Not Supported"); // never happens
+ throw new UnsupportedOperationException("Clone Not Supported", e); // never happens
}
}
diff --git a/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/generic/LocalVariableInstruction.java b/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/generic/LocalVariableInstruction.java
index 67184c0b9f1..f952a65880b 100644
--- a/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/generic/LocalVariableInstruction.java
+++ b/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/generic/LocalVariableInstruction.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2017, 2021, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2017, 2025, Oracle and/or its affiliates. All rights reserved.
*/
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
@@ -28,7 +28,7 @@ import com.sun.org.apache.bcel.internal.util.ByteSequence;
/**
* Abstract super class for instructions dealing with local variables.
*
- * @LastModified: May 2021
+ * @LastModified: Sept 2025
*/
public abstract class LocalVariableInstruction extends Instruction implements TypedInstruction, IndexedInstruction {
@@ -162,7 +162,7 @@ public abstract class LocalVariableInstruction extends Instruction implements Ty
}
/**
- * Set the local variable index. also updates opcode and length TODO Why?
+ * Sets the local variable index. also updates opcode and length TODO Why?
*
* @see #setIndexOnly(int)
*/
diff --git a/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/generic/MethodGen.java b/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/generic/MethodGen.java
index f6e8333be79..be09b0a5159 100644
--- a/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/generic/MethodGen.java
+++ b/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/generic/MethodGen.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2013, 2023, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013, 2025, Oracle and/or its affiliates. All rights reserved.
*/
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
@@ -27,6 +27,7 @@ import java.util.HashMap;
import java.util.List;
import java.util.Objects;
import java.util.Stack;
+import java.util.stream.Collectors;
import com.sun.org.apache.bcel.internal.Const;
import com.sun.org.apache.bcel.internal.classfile.AnnotationEntry;
@@ -46,6 +47,7 @@ import com.sun.org.apache.bcel.internal.classfile.ParameterAnnotations;
import com.sun.org.apache.bcel.internal.classfile.RuntimeVisibleParameterAnnotations;
import com.sun.org.apache.bcel.internal.classfile.Utility;
import com.sun.org.apache.bcel.internal.util.BCELComparator;
+import jdk.xml.internal.Utils;
/**
* Template class for building up a method. This is done by defining exception handlers, adding thrown exceptions, local
@@ -57,7 +59,7 @@ import com.sun.org.apache.bcel.internal.util.BCELComparator;
*
* @see InstructionList
* @see Method
- * @LastModified: Feb 2023
+ * @LastModified: Sept 2025
*/
public class MethodGen extends FieldGenOrMethodGen {
@@ -102,19 +104,16 @@ public class MethodGen extends FieldGenOrMethodGen {
}
}
- private static BCELComparator bcelComparator = new BCELComparator() {
+ private static BCELComparator bcelComparator = new BCELComparator() {
@Override
- public boolean equals(final Object o1, final Object o2) {
- final FieldGenOrMethodGen THIS = (FieldGenOrMethodGen) o1;
- final FieldGenOrMethodGen THAT = (FieldGenOrMethodGen) o2;
- return Objects.equals(THIS.getName(), THAT.getName()) && Objects.equals(THIS.getSignature(), THAT.getSignature());
+ public boolean equals(final FieldGenOrMethodGen a, final FieldGenOrMethodGen b) {
+ return a == b || a != null && b != null && Objects.equals(a.getName(), b.getName()) && Objects.equals(a.getSignature(), b.getSignature());
}
@Override
- public int hashCode(final Object o) {
- final FieldGenOrMethodGen THIS = (FieldGenOrMethodGen) o;
- return THIS.getSignature().hashCode() ^ THIS.getName().hashCode();
+ public int hashCode(final FieldGenOrMethodGen o) {
+ return o != null ? Objects.hash(o.getSignature(), o.getName()) : 0;
}
};
@@ -127,9 +126,9 @@ public class MethodGen extends FieldGenOrMethodGen {
}
/**
- * @return Comparison strategy object
+ * @return Comparison strategy object.
*/
- public static BCELComparator getComparator() {
+ public static BCELComparator getComparator() {
return bcelComparator;
}
@@ -206,9 +205,9 @@ public class MethodGen extends FieldGenOrMethodGen {
}
/**
- * @param comparator Comparison strategy object
+ * @param comparator Comparison strategy object.
*/
- public static void setComparator(final BCELComparator comparator) {
+ public static void setComparator(final BCELComparator comparator) {
bcelComparator = comparator;
}
@@ -636,7 +635,7 @@ public class MethodGen extends FieldGenOrMethodGen {
*/
@Override
public boolean equals(final Object obj) {
- return bcelComparator.equals(this, obj);
+ return obj instanceof FieldGenOrMethodGen && bcelComparator.equals(this, (FieldGenOrMethodGen) obj);
}
// J5TODO: Should paramAnnotations be an array of arrays? Rather than an array of lists, this
@@ -790,7 +789,7 @@ public class MethodGen extends FieldGenOrMethodGen {
}
/**
- * Get method object. Never forget to call setMaxStack() or setMaxStack(max), respectively, before calling this method
+ * Gets method object. Never forget to call setMaxStack() or setMaxStack(max), respectively, before calling this method
* (the same applies for max locals).
*
* @return method object
@@ -888,7 +887,7 @@ public class MethodGen extends FieldGenOrMethodGen {
}
/**
- * Return value as defined by given BCELComparator strategy. By default return the hashcode of the method's name XOR
+ * Return value as defined by given BCELComparator strategy. By default return the hash code of the method's name XOR
* signature.
*
* @see Object#hashCode()
@@ -899,11 +898,7 @@ public class MethodGen extends FieldGenOrMethodGen {
}
private List makeMutableVersion(final AnnotationEntry[] mutableArray) {
- final List result = new ArrayList<>();
- for (final AnnotationEntry element : mutableArray) {
- result.add(new AnnotationEntryGen(element, getConstantPool(), false));
- }
- return result;
+ return Utils.streamOfIfNonNull(mutableArray).map(ae -> new AnnotationEntryGen(ae, getConstantPool(), false)).collect(Collectors.toList());
}
/**
@@ -1027,10 +1022,8 @@ public class MethodGen extends FieldGenOrMethodGen {
*
* @since 6.5.0
*/
- public void removeRuntimeAttributes(final Attribute[] attrs) {
- for (final Attribute attr : attrs) {
- removeAttribute(attr);
- }
+ public void removeRuntimeAttributes(final Attribute[] attributes) {
+ Utils.streamOfIfNonNull(attributes).forEach(this::removeAttribute);
}
public void setArgumentName(final int i, final String name) {
@@ -1038,7 +1031,7 @@ public class MethodGen extends FieldGenOrMethodGen {
}
public void setArgumentNames(final String[] argNames) {
- this.argNames = argNames;
+ this.argNames = Utils.createEmptyArrayIfNull(argNames, String[].class);
}
public void setArgumentType(final int i, final Type type) {
@@ -1046,7 +1039,7 @@ public class MethodGen extends FieldGenOrMethodGen {
}
public void setArgumentTypes(final Type[] argTypes) {
- this.argTypes = argTypes;
+ this.argTypes = argTypes != null ? argTypes : Type.NO_ARGS;
}
public void setClassName(final String className) { // TODO could be package-protected?
@@ -1084,7 +1077,7 @@ public class MethodGen extends FieldGenOrMethodGen {
}
/**
- * Set maximum number of local variables.
+ * Sets maximum number of local variables.
*/
public void setMaxLocals(final int m) {
maxLocals = m;
@@ -1102,7 +1095,7 @@ public class MethodGen extends FieldGenOrMethodGen {
}
/**
- * Set maximum stack size for this method.
+ * Sets maximum stack size for this method.
*/
public void setMaxStack(final int m) { // TODO could be package-protected?
maxStack = m;
diff --git a/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/generic/ObjectType.java b/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/generic/ObjectType.java
index 46378a1b71e..622a3cdd961 100644
--- a/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/generic/ObjectType.java
+++ b/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/generic/ObjectType.java
@@ -27,7 +27,7 @@ import com.sun.org.apache.bcel.internal.classfile.JavaClass;
import com.sun.org.apache.bcel.internal.classfile.Utility;
/**
- * Denotes reference such as java.lang.String.
+ * Denotes reference such as {@link String}.
*/
public class ObjectType extends ReferenceType {
@@ -47,7 +47,7 @@ public class ObjectType extends ReferenceType {
/**
* Constructs a new instance.
*
- * @param className fully qualified class name, e.g. java.lang.String
+ * @param className fully qualified class name, e.g. {@link String}
*/
public ObjectType(final String className) {
super(Const.T_REFERENCE, "L" + Utility.packageToPath(className) + ";");
@@ -151,7 +151,7 @@ public class ObjectType extends ReferenceType {
* @throws ClassNotFoundException if any of this class's superclasses can't be found
*/
public boolean subclassOf(final ObjectType superclass) throws ClassNotFoundException {
- if (this.referencesInterfaceExact() || superclass.referencesInterfaceExact()) {
+ if (referencesInterfaceExact() || superclass.referencesInterfaceExact()) {
return false;
}
return Repository.instanceOf(this.className, superclass.className);
diff --git a/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/generic/RET.java b/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/generic/RET.java
index a7cacc7c165..99a1efbed16 100644
--- a/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/generic/RET.java
+++ b/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/generic/RET.java
@@ -110,7 +110,7 @@ public class RET extends Instruction implements IndexedInstruction, TypedInstruc
}
/**
- * Set index of local variable containg the return address
+ * Sets index of local variable containg the return address
*/
@Override
public final void setIndex(final int n) {
diff --git a/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/generic/ReferenceType.java b/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/generic/ReferenceType.java
index fe75792e213..9b94a1dcf2d 100644
--- a/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/generic/ReferenceType.java
+++ b/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/generic/ReferenceType.java
@@ -42,10 +42,10 @@ public abstract class ReferenceType extends Type {
/**
* This commutative operation returns the first common superclass (narrowest ReferenceType referencing a class, not an
- * interface). If one of the types is a superclass of the other, the former is returned. If "this" is Type.NULL, then t
- * is returned. If t is Type.NULL, then "this" is returned. If "this" equals t ['this.equals(t)'] "this" is returned. If
- * "this" or t is an ArrayType, then Type.OBJECT is returned. If "this" or t is a ReferenceType referencing an
- * interface, then Type.OBJECT is returned. If not all of the two classes' superclasses cannot be found, "null" is
+ * interface). If one of the types is a superclass of the other, the former is returned. If "this" is NULL, then t
+ * is returned. If t is NULL, then "this" is returned. If "this" equals t ['this.equals(t)'] "this" is returned. If
+ * "this" or t is an ArrayType, then {@link #OBJECT} is returned. If "this" or t is a ReferenceType referencing an
+ * interface, then {@link #OBJECT} is returned. If not all of the two classes' superclasses cannot be found, "null" is
* returned. See the JVM specification edition 2, "4.9.2 The Bytecode Verifier".
*
* @deprecated use getFirstCommonSuperclass(ReferenceType t) which has slightly changed semantics.
@@ -53,46 +53,46 @@ public abstract class ReferenceType extends Type {
*/
@Deprecated
public ReferenceType firstCommonSuperclass(final ReferenceType t) throws ClassNotFoundException {
- if (this.equals(Type.NULL)) {
+ if (equals(NULL)) {
return t;
}
- if (t.equals(Type.NULL) || this.equals(t)) {
+ if (t.equals(NULL) || equals(t)) {
return this;
/*
- * TODO: Above sounds a little arbitrary. On the other hand, there is no object referenced by Type.NULL so we can also
- * say all the objects referenced by Type.NULL were derived from java.lang.Object. However, the Java Language's
- * "instanceof" operator proves us wrong: "null" is not referring to an instance of java.lang.Object :)
+ * TODO: Above sounds a little arbitrary. On the other hand, there is no object referenced by {@link #NULL} so we can also
+ * say all the objects referenced by {@link #NULL} were derived from {@link Object}. However, the Java Language's
+ * "instanceof" operator proves us wrong: "null" is not referring to an instance of {@link Object} :)
*/
}
if (this instanceof ArrayType || t instanceof ArrayType) {
- return Type.OBJECT;
- // TODO: Is there a proof of OBJECT being the direct ancestor of every ArrayType?
+ return OBJECT;
+ // TODO: Is there a proof of {@link #OBJECT} being the direct ancestor of every ArrayType?
}
return getFirstCommonSuperclassInternal(t);
}
/**
* This commutative operation returns the first common superclass (narrowest ReferenceType referencing a class, not an
- * interface). If one of the types is a superclass of the other, the former is returned. If "this" is Type.NULL, then t
- * is returned. If t is Type.NULL, then "this" is returned. If "this" equals t ['this.equals(t)'] "this" is returned. If
- * "this" or t is an ArrayType, then Type.OBJECT is returned; unless their dimensions match. Then an ArrayType of the
+ * interface). If one of the types is a superclass of the other, the former is returned. If "this" is NULL, then t
+ * is returned. If t is NULL, then "this" is returned. If "this" equals t ['this.equals(t)'] "this" is returned. If
+ * "this" or t is an ArrayType, then {@link #OBJECT} is returned; unless their dimensions match. Then an ArrayType of the
* same number of dimensions is returned, with its basic type being the first common super class of the basic types of
- * "this" and t. If "this" or t is a ReferenceType referencing an interface, then Type.OBJECT is returned. If not all of
+ * "this" and t. If "this" or t is a ReferenceType referencing an interface, then {@link #OBJECT} is returned. If not all of
* the two classes' superclasses cannot be found, "null" is returned. See the JVM specification edition 2, "4.9.2 The
* Bytecode Verifier".
*
* @throws ClassNotFoundException on failure to find superclasses of this type, or the type passed as a parameter
*/
public ReferenceType getFirstCommonSuperclass(final ReferenceType t) throws ClassNotFoundException {
- if (this.equals(Type.NULL)) {
+ if (equals(NULL)) {
return t;
}
- if (t.equals(Type.NULL) || this.equals(t)) {
+ if (t.equals(NULL) || equals(t)) {
return this;
/*
- * TODO: Above sounds a little arbitrary. On the other hand, there is no object referenced by Type.NULL so we can also
- * say all the objects referenced by Type.NULL were derived from java.lang.Object. However, the Java Language's
- * "instanceof" operator proves us wrong: "null" is not referring to an instance of java.lang.Object :)
+ * TODO: Above sounds a little arbitrary. On the other hand, there is no object referenced by {@link #NULL} so we can also
+ * say all the objects referenced by {@link #NULL} were derived from {@link Object}. However, the Java Language's
+ * "instanceof" operator proves us wrong: "null" is not referring to an instance of {@link Object} :)
*/
}
/* This code is from a bug report by Konstantin Shagin */
@@ -106,8 +106,8 @@ public abstract class ReferenceType extends Type {
}
}
if (this instanceof ArrayType || t instanceof ArrayType) {
- return Type.OBJECT;
- // TODO: Is there a proof of OBJECT being the direct ancestor of every ArrayType?
+ return OBJECT;
+ // TODO: Is there a proof of {@link #OBJECT} being the direct ancestor of every ArrayType?
}
return getFirstCommonSuperclassInternal(t);
}
@@ -115,7 +115,7 @@ public abstract class ReferenceType extends Type {
private ReferenceType getFirstCommonSuperclassInternal(final ReferenceType t) throws ClassNotFoundException {
if (this instanceof ObjectType && ((ObjectType) this).referencesInterfaceExact()
|| t instanceof ObjectType && ((ObjectType) t).referencesInterfaceExact()) {
- return Type.OBJECT;
+ return OBJECT;
// TODO: The above line is correct comparing to the vmspec2. But one could
// make class file verification a bit stronger here by using the notion of
// superinterfaces or even castability or assignment compatibility.
@@ -142,7 +142,7 @@ public abstract class ReferenceType extends Type {
}
}
}
- // Huh? Did you ask for Type.OBJECT's superclass??
+ // Huh? Did you ask for OBJECT's superclass??
return null;
}
@@ -158,7 +158,7 @@ public abstract class ReferenceType extends Type {
return false;
}
final ReferenceType T = (ReferenceType) t;
- if (this.equals(Type.NULL)) {
+ if (equals(NULL)) {
return true; // This is not explicitly stated, but clear. Isn't it?
}
/*
@@ -169,7 +169,7 @@ public abstract class ReferenceType extends Type {
* If T is a class type, then this must be the same class as T, or this must be a subclass of T;
*/
if (T instanceof ObjectType && ((ObjectType) T).referencesClassExact()
- && (this.equals(T) || Repository.instanceOf(((ObjectType) this).getClassName(), ((ObjectType) T).getClassName()))) {
+ && (equals(T) || Repository.instanceOf(((ObjectType) this).getClassName(), ((ObjectType) T).getClassName()))) {
return true;
}
/*
@@ -187,14 +187,14 @@ public abstract class ReferenceType extends Type {
/*
* If T is a class type, then T must be Object (2.4.7).
*/
- if (T instanceof ObjectType && ((ObjectType) T).referencesClassExact() && T.equals(Type.OBJECT)) {
+ if (T instanceof ObjectType && ((ObjectType) T).referencesClassExact() && T.equals(OBJECT)) {
return true;
}
/*
* If T is an interface type, then T must be the same interface as this or a superinterface of this (2.13.2).
*/
if (T instanceof ObjectType && ((ObjectType) T).referencesInterfaceExact()
- && (this.equals(T) || Repository.implementationOf(((ObjectType) this).getClassName(), ((ObjectType) T).getClassName()))) {
+ && (equals(T) || Repository.implementationOf(((ObjectType) this).getClassName(), ((ObjectType) T).getClassName()))) {
return true;
}
}
@@ -205,7 +205,7 @@ public abstract class ReferenceType extends Type {
/*
* If T is a class type, then T must be Object (2.4.7).
*/
- if (T instanceof ObjectType && ((ObjectType) T).referencesClassExact() && T.equals(Type.OBJECT)) {
+ if (T instanceof ObjectType && ((ObjectType) T).referencesClassExact() && T.equals(OBJECT)) {
return true;
}
/*
@@ -246,14 +246,14 @@ public abstract class ReferenceType extends Type {
/**
* Return true iff this type is castable to another type t as defined in the JVM specification. The case where this is
- * Type.NULL is not defined (see the CHECKCAST definition in the JVM specification). However, because e.g. CHECKCAST
+ * {@link #NULL} is not defined (see the CHECKCAST definition in the JVM specification). However, because e.g. CHECKCAST
* doesn't throw a ClassCastException when casting a null reference to any Object, true is returned in this case.
*
* @throws ClassNotFoundException if any classes or interfaces required to determine assignment compatibility can't be
* found
*/
public boolean isCastableTo(final Type t) throws ClassNotFoundException {
- if (this.equals(Type.NULL)) {
+ if (equals(NULL)) {
return t instanceof ReferenceType; // If this is ever changed in isAssignmentCompatible()
}
return isAssignmentCompatibleWith(t);
diff --git a/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/generic/SWITCH.java b/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/generic/SWITCH.java
index aed1626ec0d..f929176c174 100644
--- a/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/generic/SWITCH.java
+++ b/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/generic/SWITCH.java
@@ -95,7 +95,7 @@ public final class SWITCH implements CompoundInstruction {
* @param maxGap maximum gap that may between case branches
*/
public SWITCH(final int[] match, final InstructionHandle[] targets, final InstructionHandle target, final int maxGap) {
- int[] matchClone = match.clone();
+ final int[] matchClone = match.clone();
final InstructionHandle[] targetsClone = targets.clone();
final int matchLength = match.length;
if (matchLength < 2) {
diff --git a/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/generic/Select.java b/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/generic/Select.java
index a90e795e99f..a3086ac1664 100644
--- a/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/generic/Select.java
+++ b/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/generic/Select.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2017, 2021, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2017, 2025, Oracle and/or its affiliates. All rights reserved.
*/
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
@@ -33,7 +33,7 @@ import com.sun.org.apache.bcel.internal.util.ByteSequence;
* @see LOOKUPSWITCH
* @see TABLESWITCH
* @see InstructionList
- * @LastModified: May 2021
+ * @LastModified: Sept 2025
*/
public abstract class Select extends BranchInstruction implements VariableLengthInstruction, StackConsumer /* @since 6.0 */, StackProducer {
@@ -87,7 +87,7 @@ public abstract class Select extends BranchInstruction implements VariableLength
* @param defaultTarget default instruction target
*/
Select(final short opcode, final int[] match, final InstructionHandle[] targets, final InstructionHandle defaultTarget) {
- // don't set default target before instuction is built
+ // don't set default target before instruction is built
super(opcode, null);
this.match = match;
this.targets = targets;
@@ -288,7 +288,7 @@ public abstract class Select extends BranchInstruction implements VariableLength
}
/**
- * Set branch target for 'i'th case
+ * Sets branch target for 'i'th case
*/
public void setTarget(final int i, final InstructionHandle target) { // TODO could be package-protected?
notifyTarget(targets[i], target, this);
@@ -314,7 +314,11 @@ public abstract class Select extends BranchInstruction implements VariableLength
for (int i = 0; i < match_length; i++) {
String s = "null";
if (targets[i] != null) {
- s = targets[i].getInstruction().toString();
+ if (targets[i].getInstruction() == this) {
+ s = "";
+ } else {
+ s = targets[i].getInstruction().toString();
+ }
}
buf.append("(").append(match[i]).append(", ").append(s).append(" = {").append(indices[i]).append("})");
}
diff --git a/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/generic/SimpleElementValueGen.java b/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/generic/SimpleElementValueGen.java
index a4de20315d7..363b3237632 100644
--- a/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/generic/SimpleElementValueGen.java
+++ b/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/generic/SimpleElementValueGen.java
@@ -166,7 +166,7 @@ public class SimpleElementValueGen extends ElementValueGen {
dos.writeShort(idx);
break;
default:
- throw new IllegalStateException("SimpleElementValueGen doesnt know how to write out type " + super.getElementValueType());
+ throw new IllegalStateException("SimpleElementValueGen doesn't know how to write out type " + super.getElementValueType());
}
}
@@ -184,7 +184,7 @@ public class SimpleElementValueGen extends ElementValueGen {
public int getValueInt() {
if (super.getElementValueType() != PRIMITIVE_INT) {
- throw new IllegalStateException("Dont call getValueString() on a non STRING ElementValue");
+ throw new IllegalStateException("Don't call getValueString() on a non STRING ElementValue");
}
final ConstantInteger c = (ConstantInteger) getConstantPool().getConstant(idx);
return c.getBytes();
@@ -192,7 +192,7 @@ public class SimpleElementValueGen extends ElementValueGen {
public String getValueString() {
if (super.getElementValueType() != STRING) {
- throw new IllegalStateException("Dont call getValueString() on a non STRING ElementValue");
+ throw new IllegalStateException("Don't call getValueString() on a non STRING ElementValue");
}
final ConstantUtf8 c = (ConstantUtf8) getConstantPool().getConstant(idx);
return c.getBytes();
diff --git a/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/generic/TargetLostException.java b/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/generic/TargetLostException.java
index 40ed6ff4c38..038bbe63148 100644
--- a/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/generic/TargetLostException.java
+++ b/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/generic/TargetLostException.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2017, 2023, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2017, 2025, Oracle and/or its affiliates. All rights reserved.
*/
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
@@ -21,32 +21,32 @@
package com.sun.org.apache.bcel.internal.generic;
/**
- * Thrown by InstructionList.remove() when one or multiple disposed instructions are still being referenced by an
- * InstructionTargeter object. I.e. the InstructionTargeter has to be notified that (one of) the InstructionHandle it is
- * referencing is being removed from the InstructionList and thus not valid anymore.
+ * Thrown by {@link InstructionList} when one or multiple disposed instructions are still being referenced by an {@link InstructionTargeter} object. I.e. the
+ * {@link InstructionTargeter} has to be notified that (one of) the {@link InstructionHandle} it is referencing is being removed from the
+ * {@link InstructionList} and thus not valid anymore.
*
*
- * Making this an exception instead of a return value forces the user to handle these case explicitly in a try { ... }
- * catch. The following code illustrates how this may be done:
+ * Making this an exception instead of a return value forces the user to handle these case explicitly in a try { ... } catch. The following code illustrates how
+ * this may be done:
*
*
- *
+ *
* ...
* try {
* il.delete(start_ih, end_ih);
- * } catch(TargetLostException e) {
+ * } catch (TargetLostException e) {
* for (InstructionHandle target : e.getTargets()) {
* for (InstructionTargeter targeter : target.getTargeters()) {
* targeter.updateTarget(target, new_target);
* }
* }
* }
- *
+ *
*
* @see InstructionHandle
* @see InstructionList
* @see InstructionTargeter
- * @LastModified: Feb 2023
+ * @LastModified: Sept 2025
*/
public final class TargetLostException extends Exception {
@@ -54,12 +54,14 @@ public final class TargetLostException extends Exception {
@SuppressWarnings("serial") // Array component type is not Serializable
private final InstructionHandle[] targets;
- TargetLostException(final InstructionHandle[] t, final String mesg) {
- super(mesg);
- targets = t;
+ TargetLostException(final InstructionHandle[] targets, final String message) {
+ super(message);
+ this.targets = targets;
}
/**
+ * Gets the list of instructions still being targeted.
+ *
* @return list of instructions still being targeted.
*/
public InstructionHandle[] getTargets() {
diff --git a/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/generic/Type.java b/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/generic/Type.java
index ea20710af2e..b58645b402e 100644
--- a/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/generic/Type.java
+++ b/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/generic/Type.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2017, 2021, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2017, 2025, Oracle and/or its affiliates. All rights reserved.
*/
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
@@ -26,12 +26,14 @@ import java.util.Objects;
import com.sun.org.apache.bcel.internal.Const;
import com.sun.org.apache.bcel.internal.classfile.ClassFormatException;
+import com.sun.org.apache.bcel.internal.classfile.InvalidMethodSignatureException;
import com.sun.org.apache.bcel.internal.classfile.Utility;
+import jdk.xml.internal.Utils;
/**
- * Abstract super class for all possible java types, namely basic types such as int, object types like String and array
+ * Abstract super class for all possible Java types, namely basic types such as int, object types like String and array
* types, e.g. int[]
- * @LastModified: May 2021
+ * @LastModified: Sept 2025
*/
public abstract class Type {
@@ -88,15 +90,15 @@ public abstract class Type {
// Skip any type arguments to read argument declarations between '(' and ')'
index = signature.indexOf('(') + 1;
if (index <= 0) {
- throw new ClassFormatException("Invalid method signature: " + signature);
+ throw new InvalidMethodSignatureException(signature);
}
while (signature.charAt(index) != ')') {
vec.add(getType(signature.substring(index)));
- // corrected concurrent private static field acess
+ // corrected concurrent private static field access
index += unwrap(CONSUMED_CHARS); // update position
}
} catch (final StringIndexOutOfBoundsException e) { // Should never occur
- throw new ClassFormatException("Invalid method signature: " + signature, e);
+ throw new InvalidMethodSignatureException(signature, e);
}
final Type[] types = new Type[vec.size()];
vec.toArray(types);
@@ -110,7 +112,7 @@ public abstract class Type {
// Skip any type arguments to read argument declarations between '(' and ')'
index = signature.indexOf('(') + 1;
if (index <= 0) {
- throw new ClassFormatException("Invalid method signature: " + signature);
+ throw new InvalidMethodSignatureException(signature);
}
while (signature.charAt(index) != ')') {
final int coded = getTypeSize(signature.substring(index));
@@ -118,7 +120,7 @@ public abstract class Type {
index += consumed(coded);
}
} catch (final StringIndexOutOfBoundsException e) { // Should never occur
- throw new ClassFormatException("Invalid method signature: " + signature, e);
+ throw new InvalidMethodSignatureException(signature, e);
}
return res;
}
@@ -154,13 +156,13 @@ public abstract class Type {
final int index = signature.lastIndexOf(')') + 1;
return getType(signature.substring(index));
} catch (final StringIndexOutOfBoundsException e) { // Should never occur
- throw new ClassFormatException("Invalid method signature: " + signature, e);
+ throw new InvalidMethodSignatureException(signature, e);
}
}
static int getReturnTypeSize(final String signature) {
final int index = signature.lastIndexOf(')') + 1;
- return Type.size(getTypeSize(signature.substring(index)));
+ return size(getTypeSize(signature.substring(index)));
}
public static String getSignature(final java.lang.reflect.Method meth) {
@@ -175,7 +177,7 @@ public abstract class Type {
}
/**
- * Convert runtime java.lang.Class to BCEL Type object.
+ * Convert runtime {@link Class} to BCEL Type object.
*
* @param cls Java class
* @return corresponding Type object
@@ -183,7 +185,7 @@ public abstract class Type {
public static Type getType(final Class> cls) {
Objects.requireNonNull(cls, "cls");
/*
- * That's an amzingly easy case, because getName() returns the signature. That's what we would have liked anyway.
+ * That's an amazingly easy case, because getName() returns the signature. That's what we would have liked anyway.
*/
if (cls.isArray()) {
return getType(cls.getName());
@@ -230,7 +232,7 @@ public abstract class Type {
public static Type getType(final String signature) throws StringIndexOutOfBoundsException {
final byte type = Utility.typeOfSignature(signature);
if (type <= Const.T_VOID) {
- // corrected concurrent private static field acess
+ // corrected concurrent private static field access
wrap(CONSUMED_CHARS, 1);
return BasicType.getType(type);
}
@@ -246,7 +248,7 @@ public abstract class Type {
} while (signature.charAt(dim) == '[');
// Recurse, but just once, if the signature is ok
final Type t = getType(signature.substring(dim));
- // corrected concurrent private static field acess
+ // corrected concurrent private static field access
// consumed_chars += dim; // update counter - is replaced by
final int temp = unwrap(CONSUMED_CHARS) + dim;
wrap(CONSUMED_CHARS, temp);
@@ -254,7 +256,7 @@ public abstract class Type {
}
/**
- * Convert runtime java.lang.Class[] to BCEL Type objects.
+ * Convert runtime {@code java.lang.Class[]} to BCEL Type objects.
*
* @param classes an array of runtime class objects
* @return array of corresponding Type objects
@@ -286,6 +288,24 @@ public abstract class Type {
return encode(1, index + 1);
}
+ static String internalTypeNameToSignature(final String internalTypeName) {
+ if (Utils.isEmpty(internalTypeName) || Arrays.asList(Const.SHORT_TYPE_NAMES).contains(internalTypeName)) {
+ return internalTypeName;
+ }
+ switch (internalTypeName.charAt(0)) {
+ case '[':
+ return internalTypeName;
+ case 'L':
+ case 'T':
+ if (internalTypeName.charAt(internalTypeName.length() - 1) == ';') {
+ return internalTypeName;
+ }
+ return 'L' + internalTypeName + ';';
+ default:
+ return 'L' + internalTypeName + ';';
+ }
+ }
+
static int size(final int coded) {
return coded & 3;
}
@@ -361,7 +381,7 @@ public abstract class Type {
}
/**
- * @return hashcode of Type
+ * @return hash code of Type
*/
@Override
public int hashCode() {
@@ -369,31 +389,23 @@ public abstract class Type {
}
/**
- * boolean, short and char variable are considered as int in the stack or local variable area. Returns {@link Type#INT}
- * for {@link Type#BOOLEAN}, {@link Type#SHORT} or {@link Type#CHAR}, otherwise returns the given type.
+ * boolean, short and char variable are considered as int in the stack or local variable area. Returns {@link #INT}
+ * for {@link #BOOLEAN}, {@link #SHORT} or {@link #CHAR}, otherwise returns the given type.
*
* @since 6.0
*/
public Type normalizeForStackOrLocal() {
- if (this == Type.BOOLEAN || this == Type.BYTE || this == Type.SHORT || this == Type.CHAR) {
- return Type.INT;
+ if (this == BOOLEAN || this == BYTE || this == SHORT || this == CHAR) {
+ return INT;
}
return this;
}
- /*
- * Currently only used by the ArrayType constructor. The signature has a complicated dependency on other parameter so
- * it's tricky to do it in a call to the super ctor.
- */
- void setSignature(final String signature) {
- this.signature = signature;
- }
-
/**
* @return Type string, e.g. 'int[]'
*/
@Override
public String toString() {
- return this.equals(Type.NULL) || type >= Const.T_UNKNOWN ? signature : Utility.signatureToString(signature, false);
+ return equals(NULL) || type >= Const.T_UNKNOWN ? signature : Utility.signatureToString(signature, false);
}
}
diff --git a/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/generic/TypedInstruction.java b/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/generic/TypedInstruction.java
index 5a22942a6a7..27b952f3996 100644
--- a/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/generic/TypedInstruction.java
+++ b/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/generic/TypedInstruction.java
@@ -22,7 +22,7 @@
package com.sun.org.apache.bcel.internal.generic;
/**
- * Get the type associated with an instruction, int for ILOAD, or the type of the field of a PUTFIELD instruction, e.g..
+ * Gets the type associated with an instruction, int for ILOAD, or the type of the field of a PUTFIELD instruction, e.g..
*/
public interface TypedInstruction {
diff --git a/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/generic/package-info.java b/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/generic/package-info.java
new file mode 100644
index 00000000000..63d4dc876ce
--- /dev/null
+++ b/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/generic/package-info.java
@@ -0,0 +1,26 @@
+/*
+ * reserved comment block
+ * DO NOT REMOVE OR ALTER!
+ */
+/*
+ * 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.
+ */
+
+/**
+ * Generic part of the Apache Byte Code Engineering Library (BCEL), classes to dynamically modify class objects
+ * and byte code instructions.
+ */
+package com.sun.org.apache.bcel.internal.generic;
diff --git a/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/package-info.java b/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/package-info.java
new file mode 100644
index 00000000000..581037d7981
--- /dev/null
+++ b/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/package-info.java
@@ -0,0 +1,26 @@
+/*
+ * reserved comment block
+ * DO NOT REMOVE OR ALTER!
+ */
+/*
+ * 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.
+ */
+
+/**
+ * Basic classes for the Apache Byte Code Engineering Library (BCEL) and constants defined by the
+ * JVM specification.
+ */
+package com.sun.org.apache.bcel.internal;
diff --git a/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/util/BCELComparator.java b/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/util/BCELComparator.java
index 2e663bfdaa1..fb32dc35e0b 100644
--- a/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/util/BCELComparator.java
+++ b/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/util/BCELComparator.java
@@ -22,26 +22,27 @@
package com.sun.org.apache.bcel.internal.util;
/**
- * Used for BCEL comparison strategy
+ * Used for BCEL comparison strategy.
*
+ * @param What type we are comparing.
* @since 5.2
*/
-public interface BCELComparator {
+public interface BCELComparator {
/**
- * Compare two objects and return what THIS.equals(THAT) should return
+ * Compares two objects and return what a.equals(b) should return.
*
- * @param THIS
- * @param THAT
- * @return true if and only if THIS equals THAT
+ * @param a an object.
+ * @param b an object to be compared with {@code a} for equality.
+ * @return {@code true} if the arguments are equal to each other and {@code false} otherwise.
*/
- boolean equals(Object THIS, Object THAT);
+ boolean equals(T a, T b);
/**
- * Return hashcode for THIS.hashCode()
+ * Gets the hash code for o.hashCode()
*
- * @param THIS
- * @return hashcode for THIS.hashCode()
+ * @param o
+ * @return hash code for o.hashCode()
*/
- int hashCode(Object THIS);
+ int hashCode(T o);
}
diff --git a/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/util/BCELFactory.java b/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/util/BCELFactory.java
index c931fb1e422..93f22e7d0ad 100644
--- a/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/util/BCELFactory.java
+++ b/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/util/BCELFactory.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2017, 2023, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2017, 2025, Oracle and/or its affiliates. All rights reserved.
*/
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
@@ -63,9 +63,9 @@ import com.sun.org.apache.bcel.internal.generic.Type;
* Factory creates il.append() statements, and sets instruction targets. A helper class for BCELifier.
*
* @see BCELifier
- * @LastModified: Feb 2023
+ * @LastModified: Sept 2025
*/
-class BCELFactory extends EmptyVisitor {
+final class BCELFactory extends EmptyVisitor {
private static final String CONSTANT_PREFIX = Const.class.getSimpleName() + ".";
private final MethodGen methodGen;
@@ -88,7 +88,7 @@ class BCELFactory extends EmptyVisitor {
if (value instanceof String) {
embed = '"' + Utility.convertString(embed) + '"';
} else if (value instanceof Character) {
- embed = "(char)0x" + Integer.toHexString(((Character) value).charValue());
+ embed = "(char) 0x" + Integer.toHexString(((Character) value).charValue());
} else if (value instanceof Float) {
final Float f = (Float) value;
if (Float.isNaN(f)) {
diff --git a/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/util/BCELifier.java b/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/util/BCELifier.java
index 151083ea71b..0eb9bfb4ee1 100644
--- a/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/util/BCELifier.java
+++ b/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/util/BCELifier.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2023, 2025, Oracle and/or its affiliates. All rights reserved.
*/
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
@@ -30,11 +30,15 @@ import java.util.Locale;
import com.sun.org.apache.bcel.internal.Const;
import com.sun.org.apache.bcel.internal.Repository;
import com.sun.org.apache.bcel.internal.classfile.ClassParser;
+import com.sun.org.apache.bcel.internal.classfile.Code;
import com.sun.org.apache.bcel.internal.classfile.ConstantValue;
import com.sun.org.apache.bcel.internal.classfile.ExceptionTable;
import com.sun.org.apache.bcel.internal.classfile.Field;
import com.sun.org.apache.bcel.internal.classfile.JavaClass;
import com.sun.org.apache.bcel.internal.classfile.Method;
+import com.sun.org.apache.bcel.internal.classfile.StackMap;
+import com.sun.org.apache.bcel.internal.classfile.StackMapEntry;
+import com.sun.org.apache.bcel.internal.classfile.StackMapType;
import com.sun.org.apache.bcel.internal.classfile.Utility;
import com.sun.org.apache.bcel.internal.generic.ArrayType;
import com.sun.org.apache.bcel.internal.generic.ConstantPoolGen;
@@ -46,7 +50,7 @@ import com.sun.org.apache.bcel.internal.generic.Type;
* This gives new users of BCEL a useful example showing how things are done with BCEL. It does not cover all features
* of BCEL, but tries to mimic hand-written code as close as possible.
*
- * @LastModified: Feb 2023
+ * @LastModified: Sept 2025
*/
public class BCELifier extends com.sun.org.apache.bcel.internal.classfile.EmptyVisitor {
@@ -74,7 +78,7 @@ public class BCELifier extends com.sun.org.apache.bcel.internal.classfile.EmptyV
/**
* Default main method
*/
- public static void _main(final String[] argv) throws Exception {
+ public static void main(final String[] argv) throws Exception {
if (argv.length != 1) {
System.out.println("Usage: BCELifier className");
System.out.println("\tThe class must exist on the classpath");
@@ -311,6 +315,13 @@ public class BCELifier extends com.sun.org.apache.bcel.internal.classfile.EmptyV
printWriter.println("\");");
}
}
+ final Code code = method.getCode();
+ if (code != null) {
+ final StackMap stackMap = code.getStackMap();
+ if (stackMap != null) {
+ stackMap.accept(this);
+ }
+ }
printWriter.println();
final BCELFactory factory = new BCELFactory(mg, printWriter);
factory.start();
@@ -319,4 +330,78 @@ public class BCELifier extends com.sun.org.apache.bcel.internal.classfile.EmptyV
printWriter.println(" _cg.addMethod(method.getMethod());");
printWriter.println(" il.dispose();");
}
+
+ @Override
+ public void visitStackMap(final StackMap stackMap) {
+ super.visitStackMap(stackMap);
+ printWriter.print(" method.addCodeAttribute(");
+ printWriter.print("new StackMap(_cp.addUtf8(\"");
+ printWriter.print(stackMap.getName());
+ printWriter.print("\"), ");
+ printWriter.print(stackMap.getLength());
+ printWriter.print(", ");
+ printWriter.print("new StackMapEntry[] {");
+ final StackMapEntry[] table = stackMap.getStackMap();
+ for (int i = 0; i < table.length; i++) {
+ table[i].accept(this);
+ if (i < table.length - 1) {
+ printWriter.print(", ");
+ } else {
+ printWriter.print(" }");
+ }
+ }
+ printWriter.print(", _cp.getConstantPool())");
+ printWriter.println(");");
+ }
+
+ @Override
+ public void visitStackMapEntry(final StackMapEntry stackMapEntry) {
+ super.visitStackMapEntry(stackMapEntry);
+ printWriter.print("new StackMapEntry(");
+ printWriter.print(stackMapEntry.getFrameType());
+ printWriter.print(", ");
+ printWriter.print(stackMapEntry.getByteCodeOffset());
+ printWriter.print(", ");
+ visitStackMapTypeArray(stackMapEntry.getTypesOfLocals());
+ printWriter.print(", ");
+ visitStackMapTypeArray(stackMapEntry.getTypesOfStackItems());
+ printWriter.print(", _cp.getConstantPool())");
+ }
+
+ /**
+ * Visits a {@link StackMapType} object.
+ * @param stackMapType object to visit
+ * @since 6.7.1
+ */
+ @Override
+ public void visitStackMapType(final StackMapType stackMapType) {
+ super.visitStackMapType(stackMapType);
+ printWriter.print("new StackMapType((byte)");
+ printWriter.print(stackMapType.getType());
+ printWriter.print(", ");
+ if (stackMapType.hasIndex()) {
+ printWriter.print("_cp.addClass(\"");
+ printWriter.print(stackMapType.getClassName());
+ printWriter.print("\")");
+ } else {
+ printWriter.print("-1");
+ }
+ printWriter.print(", _cp.getConstantPool())");
+ }
+
+ private void visitStackMapTypeArray(final StackMapType[] types) {
+ if (types == null || types.length == 0) {
+ printWriter.print("null"); // null translates to StackMapType.EMPTY_ARRAY
+ } else {
+ printWriter.print("new StackMapType[] {");
+ for (int i = 0; i < types.length; i++) {
+ types[i].accept(this);
+ if (i < types.length - 1) {
+ printWriter.print(", ");
+ } else {
+ printWriter.print(" }");
+ }
+ }
+ }
+ }
}
diff --git a/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/util/Class2HTML.java b/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/util/Class2HTML.java
index f644c698b72..10d31974d47 100644
--- a/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/util/Class2HTML.java
+++ b/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/util/Class2HTML.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2017, 2023, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2017, 2025, Oracle and/or its affiliates. All rights reserved.
*/
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
@@ -53,7 +53,7 @@ import com.sun.org.apache.bcel.internal.classfile.Utility;
* All subfiles reference each other appropriately, e.g. clicking on a method in the Method's frame will jump to the
* appropriate method in the Code frame.
*
- * @LastModified: Feb 2023
+ * @LastModified: Sept 2025
*/
public class Class2HTML {
@@ -73,7 +73,7 @@ public class Class2HTML {
basicTypes.add("float");
}
- public static void _main(final String[] argv) throws IOException {
+ public static void main(final String[] argv) throws IOException {
final String[] fileName = new String[argv.length];
int files = 0;
ClassParser parser = null;
@@ -89,7 +89,7 @@ public class Class2HTML {
if (argv[i].equals("-d")) { // Specify target directory, default '.'
dir = argv[++i];
if (!dir.endsWith("" + sep)) {
- dir = dir + sep;
+ dir += sep;
}
final File store = new File(dir);
if (!store.isDirectory()) {
@@ -115,7 +115,7 @@ public class Class2HTML {
if (zipFile == null) {
parser = new ClassParser(fileName[i]); // Create parser object from file
} else {
- parser = new ClassParser(zipFile, fileName[i]); // Create parser object from zip file
+ parser = new ClassParser(zipFile, fileName[i]); // Create parser object from ZIP file
}
javaClass = parser.parse();
new Class2HTML(javaClass, dir);
diff --git a/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/util/ClassSet.java b/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/util/ClassSet.java
index 178ccc786b1..e95e8fbd0a0 100644
--- a/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/util/ClassSet.java
+++ b/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/util/ClassSet.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2023, 2025, Oracle and/or its affiliates. All rights reserved.
*/
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
@@ -30,7 +30,7 @@ import com.sun.org.apache.bcel.internal.classfile.JavaClass;
* Utility class implementing a (type-safe) set of JavaClass objects. Since JavaClass has no equals() method, the name of the class is used for comparison.
*
* @see ClassStack
- * @LastModified: Feb 2023
+ * @LastModified: Sept 2025
*/
public class ClassSet {
diff --git a/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/util/CodeHTML.java b/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/util/CodeHTML.java
index 723fc07509b..1935d724b3b 100644
--- a/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/util/CodeHTML.java
+++ b/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/util/CodeHTML.java
@@ -542,7 +542,7 @@ final class CodeHTML {
final String str = codeToHTML(stream, methodNumber);
String anchor = "";
/*
- * Set an anchor mark if this line is targetted by a goto, jsr, etc. Defining an anchor for every line is very
+ * Sets an anchor mark if this line is targetted by a goto, jsr, etc. Defining an anchor for every line is very
* inefficient!
*/
if (gotoSet.get(offset)) {
diff --git a/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/util/InstructionFinder.java b/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/util/InstructionFinder.java
index 5b045bf08cc..510fe4a03a6 100644
--- a/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/util/InstructionFinder.java
+++ b/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/util/InstructionFinder.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2017, 2021, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2017, 2025, Oracle and/or its affiliates. All rights reserved.
*/
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
@@ -63,14 +63,13 @@ import com.sun.org.apache.bcel.internal.generic.InstructionList;
*
* @see com.sun.org.apache.bcel.internal.generic.Instruction
* @see InstructionList
- * @LastModified: May 2021
+ * @LastModified: Sept 2025
*/
public class InstructionFinder {
/**
* Code patterns found may be checked using an additional user-defined constraint object whether they really match the
* needed criterion. I.e., check constraints that can not expressed with regular expressions.
- *
*/
public interface CodeConstraint {
@@ -374,7 +373,7 @@ public class InstructionFinder {
// }
// private static final String pattern2string( String pattern, boolean make_string ) {
-// StringBuffer buf = new StringBuffer();
+// StringBuilder buf = new StringBuilder();
// for (int i = 0; i < pattern.length(); i++) {
// char ch = pattern.charAt(i);
// if (ch >= OFFSET) {
diff --git a/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/util/Repository.java b/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/util/Repository.java
index 8d1ddf493cd..c44e36d0a81 100644
--- a/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/util/Repository.java
+++ b/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/util/Repository.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2017, 2023, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2017, 2025, Oracle and/or its affiliates. All rights reserved.
*/
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
@@ -25,8 +25,8 @@ import com.sun.org.apache.bcel.internal.classfile.JavaClass;
* Abstract definition of a class repository. Instances may be used to load classes from different sources and may be
* used in the Repository.setRepository method.
*
- * @see org.apache.bcel.Repository
- * @LastModified: Feb 2023
+ * @see com.sun.org.apache.bcel.internal.Repository
+ * @LastModified: Sept 2025
*/
public interface Repository {
diff --git a/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/util/package-info.java b/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/util/package-info.java
new file mode 100644
index 00000000000..2bd92f155bc
--- /dev/null
+++ b/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/util/package-info.java
@@ -0,0 +1,32 @@
+/*
+ * reserved comment block
+ * DO NOT REMOVE OR ALTER!
+ */
+/*
+ * 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.
+ */
+
+/**
+ * Utility classes for the Apache Byte Code Engineering Library (BCEL), namely:
+ *
+ * - Collection classes for JavaClass objects
+ * - A converter for class files to HTML
+ * - A tool to find instructions patterns via regular expressions
+ * - A class to find classes as defined in the CLASSPATH
+ * - A class loader that allows to create classes at run time
+ *
+ */
+package com.sun.org.apache.bcel.internal.util;
diff --git a/src/java.xml/share/classes/jdk/xml/internal/Utils.java b/src/java.xml/share/classes/jdk/xml/internal/Utils.java
index f55ab95a58f..96d9b1b9521 100644
--- a/src/java.xml/share/classes/jdk/xml/internal/Utils.java
+++ b/src/java.xml/share/classes/jdk/xml/internal/Utils.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2023, 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2023, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -25,8 +25,11 @@
package jdk.xml.internal;
+import java.lang.reflect.Array;
import java.util.Arrays;
+import java.util.Objects;
import java.util.function.Supplier;
+import java.util.stream.Stream;
/**
* General utility. Use JdkXmlUtils for XML processing related functions.
@@ -76,4 +79,59 @@ public class Utils {
System.arraycopy(items, 0, result, original.length, items.length);
return result;
}
+
+ /**
+ * Returns the original array, or an empty array if it is {@code null}.
+ * @param array the specified array
+ * @return the original array, or an empty array if it is {@code null}
+ */
+ public static byte[] createEmptyArrayIfNull(byte[] array) {
+ return (array != null) ? array : new byte[0];
+ }
+
+ /**
+ * Returns the original array, or an empty array if it is {@code null}.
+ * @param array the specified array
+ * @return the original array, or an empty array if it is {@code null}
+ */
+ public static int[] createEmptyArrayIfNull(int[] array) {
+ return (array != null) ? array : new int[0];
+ }
+
+ /**
+ * Returns the original array, or an empty array if it is {@code null}.
+ * @param the class type
+ * @param array the specified array
+ * @param type the type of the array
+ * @return the original array, or an empty array if it is {@code null}
+ */
+ public static T[] createEmptyArrayIfNull(final T[] array, final Class type) {
+ Objects.requireNonNull(type, "The type argument should not be null.");
+
+ return (array != null) ? array : type.cast(Array.newInstance(type.getComponentType(), 0));
+ }
+
+ /**
+ * Returns the new stream created by {@code Stream.of(values)} or an empty
+ * sequential stream created by {@code Stream.empty()} if values is null.
+ *
+ * @param the type of stream elements
+ * @param values the elements of the new stream
+ * @return the new stream created by {@code Stream.of(values)} or an empty
+ * sequential stream created by {@code Stream.empty()} if values is null.
+ */
+ @SafeVarargs
+ @SuppressWarnings("varargs") // Creating a stream from an array is safe
+ public static Stream streamOfIfNonNull(final T... values) {
+ return values == null ? Stream.empty() : Stream.of(values);
+ }
+
+ /**
+ * Checks if a CharSequence is empty ("") or null.
+ * @param cs the CharSequence to check, may be null
+ * @return {@code true} if the CharSequence is empty or null
+ */
+ public static boolean isEmpty(final CharSequence cs) {
+ return cs == null || cs.length() == 0;
+ }
}
diff --git a/src/java.xml/share/legal/bcel.md b/src/java.xml/share/legal/bcel.md
index 2c673d6b1af..b64fc3640d4 100644
--- a/src/java.xml/share/legal/bcel.md
+++ b/src/java.xml/share/legal/bcel.md
@@ -1,4 +1,4 @@
-## Apache Commons Byte Code Engineering Library (BCEL) Version 6.7.0
+## Apache Commons Byte Code Engineering Library (BCEL) Version 6.10.0
### Apache Commons BCEL Notice