Skip to content

Commit 10d47d4

Browse files
committed
Enable ASM8_EXPERIMENTAL for Java 14 record support
Closes gh-24722
1 parent 1800b10 commit 10d47d4

File tree

8 files changed

+11
-65
lines changed

8 files changed

+11
-65
lines changed

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,7 @@ public AnnotationVisitor(final int api, final AnnotationVisitor annotationVisito
7676
&& api != Opcodes.ASM8_EXPERIMENTAL) {
7777
throw new IllegalArgumentException("Unsupported api " + api);
7878
}
79-
if (api == Opcodes.ASM8_EXPERIMENTAL) {
80-
Constants.checkAsm8Experimental(this);
81-
}
79+
// SPRING PATCH: no preview mode check for ASM 8 experimental
8280
this.api = api;
8381
this.av = annotationVisitor;
8482
}

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,7 @@ public ClassVisitor(final int api, final ClassVisitor classVisitor) {
7474
&& api != Opcodes.ASM8_EXPERIMENTAL) {
7575
throw new IllegalArgumentException("Unsupported api " + api);
7676
}
77-
if (api == Opcodes.ASM8_EXPERIMENTAL) {
78-
Constants.checkAsm8Experimental(this);
79-
}
77+
// SPRING PATCH: no preview mode check for ASM 8 experimental
8078
this.api = api;
8179
this.cv = classVisitor;
8280
}

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

Lines changed: 1 addition & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,6 @@
2727
// THE POSSIBILITY OF SUCH DAMAGE.
2828
package org.springframework.asm;
2929

