Skip to content

Commit a1bab14

Browse files
committed
Upgrade to ASM 9.0 beta
Closes gh-24872
1 parent 8e02d27 commit a1bab14

17 files changed

+89
-98
lines changed

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,12 +68,13 @@ public AnnotationVisitor(final int api) {
6868
* calls. May be {@literal null}.
6969
*/
7070
public AnnotationVisitor(final int api, final AnnotationVisitor annotationVisitor) {
71-
if (api != Opcodes.ASM8
71+
if (api != Opcodes.ASM9
72+
&& api != Opcodes.ASM8
7273
&& api != Opcodes.ASM7
7374
&& api != Opcodes.ASM6
7475
&& api != Opcodes.ASM5
7576
&& api != Opcodes.ASM4
76-
&& api != Opcodes.ASM9_EXPERIMENTAL) {
77+
&& api != Opcodes.ASM10_EXPERIMENTAL) {
7778
throw new IllegalArgumentException("Unsupported api " + api);
7879
}
7980
// SPRING PATCH: no preview mode check for ASM 9 experimental

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ final class AnnotationWriter extends AnnotationVisitor {
112112
final boolean useNamedValues,
113113
final ByteVector annotation,
114114
final AnnotationWriter previousAnnotation) {
115-
super(/* latest api = */ Opcodes.ASM8);
115+
super(/* latest api = */ Opcodes.ASM9);
116116
this.symbolTable = symbolTable;
117117
this.useNamedValues = useNamedValues;
118118
this.annotation = annotation;

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

Lines changed: 15 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,8 @@ public class ClassReader {
100100
@Deprecated
101101
// DontCheck(MemberName): can't be renamed (for backward binary compatibility).
102102
public final byte[] b;
103-
103+
/** The offset in bytes of the ClassFile's access_flags field. */
104+
public final int header;
104105
/**
105106
* A byte array containing the JVMS ClassFile structure to be parsed. <i>The content of this array
106107
* must not be modified. This field is intended for {@link Attribute} sub classes, and is normally
@@ -111,27 +112,23 @@ public class ClassReader {
111112
* ClassFile element offsets within this byte array.
112113
*/
113114
final byte[] classFileBuffer;
114-
115115
/**
116116
* The offset in bytes, in {@link #classFileBuffer}, of each cp_info entry of the ClassFile's
117117
* constant_pool array, <i>plus one</i>. In other words, the offset of constant pool entry i is
118118
* given by cpInfoOffsets[i] - 1, i.e. its cp_info's tag field is given by b[cpInfoOffsets[i] -
119119
* 1].
120120
*/
121121
private final int[] cpInfoOffsets;
122-
123122
/**
124123
* The String objects corresponding to the CONSTANT_Utf8 constant pool items. This cache avoids
125124
* multiple parsing of a given CONSTANT_Utf8 constant pool item.
126125
*/
127126
private final String[] constantUtf8Values;
128-
129127
/**
130128
* The ConstantDynamic objects corresponding to the CONSTANT_Dynamic constant pool items. This
131129
* cache avoids multiple parsing of a given CONSTANT_Dynamic constant pool item.
132130
*/
133131
private final ConstantDynamic[] constantDynamicValues;
134-
135132
/**
136133
* The start offsets in {@link #classFileBuffer} of each element of the bootstrap_methods array
137134
* (in the BootstrapMethods attribute).
@@ -140,16 +137,12 @@ public class ClassReader {
140137
* 4.7.23</a>
141138
*/
142139
private final int[] bootstrapMethodOffsets;
143-
144140
/**
145141
* A conservative estimate of the maximum length of the strings contained in the constant pool of
146142
* the class.
147143
*/
148144
private final int maxStringLength;
149145

150-
/** The offset in bytes of the ClassFile's access_flags field. */
151-
public final int header;
152-
153146
// -----------------------------------------------------------------------------------------------
154147
// Constructors
155148
// -----------------------------------------------------------------------------------------------
@@ -191,7 +184,7 @@ public ClassReader(
191184
this.b = classFileBuffer;
192185
// Check the class' major_version. This field is after the magic and minor_version fields, which
193186
// use 4 and 2 bytes respectively.
194-
if (checkClassVersion && readShort(classFileOffset + 6) > Opcodes.V15) {
187+
if (checkClassVersion && readShort(classFileOffset + 6) > Opcodes.V16) {
195188
throw new IllegalArgumentException(
196189
"Unsupported class file major version " + readShort(classFileOffset + 6));
197190
}
@@ -415,7 +408,6 @@ public void accept(final ClassVisitor classVisitor, final int parsingOptions) {
415408
* @param parsingOptions the options to use to parse this class. One or more of {@link
416409
* #SKIP_CODE}, {@link #SKIP_DEBUG}, {@link #SKIP_FRAMES} or {@link #EXPAND_FRAMES}.
417410
*/
418-
@SuppressWarnings("deprecation") // for visitPermittedSubtypeExperimental
419411
public void accept(
420412
final ClassVisitor classVisitor,
421413
final Attribute[] attributePrototypes,
@@ -468,8 +460,8 @@ public void accept(
468460
String nestHostClass = null;
469461
// - The offset of the NestMembers attribute, or 0.
470462
int nestMembersOffset = 0;
471-
// - The offset of the PermittedSubtypes attribute, or 0
472-
int permittedSubtypesOffset = 0;
463+
// - The offset of the PermittedSubclasses attribute, or 0
464+
int permittedSubclassesOffset = 0;
473465
// - The offset of the Record attribute, or 0.
474466
int recordOffset = 0;
475467
// - The non standard attributes (linked with their {@link Attribute#nextAttribute} field).
@@ -494,8 +486,8 @@ public void accept(
494486
nestHostClass = readClass(currentAttributeOffset, charBuffer);
495487
} else if (Constants.NEST_MEMBERS.equals(attributeName)) {
496488
nestMembersOffset = currentAttributeOffset;
497-
} else if (Constants.PERMITTED_SUBTYPES.equals(attributeName)) {
498-
permittedSubtypesOffset = currentAttributeOffset;
489+
} else if (Constants.PERMITTED_SUBCLASSES.equals(attributeName)) {
490+
permittedSubclassesOffset = currentAttributeOffset;
499491
} else if (Constants.SIGNATURE.equals(attributeName)) {
500492
signature = readUTF8(currentAttributeOffset, charBuffer);
501493
} else if (Constants.RUNTIME_VISIBLE_ANNOTATIONS.equals(attributeName)) {
@@ -673,14 +665,14 @@ public void accept(
673665
}
674666
}
675667

676-
// Visit the PermittedSubtypes attribute.
677-
if (permittedSubtypesOffset != 0) {
678-
int numberOfPermittedSubtypes = readUnsignedShort(permittedSubtypesOffset);
679-
int currentPermittedSubtypeOffset = permittedSubtypesOffset + 2;
680-
while (numberOfPermittedSubtypes-- > 0) {
681-
classVisitor.visitPermittedSubtypeExperimental(
682-
readClass(currentPermittedSubtypeOffset, charBuffer));
683-
currentPermittedSubtypeOffset += 2;
668+
// Visit the PermittedSubclasses attribute.
669+
if (permittedSubclassesOffset != 0) {
670+
int numberOfPermittedSubclasses = readUnsignedShort(permittedSubclassesOffset);
671+
int currentPermittedSubclassesOffset = permittedSubclassesOffset + 2;
672+
while (numberOfPermittedSubclasses-- > 0) {
673+
classVisitor.visitPermittedSubclass(
674+
readClass(currentPermittedSubclassesOffset, charBuffer));
675+
currentPermittedSubclassesOffset += 2;
684676
}
685677
}
686678

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

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
/**
3131
* A visitor to visit a Java class. The methods of this class must be called in the following order:
3232
* {@code visit} [ {@code visitSource} ] [ {@code visitModule} ][ {@code visitNestHost} ][ {@code
33-
* visitPermittedSubtype} ][ {@code visitOuterClass} ] ( {@code visitAnnotation} | {@code
33+
* visitPermittedclass} ][ {@code visitOuterClass} ] ( {@code visitAnnotation} | {@code
3434
* visitTypeAnnotation} | {@code visitAttribute} )* ( {@code visitNestMember} | {@code
3535
* visitInnerClass} | {@code visitRecordComponent} | {@code visitField} | {@code visitMethod} )*
3636
* {@code visitEnd}.
@@ -62,18 +62,19 @@ public ClassVisitor(final int api) {
6262
* Constructs a new {@link ClassVisitor}.
6363
*
6464
* @param api the ASM API version implemented by this visitor. Must be one of {@link
65-
* Opcodes#ASM4}, {@link Opcodes#ASM5}, {@link Opcodes#ASM6}, {@link Opcodes#ASM7} or {@link
66-
* Opcodes#ASM8}.
65+
* Opcodes#ASM4}, {@link Opcodes#ASM5}, {@link Opcodes#ASM6}, {@link Opcodes#ASM7}, {@link
66+
* Opcodes#ASM8} or {@link Opcodes#ASM9}.
6767
* @param classVisitor the class visitor to which this visitor must delegate method calls. May be
6868
* null.
6969
*/
7070
public ClassVisitor(final int api, final ClassVisitor classVisitor) {
71-
if (api != Opcodes.ASM8
71+
if (api != Opcodes.ASM9
72+
&& api != Opcodes.ASM8
7273
&& api != Opcodes.ASM7
7374
&& api != Opcodes.ASM6
7475
&& api != Opcodes.ASM5
7576
&& api != Opcodes.ASM4
76-
&& api != Opcodes.ASM9_EXPERIMENTAL) {
77+
&& api != Opcodes.ASM10_EXPERIMENTAL) {
7778
throw new IllegalArgumentException("Unsupported api " + api);
7879
}
7980
// SPRING PATCH: no preview mode check for ASM 9 experimental
@@ -139,7 +140,7 @@ public void visitSource(final String source, final String debug) {
139140
*/
140141
public ModuleVisitor visitModule(final String name, final int access, final String version) {
141142
if (api < Opcodes.ASM6) {
142-
throw new UnsupportedOperationException("This feature requires ASM6");
143+
throw new UnsupportedOperationException("Module requires ASM6");
143144
}
144145
if (cv != null) {
145146
return cv.visitModule(name, access, version);
@@ -159,7 +160,7 @@ public ModuleVisitor visitModule(final String name, final int access, final Stri
159160
*/
160161
public void visitNestHost(final String nestHost) {
161162
if (api < Opcodes.ASM7) {
162-
throw new UnsupportedOperationException("This feature requires ASM7");
163+
throw new UnsupportedOperationException("NestHost requires ASM7");
163164
}
164165
if (cv != null) {
165166
cv.visitNestHost(nestHost);
@@ -215,7 +216,7 @@ public AnnotationVisitor visitAnnotation(final String descriptor, final boolean
215216
public AnnotationVisitor visitTypeAnnotation(
216217
final int typeRef, final TypePath typePath, final String descriptor, final boolean visible) {
217218
if (api < Opcodes.ASM5) {
218-
throw new UnsupportedOperationException("This feature requires ASM5");
219+
throw new UnsupportedOperationException("TypeAnnotation requires ASM5");
219220
}
220221
if (cv != null) {
221222
return cv.visitTypeAnnotation(typeRef, typePath, descriptor, visible);
@@ -245,28 +246,25 @@ public void visitAttribute(final Attribute attribute) {
245246
*/
246247
public void visitNestMember(final String nestMember) {
247248
if (api < Opcodes.ASM7) {
248-
throw new UnsupportedOperationException("This feature requires ASM7");
249+
throw new UnsupportedOperationException("NestMember requires ASM7");
249250
}
250251
if (cv != null) {
251252
cv.visitNestMember(nestMember);
252253
}
253254
}
254255

255256
/**
256-
* <b>Experimental, use at your own risk. This method will be renamed when it becomes stable, this
257-
* will break existing code using it</b>. Visits a permitted subtypes. A permitted subtypes is one
258-
* of the allowed subtypes of the current class.
257+
* Visits a permitted subclasses. A permitted subclass is one of the allowed subclasses of the
258+
* current class.
259259
*
260-
* @param permittedSubtype the internal name of a permitted subtype.
261-
* @deprecated this API is experimental.
260+
* @param permittedSubclass the internal name of a permitted subclass.
262261
*/
263-
@Deprecated
264-
public void visitPermittedSubtypeExperimental(final String permittedSubtype) {
265-
if (api != Opcodes.ASM9_EXPERIMENTAL) {
266-
throw new UnsupportedOperationException("This feature requires ASM9_EXPERIMENTAL");
262+
public void visitPermittedSubclass(final String permittedSubclass) {
263+
if (api < Opcodes.ASM9) {
264+
throw new UnsupportedOperationException("PermittedSubclasses requires ASM9");
267265
}
268266
if (cv != null) {
269-
cv.visitPermittedSubtypeExperimental(permittedSubtype);
267+
cv.visitPermittedSubclass(permittedSubclass);
270268
}
271269
}
272270

@@ -302,7 +300,7 @@ public void visitInnerClass(
302300
public RecordComponentVisitor visitRecordComponent(
303301
final String name, final String descriptor, final String signature) {
304302
if (api < Opcodes.ASM8) {
305-
throw new UnsupportedOperationException("This feature requires ASM8");
303+
throw new UnsupportedOperationException("Record requires ASM8");
306304
}
307305
if (cv != null) {
308306
return cv.visitRecordComponent(name, descriptor, signature);

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

Lines changed: 20 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -177,11 +177,11 @@ public class ClassWriter extends ClassVisitor {
177177
/** The 'classes' array of the NestMembers attribute, or {@literal null}. */
178178
private ByteVector nestMemberClasses;
179179

180-
/** The number_of_classes field of the PermittedSubtypes attribute, or 0. */
181-
private int numberOfPermittedSubtypeClasses;
180+
/** The number_of_classes field of the PermittedSubclasses attribute, or 0. */
181+
private int numberOfPermittedSubclasses;
182182

183-
/** The 'classes' array of the PermittedSubtypes attribute, or {@literal null}. */
184-
private ByteVector permittedSubtypeClasses;
183+
/** The 'classes' array of the PermittedSubclasses attribute, or {@literal null}. */
184+
private ByteVector permittedSubclasses;
185185

186186
/**
187187
* The record components of this class, stored in a linked list of {@link RecordComponentWriter}
@@ -254,7 +254,7 @@ public ClassWriter(final int flags) {
254254
* maximum stack size nor the stack frames will be computed for these methods</i>.
255255
*/
256256
public ClassWriter(final ClassReader classReader, final int flags) {
257-
super(/* latest api = */ Opcodes.ASM8);
257+
super(/* latest api = */ Opcodes.ASM9);
258258
symbolTable = classReader == null ? new SymbolTable(this) : new SymbolTable(this, classReader);
259259
if ((flags & COMPUTE_FRAMES) != 0) {
260260
this.compute = MethodWriter.COMPUTE_ALL_FRAMES;
@@ -372,20 +372,13 @@ public final void visitNestMember(final String nestMember) {
372372
nestMemberClasses.putShort(symbolTable.addConstantClass(nestMember).index);
373373
}
374374

375-
/**
376-
* <b>Experimental, use at your own risk.</b>
377-
*
378-
* @param permittedSubtype the internal name of a permitted subtype.
379-
* @deprecated this API is experimental.
380-
*/
381375
@Override
382-
@Deprecated
383-
public final void visitPermittedSubtypeExperimental(final String permittedSubtype) {
384-
if (permittedSubtypeClasses == null) {
385-
permittedSubtypeClasses = new ByteVector();
376+
public final void visitPermittedSubclass(final String permittedSubclass) {
377+
if (permittedSubclasses == null) {
378+
permittedSubclasses = new ByteVector();
386379
}
387-
++numberOfPermittedSubtypeClasses;
388-
permittedSubtypeClasses.putShort(symbolTable.addConstantClass(permittedSubtype).index);
380+
++numberOfPermittedSubclasses;
381+
permittedSubclasses.putShort(symbolTable.addConstantClass(permittedSubclass).index);
389382
}
390383

391384
@Override
@@ -576,10 +569,10 @@ public byte[] toByteArray() {
576569
size += 8 + nestMemberClasses.length;
577570
symbolTable.addConstantUtf8(Constants.NEST_MEMBERS);
578571
}
579-
if (permittedSubtypeClasses != null) {
572+
if (permittedSubclasses != null) {
580573
++attributesCount;
581-
size += 8 + permittedSubtypeClasses.length;
582-
symbolTable.addConstantUtf8(Constants.PERMITTED_SUBTYPES);
574+
size += 8 + permittedSubclasses.length;
575+
symbolTable.addConstantUtf8(Constants.PERMITTED_SUBCLASSES);
583576
}
584577
int recordComponentCount = 0;
585578
int recordSize = 0;
@@ -698,12 +691,12 @@ public byte[] toByteArray() {
698691
.putShort(numberOfNestMemberClasses)
699692
.putByteArray(nestMemberClasses.data, 0, nestMemberClasses.length);
700693
}
701-
if (permittedSubtypeClasses != null) {
694+
if (permittedSubclasses != null) {
702695
result
703-
.putShort(symbolTable.addConstantUtf8(Constants.PERMITTED_SUBTYPES))
704-
.putInt(permittedSubtypeClasses.length + 2)
705-
.putShort(numberOfPermittedSubtypeClasses)
706-
.putByteArray(permittedSubtypeClasses.data, 0, permittedSubtypeClasses.length);
696+
.putShort(symbolTable.addConstantUtf8(Constants.PERMITTED_SUBCLASSES))
697+
.putInt(permittedSubclasses.length + 2)
698+
.putShort(numberOfPermittedSubclasses)
699+
.putByteArray(permittedSubclasses.data, 0, permittedSubclasses.length);
707700
}
708701
if ((accessFlags & Opcodes.ACC_RECORD) != 0 || firstRecordComponent != null) {
709702
result
@@ -752,8 +745,8 @@ private byte[] replaceAsmInstructions(final byte[] classFile, final boolean hasF
752745
nestHostClassIndex = 0;
753746
numberOfNestMemberClasses = 0;
754747
nestMemberClasses = null;
755-
numberOfPermittedSubtypeClasses = 0;
756-
permittedSubtypeClasses = null;
748+
numberOfPermittedSubclasses = 0;
749+
permittedSubclasses = null;
757750
firstRecordComponent = null;
758751
lastRecordComponent = null;
759752
firstAttribute = null;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ final class Constants {
6767
static final String MODULE_MAIN_CLASS = "ModuleMainClass";
6868
static final String NEST_HOST = "NestHost";
6969
static final String NEST_MEMBERS = "NestMembers";
70-
static final String PERMITTED_SUBTYPES = "PermittedSubtypes";
70+
static final String PERMITTED_SUBCLASSES = "PermittedSubclasses";
7171
static final String RECORD = "Record";
7272

7373
// ASM specific access flags.

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

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ public abstract class FieldVisitor {
3838

3939
/**
4040
* The ASM API version implemented by this visitor. The value of this field must be one of {@link
41-
* Opcodes#ASM4}, {@link Opcodes#ASM5}, {@link Opcodes#ASM6}, {@link Opcodes#ASM7} or {@link
42-
* Opcodes#ASM8}.
41+
* Opcodes#ASM4}, {@link Opcodes#ASM5}, {@link Opcodes#ASM6}, {@link Opcodes#ASM7}, {@link
42+
* Opcodes#ASM8} or {@link Opcodes#ASM9}.
4343
*/
4444
protected final int api;
4545

@@ -50,8 +50,8 @@ public abstract class FieldVisitor {
5050
* Constructs a new {@link FieldVisitor}.
5151
*
5252
* @param api the ASM API version implemented by this visitor. Must be one of {@link
53-
* Opcodes#ASM4}, {@link Opcodes#ASM5}, {@link Opcodes#ASM6}, {@link Opcodes#ASM7} or {@link
54-
* Opcodes#ASM8}.
53+
* Opcodes#ASM4}, {@link Opcodes#ASM5}, {@link Opcodes#ASM6}, {@link Opcodes#ASM7}, {@link
54+
* Opcodes#ASM8} or {@link Opcodes#ASM9}.
5555
*/
5656
public FieldVisitor(final int api) {
5757
this(api, null);
@@ -67,12 +67,13 @@ public FieldVisitor(final int api) {
6767
* null.
6868
*/
6969
public FieldVisitor(final int api, final FieldVisitor fieldVisitor) {
70-
if (api != Opcodes.ASM8
70+
if (api != Opcodes.ASM9
71+
&& api != Opcodes.ASM8
7172
&& api != Opcodes.ASM7
7273
&& api != Opcodes.ASM6
7374
&& api != Opcodes.ASM5
7475
&& api != Opcodes.ASM4
75-
&& api != Opcodes.ASM9_EXPERIMENTAL) {
76+
&& api != Opcodes.ASM10_EXPERIMENTAL) {
7677
throw new IllegalArgumentException("Unsupported api " + api);
7778
}
7879
// SPRING PATCH: no preview mode check for ASM 9 experimental

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ final class FieldWriter extends FieldVisitor {
124124
final String descriptor,
125125
final String signature,
126126
final Object constantValue) {
127-
super(/* latest api = */ Opcodes.ASM8);
127+
super(/* latest api = */ Opcodes.ASM9);
128128
this.symbolTable = symbolTable;
129129
this.accessFlags = access;
130130
this.nameIndex = symbolTable.addConstantUtf8(name);

0 commit comments

Comments
 (0)