Skip to content

Commit 7025c3b

Browse files
committed
Upgrade to ASM 9.4
Closes gh-29305
1 parent 313b53a commit 7025c3b

12 files changed

+113
-52
lines changed

spring-core/src/main/java/org/springframework/asm/AnnotationVisitor.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,17 @@ protected AnnotationVisitor(final int api, final AnnotationVisitor annotationVis
8282
this.av = annotationVisitor;
8383
}
8484

85+
/**
86+
* The annotation visitor to which this visitor must delegate method calls. May be {@literal
87+
* null}.
88+
*
89+
* @return the annotation visitor to which this visitor must delegate method calls, or {@literal
90+
* null}.
91+
*/
92+
public AnnotationVisitor getDelegate() {
93+
return av;
94+
}
95+
8596
/**
8697
* Visits a primitive value of the annotation.
8798
*

spring-core/src/main/java/org/springframework/asm/ClassReader.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ public ClassReader(
194194
this.b = classFileBuffer;
195195
// Check the class' major_version. This field is after the magic and minor_version fields, which
196196
// use 4 and 2 bytes respectively.
197-
if (checkClassVersion && readShort(classFileOffset + 6) > Opcodes.V19) {
197+
if (checkClassVersion && readShort(classFileOffset + 6) > Opcodes.V20) {
198198
throw new IllegalArgumentException(
199199
"Unsupported class file major version " + readShort(classFileOffset + 6));
200200
}
@@ -308,6 +308,7 @@ public ClassReader(final String className) throws IOException {
308308
* @return the content of the given input stream.
309309
* @throws IOException if a problem occurs during reading.
310310
*/
311+
@SuppressWarnings("PMD.UseTryWithResources")
311312
private static byte[] readStream(final InputStream inputStream, final boolean close)
312313
throws IOException {
313314
if (inputStream == null) {
@@ -376,7 +377,7 @@ public String getClassName() {
376377
}
377378

378379
/**
379-
* Returns the internal of name of the super class (see {@link Type#getInternalName()}). For
380+
* Returns the internal name of the super class (see {@link Type#getInternalName()}). For
380381
* interfaces, the super class is {@link Object}.
381382
*
382383
* @return the internal name of the super class, or {@literal null} for {@link Object} class.

spring-core/src/main/java/org/springframework/asm/ClassTooLargeException.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ public final class ClassTooLargeException extends IndexOutOfBoundsException {
4242
/**
4343
* Constructs a new {@link ClassTooLargeException}.
4444
*
45-
* @param className the internal name of the class.
45+
* @param className the internal name of the class (see {@link
46+
* org.objectweb.asm.Type#getInternalName()}).
4647
* @param constantPoolCount the number of constant pool items of the class.
4748
*/
4849
public ClassTooLargeException(final String className, final int constantPoolCount) {
@@ -52,7 +53,7 @@ public ClassTooLargeException(final String className, final int constantPoolCoun
5253
}
5354

5455
/**
55-
* Returns the internal name of the class.
56+
* Returns the internal name of the class (see {@link org.objectweb.asm.Type#getInternalName()}).
5657
*
5758
* @return the internal name of the class.
5859
*/

spring-core/src/main/java/org/springframework/asm/ClassVisitor.java

Lines changed: 35 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,15 @@ protected ClassVisitor(final int api, final ClassVisitor classVisitor) {
8181
this.cv = classVisitor;
8282
}
8383

84+
/**
85+
* The class visitor to which this visitor must delegate method calls. May be {@literal null}.
86+
*
87+
* @return the class visitor to which this visitor must delegate method calls, or {@literal null}.
88+
*/
89+
public ClassVisitor getDelegate() {
90+
return cv;
91+
}
92+
8493
/**
8594
* Visits the header of the class.
8695
*
@@ -155,7 +164,8 @@ public ModuleVisitor visitModule(final String name, final int access, final Stri
155164
* implicitly its own nest, so it's invalid to call this method with the visited class name as
156165
* argument.
157166
*
158-
* @param nestHost the internal name of the host class of the nest.
167+
* @param nestHost the internal name of the host class of the nest (see {@link
168+
* Type#getInternalName()}).
159169
*/
160170
public void visitNestHost(final String nestHost) {
161171
if (api < Opcodes.ASM7) {
@@ -167,14 +177,19 @@ public void visitNestHost(final String nestHost) {
167177
}
168178

169179
/**
170-
* Visits the enclosing class of the class. This method must be called only if the class has an
171-
* enclosing class.
180+
* Visits the enclosing class of the class. This method must be called only if this class is a
181+
* local or anonymous class. See the JVMS 4.7.7 section for more details.
172182
*
173-
* @param owner internal name of the enclosing class of the class.
183+
* @param owner internal name of the enclosing class of the class (see {@link
184+
* Type#getInternalName()}).
174185
* @param name the name of the method that contains the class, or {@literal null} if the class is
175-
* not enclosed in a method of its enclosing class.
186+
* not enclosed in a method or constructor of its enclosing class (e.g. if it is enclosed in
187+
* an instance initializer, static initializer, instance variable initializer, or class
188+
* variable initializer).
176189
* @param descriptor the descriptor of the method that contains the class, or {@literal null} if
177-
* the class is not enclosed in a method of its enclosing class.
190+
* the class is not enclosed in a method or constructor of its enclosing class (e.g. if it is
191+
* enclosed in an instance initializer, static initializer, instance variable initializer, or
192+
* class variable initializer).
178193
*/
179194
public void visitOuterClass(final String owner, final String name, final String descriptor) {
180195
if (cv != null) {
@@ -241,7 +256,7 @@ public void visitAttribute(final Attribute attribute) {
241256
* the visited class is the host of a nest. A nest host is implicitly a member of its own nest, so
242257
* it's invalid to call this method with the visited class name as argument.
243258
*
244-
* @param nestMember the internal name of a nest member.
259+
* @param nestMember the internal name of a nest member (see {@link Type#getInternalName()}).
245260
*/
246261
public void visitNestMember(final String nestMember) {
247262
if (api < Opcodes.ASM7) {
@@ -256,7 +271,8 @@ public void visitNestMember(final String nestMember) {
256271
* Visits a permitted subclasses. A permitted subclass is one of the allowed subclasses of the
257272
* current class.
258273
*
259-
* @param permittedSubclass the internal name of a permitted subclass.
274+
* @param permittedSubclass the internal name of a permitted subclass (see {@link
275+
* Type#getInternalName()}).
260276
*/
261277
public void visitPermittedSubclass(final String permittedSubclass) {
262278
if (api < Opcodes.ASM9) {
@@ -269,15 +285,18 @@ public void visitPermittedSubclass(final String permittedSubclass) {
269285

270286
/**
271287
* Visits information about an inner class. This inner class is not necessarily a member of the
272-
* class being visited.
288+
* class being visited. More precisely, every class or interface C which is referenced by this
289+
* class and which is not a package member must be visited with this method. This class must
290+
* reference its nested class or interface members, and its enclosing class, if any. See the JVMS
291+
* 4.7.6 section for more details.
273292
*
274-
* @param name the internal name of an inner class (see {@link Type#getInternalName()}).
275-
* @param outerName the internal name of the class to which the inner class belongs (see {@link
276-
* Type#getInternalName()}). May be {@literal null} for not member classes.
277-
* @param innerName the (simple) name of the inner class inside its enclosing class. May be
278-
* {@literal null} for anonymous inner classes.
279-
* @param access the access flags of the inner class as originally declared in the enclosing
280-
* class.
293+
* @param name the internal name of C (see {@link Type#getInternalName()}).
294+
* @param outerName the internal name of the class or interface C is a member of (see {@link
295+
* Type#getInternalName()}). Must be {@literal null} if C is not the member of a class or
296+
* interface (e.g. for local or anonymous classes).
297+
* @param innerName the (simple) name of C. Must be {@literal null} for anonymous inner classes.
298+
* @param access the access flags of C originally declared in the source code from which this
299+
* class was compiled.
281300
*/
282301
public void visitInnerClass(
283302
final String name, final String outerName, final String innerName, final int access) {

spring-core/src/main/java/org/springframework/asm/ClassWriter.java

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -842,7 +842,7 @@ public int newUTF8(final String value) {
842842
* constant pool already contains a similar item. <i>This method is intended for {@link Attribute}
843843
* sub classes, and is normally not needed by class generators or adapters.</i>
844844
*
845-
* @param value the internal name of the class.
845+
* @param value the internal name of the class (see {@link Type#getInternalName()}).
846846
* @return the index of a new or already existing class reference item.
847847
*/
848848
public int newClass(final String value) {
@@ -894,7 +894,8 @@ public int newPackage(final String packageName) {
894894
* Opcodes#H_GETSTATIC}, {@link Opcodes#H_PUTFIELD}, {@link Opcodes#H_PUTSTATIC}, {@link
895895
* Opcodes#H_INVOKEVIRTUAL}, {@link Opcodes#H_INVOKESTATIC}, {@link Opcodes#H_INVOKESPECIAL},
896896
* {@link Opcodes#H_NEWINVOKESPECIAL} or {@link Opcodes#H_INVOKEINTERFACE}.
897-
* @param owner the internal name of the field or method owner class.
897+
* @param owner the internal name of the field or method owner class (see {@link
898+
* Type#getInternalName()}).
898899
* @param name the name of the field or method.
899900
* @param descriptor the descriptor of the field or method.
900901
* @return the index of a new or already existing method type reference item.
@@ -916,7 +917,8 @@ public int newHandle(
916917
* Opcodes#H_GETSTATIC}, {@link Opcodes#H_PUTFIELD}, {@link Opcodes#H_PUTSTATIC}, {@link
917918
* Opcodes#H_INVOKEVIRTUAL}, {@link Opcodes#H_INVOKESTATIC}, {@link Opcodes#H_INVOKESPECIAL},
918919
* {@link Opcodes#H_NEWINVOKESPECIAL} or {@link Opcodes#H_INVOKEINTERFACE}.
919-
* @param owner the internal name of the field or method owner class.
920+
* @param owner the internal name of the field or method owner class (see {@link
921+
* Type#getInternalName()}).
920922
* @param name the name of the field or method.
921923
* @param descriptor the descriptor of the field or method.
922924
* @param isInterface true if the owner is an interface.
@@ -978,7 +980,7 @@ public int newInvokeDynamic(
978980
* constant pool already contains a similar item. <i>This method is intended for {@link Attribute}
979981
* sub classes, and is normally not needed by class generators or adapters.</i>
980982
*
981-
* @param owner the internal name of the field's owner class.
983+
* @param owner the internal name of the field's owner class (see {@link Type#getInternalName()}).
982984
* @param name the field's name.
983985
* @param descriptor the field's descriptor.
984986
* @return the index of a new or already existing field reference item.
@@ -992,7 +994,8 @@ public int newField(final String owner, final String name, final String descript
992994
* constant pool already contains a similar item. <i>This method is intended for {@link Attribute}
993995
* sub classes, and is normally not needed by class generators or adapters.</i>
994996
*
995-
* @param owner the internal name of the method's owner class.
997+
* @param owner the internal name of the method's owner class (see {@link
998+
* Type#getInternalName()}).
996999
* @param name the method's name.
9971000
* @param descriptor the method's descriptor.
9981001
* @param isInterface {@literal true} if {@code owner} is an interface.
@@ -1028,9 +1031,10 @@ public int newNameType(final String name, final String descriptor) {
10281031
* currently being generated by this ClassWriter, which can of course not be loaded since it is
10291032
* under construction.
10301033
*
1031-
* @param type1 the internal name of a class.
1032-
* @param type2 the internal name of another class.
1033-
* @return the internal name of the common super class of the two given classes.
1034+
* @param type1 the internal name of a class (see {@link Type#getInternalName()}).
1035+
* @param type2 the internal name of another class (see {@link Type#getInternalName()}).
1036+
* @return the internal name of the common super class of the two given classes (see {@link
1037+
* Type#getInternalName()}).
10341038
*/
10351039
protected String getCommonSuperClass(final String type1, final String type2) {
10361040
ClassLoader classLoader = getClassLoader();

spring-core/src/main/java/org/springframework/asm/FieldVisitor.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,15 @@ protected FieldVisitor(final int api, final FieldVisitor fieldVisitor) {
7878
this.fv = fieldVisitor;
7979
}
8080

81+
/**
82+
* The field visitor to which this visitor must delegate method calls. May be {@literal null}.
83+
*
84+
* @return the field visitor to which this visitor must delegate method calls, or {@literal null}.
85+
*/
86+
public FieldVisitor getDelegate() {
87+
return fv;
88+
}
89+
8190
/**
8291
* Visits an annotation of the field.
8392
*

spring-core/src/main/java/org/springframework/asm/Handle.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public final class Handle {
6565
* {@link Opcodes#H_INVOKESPECIAL}, {@link Opcodes#H_NEWINVOKESPECIAL} or {@link
6666
* Opcodes#H_INVOKEINTERFACE}.
6767
* @param owner the internal name of the class that owns the field or method designated by this
68-
* handle.
68+
* handle (see {@link Type#getInternalName()}).
6969
* @param name the name of the field or method designated by this handle.
7070
* @param descriptor the descriptor of the field or method designated by this handle.
7171
* @deprecated this constructor has been superseded by {@link #Handle(int, String, String, String,
@@ -85,7 +85,7 @@ public Handle(final int tag, final String owner, final String name, final String
8585
* {@link Opcodes#H_INVOKESPECIAL}, {@link Opcodes#H_NEWINVOKESPECIAL} or {@link
8686
* Opcodes#H_INVOKEINTERFACE}.
8787
* @param owner the internal name of the class that owns the field or method designated by this
88-
* handle.
88+
* handle (see {@link Type#getInternalName()}).
8989
* @param name the name of the field or method designated by this handle.
9090
* @param descriptor the descriptor of the field or method designated by this handle.
9191
* @param isInterface whether the owner is an interface or not.
@@ -118,7 +118,8 @@ public int getTag() {
118118
/**
119119
* Returns the internal name of the class that owns the field or method designated by this handle.
120120
*
121-
* @return the internal name of the class that owns the field or method designated by this handle.
121+
* @return the internal name of the class that owns the field or method designated by this handle
122+
* (see {@link Type#getInternalName()}).
122123
*/
123124
public String getOwner() {
124125
return owner;

spring-core/src/main/java/org/springframework/asm/MethodTooLargeException.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public final class MethodTooLargeException extends IndexOutOfBoundsException {
4444
/**
4545
* Constructs a new {@link MethodTooLargeException}.
4646
*
47-
* @param className the internal name of the owner class.
47+
* @param className the internal name of the owner class (see {@link Type#getInternalName()}).
4848
* @param methodName the name of the method.
4949
* @param descriptor the descriptor of the method.
5050
* @param codeSize the size of the method's Code attribute, in bytes.
@@ -64,7 +64,7 @@ public MethodTooLargeException(
6464
/**
6565
* Returns the internal name of the owner class.
6666
*
67-
* @return the internal name of the owner class.
67+
* @return the internal name of the owner class (see {@link Type#getInternalName()}).
6868
*/
6969
public String getClassName() {
7070
return className;

spring-core/src/main/java/org/springframework/asm/MethodVisitor.java

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,16 @@ protected MethodVisitor(final int api, final MethodVisitor methodVisitor) {
9494
this.mv = methodVisitor;
9595
}
9696

97+
/**
98+
* The method visitor to which this visitor must delegate method calls. May be {@literal null}.
99+
*
100+
* @return the method visitor to which this visitor must delegate method calls, or {@literal
101+
* null}.
102+
*/
103+
public MethodVisitor getDelegate() {
104+
return mv;
105+
}
106+
97107
// -----------------------------------------------------------------------------------------------
98108
// Parameters, annotations and non standard attributes
99109
// -----------------------------------------------------------------------------------------------
@@ -120,7 +130,7 @@ public void visitParameter(final String name, final int access) {
120130
* @return a visitor to the visit the actual default value of this annotation interface method, or
121131
* {@literal null} if this visitor is not interested in visiting this default value. The
122132
* 'name' parameters passed to the methods of this annotation visitor are ignored. Moreover,
123-
* exacly one visit method must be called on this annotation visitor, followed by visitEnd.
133+
* exactly one visit method must be called on this annotation visitor, followed by visitEnd.
124134
*/
125135
public AnnotationVisitor visitAnnotationDefault() {
126136
if (mv != null) {
@@ -273,15 +283,17 @@ public void visitCode() {
273283
* @param type the type of this stack map frame. Must be {@link Opcodes#F_NEW} for expanded
274284
* frames, or {@link Opcodes#F_FULL}, {@link Opcodes#F_APPEND}, {@link Opcodes#F_CHOP}, {@link
275285
* Opcodes#F_SAME} or {@link Opcodes#F_APPEND}, {@link Opcodes#F_SAME1} for compressed frames.
276-
* @param numLocal the number of local variables in the visited frame.
286+
* @param numLocal the number of local variables in the visited frame. Long and double values
287+
* count for one variable.
277288
* @param local the local variable types in this frame. This array must not be modified. Primitive
278289
* types are represented by {@link Opcodes#TOP}, {@link Opcodes#INTEGER}, {@link
279290
* Opcodes#FLOAT}, {@link Opcodes#LONG}, {@link Opcodes#DOUBLE}, {@link Opcodes#NULL} or
280291
* {@link Opcodes#UNINITIALIZED_THIS} (long and double are represented by a single element).
281-
* Reference types are represented by String objects (representing internal names), and
282-
* uninitialized types by Label objects (this label designates the NEW instruction that
283-
* created this uninitialized value).
284-
* @param numStack the number of operand stack elements in the visited frame.
292+
* Reference types are represented by String objects (representing internal names, see {@link
293+
* Type#getInternalName()}), and uninitialized types by Label objects (this label designates
294+
* the NEW instruction that created this uninitialized value).
295+
* @param numStack the number of operand stack elements in the visited frame. Long and double
296+
* values count for one stack element.
285297
* @param stack the operand stack types in this frame. This array must not be modified. Its
286298
* content has the same format as the "local" array.
287299
* @throws IllegalStateException if a frame is visited just after another one, without any
@@ -360,7 +372,7 @@ public void visitVarInsn(final int opcode, final int varIndex) {
360372

361373
/**
362374
* Visits a type instruction. A type instruction is an instruction that takes the internal name of
363-
* a class as parameter.
375+
* a class as parameter (see {@link Type#getInternalName()}).
364376
*
365377
* @param opcode the opcode of the type instruction to be visited. This opcode is either NEW,
366378
* ANEWARRAY, CHECKCAST or INSTANCEOF.
@@ -552,12 +564,12 @@ public void visitLdcInsn(final Object value) {
552564
/**
553565
* Visits an IINC instruction.
554566
*
555-
* @param var index of the local variable to be incremented.
567+
* @param varIndex index of the local variable to be incremented.
556568
* @param increment amount to increment the local variable by.
557569
*/
558-
public void visitIincInsn(final int var, final int increment) {
570+
public void visitIincInsn(final int varIndex, final int increment) {
559571
if (mv != null) {
560-
mv.visitIincInsn(var, increment);
572+
mv.visitIincInsn(varIndex, increment);
561573
}
562574
}
563575

@@ -643,8 +655,9 @@ public AnnotationVisitor visitInsnAnnotation(
643655
* @param start the beginning of the exception handler's scope (inclusive).
644656
* @param end the end of the exception handler's scope (exclusive).
645657
* @param handler the beginning of the exception handler's code.
646-
* @param type the internal name of the type of exceptions handled by the handler, or {@literal
647-
* null} to catch any exceptions (for "finally" blocks).
658+
* @param type the internal name of the type of exceptions handled by the handler (see {@link
659+
* Type#getInternalName()}), or {@literal null} to catch any exceptions (for "finally"
660+
* blocks).
648661
* @throws IllegalArgumentException if one of the labels has already been visited by this visitor
649662
* (by the {@link #visitLabel} method).
650663
*/

spring-core/src/main/java/org/springframework/asm/Opcodes.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,7 @@ public interface Opcodes {
284284
int V17 = 0 << 16 | 61;
285285
int V18 = 0 << 16 | 62;
286286
int V19 = 0 << 16 | 63;
287+
int V20 = 0 << 16 | 64;
287288

288289
/**
289290
* Version flag indicating that the class is using 'preview' features.

0 commit comments

Comments
 (0)