30-
import java.io.DataInputStream;
31-
import java.io.IOException;
32-
import java.io.InputStream;
33-
import java.util.regex.Pattern;
34-
3530
/**
3631
* Defines additional JVM opcodes, access flags and constants which are not part of the ASM public
3732
* API.
@@ -61,8 +56,7 @@ final class Constants implements Opcodes {
6156
static final String RUNTIME_VISIBLE_ANNOTATIONS = "RuntimeVisibleAnnotations";
6257
static final String RUNTIME_INVISIBLE_ANNOTATIONS = "RuntimeInvisibleAnnotations";
6358
static final String RUNTIME_VISIBLE_PARAMETER_ANNOTATIONS = "RuntimeVisibleParameterAnnotations";
64-
static final String RUNTIME_INVISIBLE_PARAMETER_ANNOTATIONS =
65-
"RuntimeInvisibleParameterAnnotations";
59+
static final String RUNTIME_INVISIBLE_PARAMETER_ANNOTATIONS = "RuntimeInvisibleParameterAnnotations";
6660
static final String RUNTIME_VISIBLE_TYPE_ANNOTATIONS = "RuntimeVisibleTypeAnnotations";
6761
static final String RUNTIME_INVISIBLE_TYPE_ANNOTATIONS = "RuntimeInvisibleTypeAnnotations";
6862
static final String ANNOTATION_DEFAULT = "AnnotationDefault";
@@ -181,41 +175,4 @@ final class Constants implements Opcodes {
181175
static final int ASM_GOTO_W = 220;
182176

183177
private Constants() {}
184-
185-
static void checkAsm8Experimental(final Object caller) {
186-
Class<?> callerClass = caller.getClass();
187-
String internalName = callerClass.getName().replace('.', '/');
188-
if (!isWhitelisted(internalName)) {
189-
checkIsPreview(callerClass.getClassLoader().getResourceAsStream(internalName + ".class"));
190-
}
191-
}
192-
193-
static boolean isWhitelisted(final String internalName) {
194-
if (!internalName.startsWith("org/objectweb/asm/")) {
195-
return false;
196-
}
197-
String member = "(Annotation|Class|Field|Method|Module|RecordComponent|Signature)";
198-
return internalName.contains("Test$")
199-
|| Pattern.matches(
200-
"org/objectweb/asm/util/Trace" + member + "Visitor(\\$.*)?", internalName)
201-
|| Pattern.matches(
202-
"org/objectweb/asm/util/Check" + member + "Adapter(\\$.*)?", internalName);
203-
}
204-
205-
static void checkIsPreview(final InputStream classInputStream) {
206-
if (classInputStream == null) {
207-
throw new IllegalStateException("Bytecode not available, can't check class version");
208-
}
209-
int minorVersion;
210-
try (DataInputStream callerClassStream = new DataInputStream(classInputStream); ) {
211-
callerClassStream.readInt();
212-
minorVersion = callerClassStream.readUnsignedShort();
213-
} catch (IOException ioe) {
214-
throw new IllegalStateException("I/O error, can't check class version", ioe);
215-
}
216-
if (minorVersion != 0xFFFF) {
217-
throw new IllegalStateException(
218-
"ASM8_EXPERIMENTAL can only be used by classes compiled with --enable-preview");
219-
}
220-
}
221178
}

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,7 @@ public FieldVisitor(final int api, final FieldVisitor fieldVisitor) {
7272
&& api != Opcodes.ASM8_EXPERIMENTAL) {
7373
throw new IllegalArgumentException("Unsupported api " + api);
7474
}
75-
if (api == Opcodes.ASM8_EXPERIMENTAL) {
76-
Constants.checkAsm8Experimental(this);
77-
}
75+
// SPRING PATCH: no preview mode check for ASM 8 experimental
7876
this.api = api;
7977
this.fv = fieldVisitor;
8078
}

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,7 @@ public MethodVisitor(final int api, final MethodVisitor methodVisitor) {
8888
&& api != Opcodes.ASM8_EXPERIMENTAL) {
8989
throw new IllegalArgumentException("Unsupported api " + api);
9090
}
91-
if (api == Opcodes.ASM8_EXPERIMENTAL) {
92-
Constants.checkAsm8Experimental(this);
93-
}
91+
// SPRING PATCH: no preview mode check for ASM 8 experimental
9492
this.api = api;
9593
this.mv = methodVisitor;
9694
}

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,7 @@ public ModuleVisitor(final int api, final ModuleVisitor moduleVisitor) {
7474
&& api != Opcodes.ASM8_EXPERIMENTAL) {
7575
throw new IllegalArgumentException("Unsupported api " + api);
7676
}
77-
if (api == Opcodes.ASM8_EXPERIMENTAL) {
78-
Constants.checkAsm8Experimental(this);
79-
}
77+
// SPRING PATCH: no preview mode check for ASM 8 experimental
8078
this.api = api;
8179
this.mv = moduleVisitor;
8280
}

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,7 @@ public RecordComponentVisitor(
8080
&& api != Opcodes.ASM8_EXPERIMENTAL) {
8181
throw new IllegalArgumentException("Unsupported api " + api);
8282
}
83-
if (api == Opcodes.ASM8_EXPERIMENTAL) {
84-
Constants.checkAsm8Experimental(this);
85-
}
83+
// SPRING PATCH: no preview mode check for ASM 8 experimental
8684
this.api = api;
8785
this.delegate = recordComponentVisitor;
8886
}

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2019 the original author or authors.
2+
* Copyright 2002-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -31,8 +31,9 @@ public final class SpringAsmInfo {
3131

3232
/**
3333
* The ASM compatibility version for Spring's ASM visitor implementations:
34-
* currently {@link Opcodes#ASM7}, as of Spring Framework 5.1.
34+
* currently {@link Opcodes#ASM8_EXPERIMENTAL}, as of Spring Framework 5.2.5.
3535
*/
36-
public static final int ASM_VERSION = Opcodes.ASM7;
36+
@SuppressWarnings("deprecation")
37+
public static final int ASM_VERSION = Opcodes.ASM8_EXPERIMENTAL;
3738

3839
}

0 commit comments

Comments
 (0)