Skip to content

Commit bdf6c38

Browse files
jansupolsenivam
authored andcommitted
Adopt ASM 9
Signed-off-by: Jan Supol <[email protected]>
1 parent cb3d1cf commit bdf6c38

File tree

17 files changed

+109
-110
lines changed

17 files changed

+109
-110
lines changed

core-server/src/main/java/jersey/repackaged/org/objectweb/asm/AnnotationVisitor.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,15 +68,16 @@ 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
}
79-
if (api == Opcodes.ASM9_EXPERIMENTAL) {
80+
if (api == Opcodes.ASM10_EXPERIMENTAL) {
8081
Constants.checkAsmExperimental(this);
8182
}
8283
this.api = api;

core-server/src/main/java/jersey/repackaged/org/objectweb/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;

core-server/src/main/java/jersey/repackaged/org/objectweb/asm/ClassReader.java

Lines changed: 17 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
}
@@ -467,8 +460,8 @@ public void accept(
467460
String nestHostClass = null;
468461
// - The offset of the NestMembers attribute, or 0.
469462
int nestMembersOffset = 0;
470-
// - The offset of the PermittedSubtypes attribute, or 0
471-
int permittedSubtypesOffset = 0;
463+
// - The offset of the PermittedSubclasses attribute, or 0
464+
int permittedSubclassesOffset = 0;
472465
// - The offset of the Record attribute, or 0.
473466
int recordOffset = 0;
474467
// - The non standard attributes (linked with their {@link Attribute#nextAttribute} field).
@@ -493,8 +486,8 @@ public void accept(
493486
nestHostClass = readClass(currentAttributeOffset, charBuffer);
494487
} else if (Constants.NEST_MEMBERS.equals(attributeName)) {
495488
nestMembersOffset = currentAttributeOffset;
496-
} else if (Constants.PERMITTED_SUBTYPES.equals(attributeName)) {
497-
permittedSubtypesOffset = currentAttributeOffset;
489+
} else if (Constants.PERMITTED_SUBCLASSES.equals(attributeName)) {
490+
permittedSubclassesOffset = currentAttributeOffset;
498491
} else if (Constants.SIGNATURE.equals(attributeName)) {
499492
signature = readUTF8(currentAttributeOffset, charBuffer);
500493
} else if (Constants.RUNTIME_VISIBLE_ANNOTATIONS.equals(attributeName)) {
@@ -514,6 +507,7 @@ public void accept(
514507
runtimeInvisibleTypeAnnotationsOffset = currentAttributeOffset;
515508
} else if (Constants.RECORD.equals(attributeName)) {
516509
recordOffset = currentAttributeOffset;
510+
accessFlags |= Opcodes.ACC_RECORD;
517511
} else if (Constants.MODULE.equals(attributeName)) {
518512
moduleOffset = currentAttributeOffset;
519513
} else if (Constants.MODULE_MAIN_CLASS.equals(attributeName)) {
@@ -671,14 +665,14 @@ public void accept(
671665
}
672666
}
673667

674-
// Visit the PermittedSubtypes attribute.
675-
if (permittedSubtypesOffset != 0) {
676-
int numberOfPermittedSubtypes = readUnsignedShort(permittedSubtypesOffset);
677-
int currentPermittedSubtypeOffset = permittedSubtypesOffset + 2;
678-
while (numberOfPermittedSubtypes-- > 0) {
679-
classVisitor.visitPermittedSubtypeExperimental(
680-
readClass(currentPermittedSubtypeOffset, charBuffer));
681-
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;
682676
}
683677
}
684678

@@ -2966,7 +2960,7 @@ private int readElementValues(
29662960
// Parse the array_value array.
29672961
while (numElementValuePairs-- > 0) {
29682962
currentOffset =
2969-
readElementValue(annotationVisitor, currentOffset, /* named = */ null, charBuffer);
2963+
readElementValue(annotationVisitor, currentOffset, /* elementName= */ null, charBuffer);
29702964
}
29712965
}
29722966
if (annotationVisitor != null) {

core-server/src/main/java/jersey/repackaged/org/objectweb/asm/ClassVisitor.java

Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,10 @@
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+
* visitPermittedSubclass} ][ {@code visitOuterClass} ] ( {@code visitAnnotation} | {@code
3434
* visitTypeAnnotation} | {@code visitAttribute} )* ( {@code visitNestMember} | {@code
35-
* visitInnerClass} | {@code visitField} | {@code visitMethod} )* {@code visitEnd}.
35+
* visitInnerClass} | {@code visitRecordComponent} | {@code visitField} | {@code visitMethod} )*
36+
* {@code visitEnd}.
3637
*
3738
* @author Eric Bruneton
3839
*/
@@ -61,21 +62,22 @@ public ClassVisitor(final int api) {
6162
* Constructs a new {@link ClassVisitor}.
6263
*
6364
* @param api the ASM API version implemented by this visitor. Must be one of {@link
64-
* Opcodes#ASM4}, {@link Opcodes#ASM5}, {@link Opcodes#ASM6}, {@link Opcodes#ASM7} or {@link
65-
* Opcodes#ASM8}.
65+
* Opcodes#ASM4}, {@link Opcodes#ASM5}, {@link Opcodes#ASM6}, {@link Opcodes#ASM7}, {@link
66+
* Opcodes#ASM8} or {@link Opcodes#ASM9}.
6667
* @param classVisitor the class visitor to which this visitor must delegate method calls. May be
6768
* null.
6869
*/
6970
public ClassVisitor(final int api, final ClassVisitor classVisitor) {
70-
if (api != Opcodes.ASM8
71+
if (api != Opcodes.ASM9
72+
&& api != Opcodes.ASM8
7173
&& api != Opcodes.ASM7
7274
&& api != Opcodes.ASM6
7375
&& api != Opcodes.ASM5
7476
&& api != Opcodes.ASM4
75-
&& api != Opcodes.ASM9_EXPERIMENTAL) {
77+
&& api != Opcodes.ASM10_EXPERIMENTAL) {
7678
throw new IllegalArgumentException("Unsupported api " + api);
7779
}
78-
if (api == Opcodes.ASM9_EXPERIMENTAL) {
80+
if (api == Opcodes.ASM10_EXPERIMENTAL) {
7981
Constants.checkAsmExperimental(this);
8082
}
8183
this.api = api;
@@ -88,7 +90,8 @@ public ClassVisitor(final int api, final ClassVisitor classVisitor) {
8890
* @param version the class version. The minor version is stored in the 16 most significant bits,
8991
* and the major version in the 16 least significant bits.
9092
* @param access the class's access flags (see {@link Opcodes}). This parameter also indicates if
91-
* the class is deprecated.
93+
* the class is deprecated {@link Opcodes#ACC_DEPRECATED} or a record {@link
94+
* Opcodes#ACC_RECORD}.
9295
* @param name the internal name of the class (see {@link Type#getInternalName()}).
9396
* @param signature the signature of this class. May be {@literal null} if the class is not a
9497
* generic one, and does not extend or implement generic classes or interfaces.
@@ -105,6 +108,9 @@ public void visit(
105108
final String signature,
106109
final String superName,
107110
final String[] interfaces) {
111+
if (api < Opcodes.ASM8 && (access & Opcodes.ACC_RECORD) != 0) {
112+
throw new UnsupportedOperationException("Records requires ASM8");
113+
}
108114
if (cv != null) {
109115
cv.visit(version, access, name, signature, superName, interfaces);
110116
}
@@ -136,7 +142,7 @@ public void visitSource(final String source, final String debug) {
136142
*/
137143
public ModuleVisitor visitModule(final String name, final int access, final String version) {
138144
if (api < Opcodes.ASM6) {
139-
throw new UnsupportedOperationException("This feature requires ASM6");
145+
throw new UnsupportedOperationException("Module requires ASM6");
140146
}
141147
if (cv != null) {
142148
return cv.visitModule(name, access, version);
@@ -156,7 +162,7 @@ public ModuleVisitor visitModule(final String name, final int access, final Stri
156162
*/
157163
public void visitNestHost(final String nestHost) {
158164
if (api < Opcodes.ASM7) {
159-
throw new UnsupportedOperationException("This feature requires ASM7");
165+
throw new UnsupportedOperationException("NestHost requires ASM7");
160166
}
161167
if (cv != null) {
162168
cv.visitNestHost(nestHost);
@@ -212,7 +218,7 @@ public AnnotationVisitor visitAnnotation(final String descriptor, final boolean
212218
public AnnotationVisitor visitTypeAnnotation(
213219
final int typeRef, final TypePath typePath, final String descriptor, final boolean visible) {
214220
if (api < Opcodes.ASM5) {
215-
throw new UnsupportedOperationException("This feature requires ASM5");
221+
throw new UnsupportedOperationException("TypeAnnotation requires ASM5");
216222
}
217223
if (cv != null) {
218224
return cv.visitTypeAnnotation(typeRef, typePath, descriptor, visible);
@@ -242,28 +248,25 @@ public void visitAttribute(final Attribute attribute) {
242248
*/
243249
public void visitNestMember(final String nestMember) {
244250
if (api < Opcodes.ASM7) {
245-
throw new UnsupportedOperationException("This feature requires ASM7");
251+
throw new UnsupportedOperationException("NestMember requires ASM7");
246252
}
247253
if (cv != null) {
248254
cv.visitNestMember(nestMember);
249255
}
250256
}
251257

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

@@ -299,7 +302,7 @@ public void visitInnerClass(
299302
public RecordComponentVisitor visitRecordComponent(
300303
final String name, final String descriptor, final String signature) {
301304
if (api < Opcodes.ASM8) {
302-
throw new UnsupportedOperationException("This feature requires ASM8");
305+
throw new UnsupportedOperationException("Record requires ASM8");
303306
}
304307
if (cv != null) {
305308
return cv.visitRecordComponent(name, descriptor, signature);

0 commit comments

Comments
 (0)