Enable ASM8_EXPERIMENTAL for Java 14 record support

Closes gh-24722
This commit is contained in:
Juergen Hoeller 2020-03-23 18:00:59 +01:00
parent 1800b10717
commit 10d47d4d21
8 changed files with 11 additions and 65 deletions

View File

@ -76,9 +76,7 @@ public abstract class AnnotationVisitor {
&& api != Opcodes.ASM8_EXPERIMENTAL) {
throw new IllegalArgumentException("Unsupported api " + api);
}
if (api == Opcodes.ASM8_EXPERIMENTAL) {
Constants.checkAsm8Experimental(this);
}
// SPRING PATCH: no preview mode check for ASM 8 experimental
this.api = api;
this.av = annotationVisitor;
}

View File

@ -74,9 +74,7 @@ public abstract class ClassVisitor {
&& api != Opcodes.ASM8_EXPERIMENTAL) {
throw new IllegalArgumentException("Unsupported api " + api);
}
if (api == Opcodes.ASM8_EXPERIMENTAL) {
Constants.checkAsm8Experimental(this);
}
// SPRING PATCH: no preview mode check for ASM 8 experimental
this.api = api;
this.cv = classVisitor;
}

View File

@ -27,11 +27,6 @@
// THE POSSIBILITY OF SUCH DAMAGE.
package org.springframework.asm;
import java.io.DataInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.regex.Pattern;
/**
* Defines additional JVM opcodes, access flags and constants which are not part of the ASM public
* API.
@ -61,8 +56,7 @@ final class Constants implements Opcodes {
static final String RUNTIME_VISIBLE_ANNOTATIONS = "RuntimeVisibleAnnotations";
static final String RUNTIME_INVISIBLE_ANNOTATIONS = "RuntimeInvisibleAnnotations";
static final String RUNTIME_VISIBLE_PARAMETER_ANNOTATIONS = "RuntimeVisibleParameterAnnotations";
static final String RUNTIME_INVISIBLE_PARAMETER_ANNOTATIONS =
"RuntimeInvisibleParameterAnnotations";
static final String RUNTIME_INVISIBLE_PARAMETER_ANNOTATIONS = "RuntimeInvisibleParameterAnnotations";
static final String RUNTIME_VISIBLE_TYPE_ANNOTATIONS = "RuntimeVisibleTypeAnnotations";
static final String RUNTIME_INVISIBLE_TYPE_ANNOTATIONS = "RuntimeInvisibleTypeAnnotations";
static final String ANNOTATION_DEFAULT = "AnnotationDefault";
@ -181,41 +175,4 @@ final class Constants implements Opcodes {
static final int ASM_GOTO_W = 220;
private Constants() {}
static void checkAsm8Experimental(final Object caller) {
Class<?> callerClass = caller.getClass();
String internalName = callerClass.getName().replace('.', '/');
if (!isWhitelisted(internalName)) {
checkIsPreview(callerClass.getClassLoader().getResourceAsStream(internalName + ".class"));
}
}
static boolean isWhitelisted(final String internalName) {
if (!internalName.startsWith("org/objectweb/asm/")) {
return false;
}
String member = "(Annotation|Class|Field|Method|Module|RecordComponent|Signature)";
return internalName.contains("Test$")
|| Pattern.matches(
"org/objectweb/asm/util/Trace" + member + "Visitor(\\$.*)?", internalName)
|| Pattern.matches(
"org/objectweb/asm/util/Check" + member + "Adapter(\\$.*)?", internalName);
}
static void checkIsPreview(final InputStream classInputStream) {
if (classInputStream == null) {
throw new IllegalStateException("Bytecode not available, can't check class version");
}
int minorVersion;
try (DataInputStream callerClassStream = new DataInputStream(classInputStream); ) {
callerClassStream.readInt();
minorVersion = callerClassStream.readUnsignedShort();
} catch (IOException ioe) {
throw new IllegalStateException("I/O error, can't check class version", ioe);
}
if (minorVersion != 0xFFFF) {
throw new IllegalStateException(
"ASM8_EXPERIMENTAL can only be used by classes compiled with --enable-preview");
}
}
}

View File

@ -72,9 +72,7 @@ public abstract class FieldVisitor {
&& api != Opcodes.ASM8_EXPERIMENTAL) {
throw new IllegalArgumentException("Unsupported api " + api);
}
if (api == Opcodes.ASM8_EXPERIMENTAL) {
Constants.checkAsm8Experimental(this);
}
// SPRING PATCH: no preview mode check for ASM 8 experimental
this.api = api;
this.fv = fieldVisitor;
}

View File

@ -88,9 +88,7 @@ public abstract class MethodVisitor {
&& api != Opcodes.ASM8_EXPERIMENTAL) {
throw new IllegalArgumentException("Unsupported api " + api);
}
if (api == Opcodes.ASM8_EXPERIMENTAL) {
Constants.checkAsm8Experimental(this);
}
// SPRING PATCH: no preview mode check for ASM 8 experimental
this.api = api;
this.mv = methodVisitor;
}

View File

@ -74,9 +74,7 @@ public abstract class ModuleVisitor {
&& api != Opcodes.ASM8_EXPERIMENTAL) {
throw new IllegalArgumentException("Unsupported api " + api);
}
if (api == Opcodes.ASM8_EXPERIMENTAL) {
Constants.checkAsm8Experimental(this);
}
// SPRING PATCH: no preview mode check for ASM 8 experimental
this.api = api;
this.mv = moduleVisitor;
}

View File

@ -80,9 +80,7 @@ public abstract class RecordComponentVisitor {
&& api != Opcodes.ASM8_EXPERIMENTAL) {
throw new IllegalArgumentException("Unsupported api " + api);
}
if (api == Opcodes.ASM8_EXPERIMENTAL) {
Constants.checkAsm8Experimental(this);
}
// SPRING PATCH: no preview mode check for ASM 8 experimental
this.api = api;
this.delegate = recordComponentVisitor;
}

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -31,8 +31,9 @@ public final class SpringAsmInfo {
/**
* The ASM compatibility version for Spring's ASM visitor implementations:
* currently {@link Opcodes#ASM7}, as of Spring Framework 5.1.
* currently {@link Opcodes#ASM8_EXPERIMENTAL}, as of Spring Framework 5.2.5.
*/
public static final int ASM_VERSION = Opcodes.ASM7;
@SuppressWarnings("deprecation")
public static final int ASM_VERSION = Opcodes.ASM8_EXPERIMENTAL;
}