Skip to content

Commit 1e0de07

Browse files
committed
Upgrade to ASM 7.0 beta release
Issue: SPR-17267
1 parent bb5c8ed commit 1e0de07

File tree

7 files changed

+69
-52
lines changed

7 files changed

+69
-52
lines changed

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

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,9 @@ public ClassReader(final byte[] classFile) {
160160
* @param classFileLength the length in bytes of the ClassFile to be read.
161161
*/
162162
public ClassReader(
163-
final byte[] classFileBuffer, final int classFileOffset, final int classFileLength) {
163+
final byte[] classFileBuffer,
164+
final int classFileOffset,
165+
final int classFileLength) { // NOPMD(UnusedFormalParameter) used for backward compatibility.
164166
this(classFileBuffer, classFileOffset, /* checkClassVersion = */ true);
165167
}
166168

@@ -500,9 +502,8 @@ public void accept(
500502
moduleMainClass = readClass(currentAttributeOffset, charBuffer);
501503
} else if (Constants.MODULE_PACKAGES.equals(attributeName)) {
502504
modulePackagesOffset = currentAttributeOffset;
503-
} else if (Constants.BOOTSTRAP_METHODS.equals(attributeName)) {
504-
// This attribute is read in the constructor.
505-
} else {
505+
} else if (!Constants.BOOTSTRAP_METHODS.equals(attributeName)) {
506+
// The BootstrapMethods attribute is read in the constructor.
506507
Attribute attribute =
507508
readAttribute(
508509
attributePrototypes,
@@ -2358,12 +2359,12 @@ private void readCode(
23582359

23592360
// Visit the local variable type annotations of the RuntimeVisibleTypeAnnotations attribute.
23602361
if (visibleTypeAnnotationOffsets != null) {
2361-
for (int i = 0; i < visibleTypeAnnotationOffsets.length; ++i) {
2362-
int targetType = readByte(visibleTypeAnnotationOffsets[i]);
2362+
for (int typeAnnotationOffset : visibleTypeAnnotationOffsets) {
2363+
int targetType = readByte(typeAnnotationOffset);
23632364
if (targetType == TypeReference.LOCAL_VARIABLE
23642365
|| targetType == TypeReference.RESOURCE_VARIABLE) {
23652366
// Parse the target_type, target_info and target_path fields.
2366-
currentOffset = readTypeAnnotationTarget(context, visibleTypeAnnotationOffsets[i]);
2367+
currentOffset = readTypeAnnotationTarget(context, typeAnnotationOffset);
23672368
// Parse the type_index field.
23682369
String annotationDescriptor = readUTF8(currentOffset, charBuffer);
23692370
currentOffset += 2;
@@ -2386,12 +2387,12 @@ private void readCode(
23862387

23872388
// Visit the local variable type annotations of the RuntimeInvisibleTypeAnnotations attribute.
23882389
if (invisibleTypeAnnotationOffsets != null) {
2389-
for (int i = 0; i < invisibleTypeAnnotationOffsets.length; ++i) {
2390-
int targetType = readByte(invisibleTypeAnnotationOffsets[i]);
2390+
for (int typeAnnotationOffset : invisibleTypeAnnotationOffsets) {
2391+
int targetType = readByte(typeAnnotationOffset);
23912392
if (targetType == TypeReference.LOCAL_VARIABLE
23922393
|| targetType == TypeReference.RESOURCE_VARIABLE) {
23932394
// Parse the target_type, target_info and target_path fields.
2394-
currentOffset = readTypeAnnotationTarget(context, invisibleTypeAnnotationOffsets[i]);
2395+
currentOffset = readTypeAnnotationTarget(context, typeAnnotationOffset);
23952396
// Parse the type_index field.
23962397
String annotationDescriptor = readUTF8(currentOffset, charBuffer);
23972398
currentOffset += 2;
@@ -3283,9 +3284,9 @@ private Attribute readAttribute(
32833284
final char[] charBuffer,
32843285
final int codeAttributeOffset,
32853286
final Label[] labels) {
3286-
for (int i = 0; i < attributePrototypes.length; ++i) {
3287-
if (attributePrototypes[i].type.equals(type)) {
3288-
return attributePrototypes[i].read(
3287+
for (Attribute attributePrototype : attributePrototypes) {
3288+
if (attributePrototype.type.equals(type)) {
3289+
return attributePrototype.read(
32893290
this, offset, length, charBuffer, codeAttributeOffset, labels);
32903291
}
32913292
}

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -383,10 +383,9 @@ public final void visitInnerClass(
383383
innerClasses.putShort(innerName == null ? 0 : symbolTable.addConstantUtf8(innerName));
384384
innerClasses.putShort(access);
385385
nameSymbol.info = numberOfInnerClasses;
386-
} else {
387-
// Compare the inner classes entry nameSymbol.info - 1 with the arguments of this method and
388-
// throw an exception if there is a difference?
389386
}
387+
// Else, compare the inner classes entry nameSymbol.info - 1 with the arguments of this method
388+
// and throw an exception if there is a difference?
390389
}
391390

392391
@Override

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

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,13 +99,36 @@ public Handle getBootstrapMethod() {
9999
}
100100

101101
/**
102-
* Returns the arguments to pass to the bootstrap method, in order to compute the value of this
102+
* Returns the number of arguments passed to the bootstrap method, in order to compute the value
103+
* of this constant.
104+
*
105+
* @return the number of arguments passed to the bootstrap method, in order to compute the value
106+
* of this constant.
107+
*/
108+
public int getBootstrapMethodArgumentCount() {
109+
return bootstrapMethodArguments.length;
110+
}
111+
112+
/**
113+
* Returns an argument passed to the bootstrap method, in order to compute the value of this
103114
* constant.
104115
*
116+
* @param index an argument index, between 0 and {@link #getBootstrapMethodArgumentCount()}
117+
* (exclusive).
118+
* @return the argument passed to the bootstrap method, with the given index.
119+
*/
120+
public Object getBootstrapMethodArgument(final int index) {
121+
return bootstrapMethodArguments[index];
122+
}
123+
124+
/**
125+
* Returns the arguments to pass to the bootstrap method, in order to compute the value of this
126+
* constant. WARNING: this array must not be modified, and must not be returned to the user.
127+
*
105128
* @return the arguments to pass to the bootstrap method, in order to compute the value of this
106129
* constant.
107130
*/
108-
public Object[] getBootstrapMethodArguments() {
131+
Object[] getBootstrapMethodArgumentsUnsafe() {
109132
return bootstrapMethodArguments;
110133
}
111134

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -765,11 +765,10 @@ public void visitFrame(
765765
if (type == Opcodes.F_NEW) {
766766
currentBasicBlock.frame.setInputFrameFromApiFormat(
767767
symbolTable, numLocal, local, numStack, stack);
768-
} else {
769-
// In this case type is equal to F_INSERT by hypothesis, and currentBlock.frame contains
770-
// the stack map frame at the current instruction, computed from the last F_NEW frame
771-
// and the bytecode instructions in between (via calls to CurrentFrame#execute).
772768
}
769+
// If type is not F_NEW then it is F_INSERT by hypothesis, and currentBlock.frame contains
770+
// the stack map frame at the current instruction, computed from the last F_NEW frame and
771+
// the bytecode instructions in between (via calls to CurrentFrame#execute).
773772
currentBasicBlock.frame.accept(this);
774773
}
775774
} else if (type == Opcodes.F_NEW) {
@@ -1951,6 +1950,7 @@ private void putFrame() {
19511950
putAbstractTypes(3, 3 + numLocal);
19521951
stackMapTableEntries.putShort(numStack);
19531952
putAbstractTypes(3 + numLocal, 3 + numLocal + numStack);
1953+
break;
19541954
}
19551955
}
19561956

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -496,7 +496,7 @@ Symbol addConstant(final Object value) {
496496
constantDynamic.getName(),
497497
constantDynamic.getDescriptor(),
498498
constantDynamic.getBootstrapMethod(),
499-
constantDynamic.getBootstrapMethodArguments());
499+
constantDynamic.getBootstrapMethodArgumentsUnsafe());
500500
} else {
501501
throw new IllegalArgumentException("value " + value);
502502
}

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

Lines changed: 22 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
* @author Eric Bruneton
3838
* @author Chris Nokleberg
3939
*/
40-
public class Type {
40+
public final class Type {
4141

4242
/** The sort of the {@code void} type. See {@link #getSort}. */
4343
public static final int VOID = 0;
@@ -153,7 +153,7 @@ public class Type {
153153
* @param valueBuffer a buffer containing the value of this field or method type.
154154
* @param valueBegin the beginning index, inclusive, of the value of this field or method type in
155155
* valueBuffer.
156-
* @param valueEnd tne end index, exclusive, of the value of this field or method type in
156+
* @param valueEnd the end index, exclusive, of the value of this field or method type in
157157
* valueBuffer.
158158
*/
159159
private Type(final int sort, final String valueBuffer, final int valueBegin, final int valueEnd) {
@@ -304,9 +304,8 @@ public static Type[] getArgumentTypes(final String methodDescriptor) {
304304
currentOffset++;
305305
}
306306
if (methodDescriptor.charAt(currentOffset++) == 'L') {
307-
while (methodDescriptor.charAt(currentOffset++) != ';') {
308-
// Skip the argument descriptor content.
309-
}
307+
// Skip the argument descriptor content.
308+
currentOffset = methodDescriptor.indexOf(';', currentOffset) + 1;
310309
}
311310
++numArgumentTypes;
312311
}
@@ -323,9 +322,8 @@ public static Type[] getArgumentTypes(final String methodDescriptor) {
323322
currentOffset++;
324323
}
325324
if (methodDescriptor.charAt(currentOffset++) == 'L') {
326-
while (methodDescriptor.charAt(currentOffset++) != ';') {
327-
// Skip the argument descriptor content.
328-
}
325+
// Skip the argument descriptor content.
326+
currentOffset = methodDescriptor.indexOf(';', currentOffset) + 1;
329327
}
330328
argumentTypes[currentArgumentTypeIndex++] =
331329
getTypeInternal(methodDescriptor, currentArgumentTypeOffset, currentOffset);
@@ -373,9 +371,8 @@ public static Type getReturnType(final String methodDescriptor) {
373371
currentOffset++;
374372
}
375373
if (methodDescriptor.charAt(currentOffset++) == 'L') {
376-
while (methodDescriptor.charAt(currentOffset++) != ';') {
377-
// Skip the argument descriptor content.
378-
}
374+
// Skip the argument descriptor content.
375+
currentOffset = methodDescriptor.indexOf(';', currentOffset) + 1;
379376
}
380377
}
381378
return getTypeInternal(methodDescriptor, currentOffset + 1, methodDescriptor.length());
@@ -508,11 +505,11 @@ public String getDescriptor() {
508505
if (sort == OBJECT) {
509506
return valueBuffer.substring(valueBegin - 1, valueEnd + 1);
510507
} else if (sort == INTERNAL) {
511-
StringBuilder stringBuilder = new StringBuilder();
512-
stringBuilder.append('L');
513-
stringBuilder.append(valueBuffer, valueBegin, valueEnd);
514-
stringBuilder.append(';');
515-
return stringBuilder.toString();
508+
return new StringBuilder()
509+
.append('L')
510+
.append(valueBuffer, valueBegin, valueEnd)
511+
.append(';')
512+
.toString();
516513
} else {
517514
return valueBuffer.substring(valueBegin, valueEnd);
518515
}
@@ -540,8 +537,8 @@ public static String getConstructorDescriptor(final Constructor<?> constructor)
540537
StringBuilder stringBuilder = new StringBuilder();
541538
stringBuilder.append('(');
542539
Class<?>[] parameters = constructor.getParameterTypes();
543-
for (int i = 0; i < parameters.length; ++i) {
544-
appendDescriptor(parameters[i], stringBuilder);
540+
for (Class<?> parameter : parameters) {
541+
appendDescriptor(parameter, stringBuilder);
545542
}
546543
return stringBuilder.append(")V").toString();
547544
}
@@ -556,8 +553,8 @@ public static String getConstructorDescriptor(final Constructor<?> constructor)
556553
public static String getMethodDescriptor(final Type returnType, final Type... argumentTypes) {
557554
StringBuilder stringBuilder = new StringBuilder();
558555
stringBuilder.append('(');
559-
for (int i = 0; i < argumentTypes.length; ++i) {
560-
argumentTypes[i].appendDescriptor(stringBuilder);
556+
for (Type argumentType : argumentTypes) {
557+
argumentType.appendDescriptor(stringBuilder);
561558
}
562559
stringBuilder.append(')');
563560
returnType.appendDescriptor(stringBuilder);
@@ -574,8 +571,8 @@ public static String getMethodDescriptor(final Method method) {
574571
StringBuilder stringBuilder = new StringBuilder();
575572
stringBuilder.append('(');
576573
Class<?>[] parameters = method.getParameterTypes();
577-
for (int i = 0; i < parameters.length; ++i) {
578-
appendDescriptor(parameters[i], stringBuilder);
574+
for (Class<?> parameter : parameters) {
575+
appendDescriptor(parameter, stringBuilder);
579576
}
580577
stringBuilder.append(')');
581578
appendDescriptor(method.getReturnType(), stringBuilder);
@@ -591,9 +588,7 @@ private void appendDescriptor(final StringBuilder stringBuilder) {
591588
if (sort == OBJECT) {
592589
stringBuilder.append(valueBuffer, valueBegin - 1, valueEnd + 1);
593590
} else if (sort == INTERNAL) {
594-
stringBuilder.append('L');
595-
stringBuilder.append(valueBuffer, valueBegin, valueEnd);
596-
stringBuilder.append(';');
591+
stringBuilder.append('L').append(valueBuffer, valueBegin, valueEnd).append(';');
597592
} else {
598593
stringBuilder.append(valueBuffer, valueBegin, valueEnd);
599594
}
@@ -741,9 +736,8 @@ public static int getArgumentsAndReturnSizes(final String methodDescriptor) {
741736
currentOffset++;
742737
}
743738
if (methodDescriptor.charAt(currentOffset++) == 'L') {
744-
while (methodDescriptor.charAt(currentOffset++) != ';') {
745-
// Skip the argument descriptor content.
746-
}
739+
// Skip the argument descriptor content.
740+
currentOffset = methodDescriptor.indexOf(';', currentOffset) + 1;
747741
}
748742
argumentsSize += 1;
749743
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
*
3535
* @author Eric Bruneton
3636
*/
37-
public class TypePath {
37+
public final class TypePath {
3838

3939
/** A type path step that steps into the element type of an array type. See {@link #getStep}. */
4040
public static final int ARRAY_ELEMENT = 0;

0 commit comments

Comments
 (0)