From 94574b0ad2440a247c3aee239e600efb215d62c3 Mon Sep 17 00:00:00 2001 From: jansupol Date: Wed, 24 Mar 2021 22:31:30 +0100 Subject: [PATCH] Adopt ASM 9.1 to support JDK 17 Signed-off-by: jansupol --- .../org/objectweb/asm/AnnotationVisitor.java | 4 ++-- .../org/objectweb/asm/ClassReader.java | 24 ++++++++++++++----- .../repackaged/org/objectweb/asm/Opcodes.java | 5 ++-- .../scanning/AnnotationAcceptingListener.java | 4 ++-- pom.xml | 2 +- 5 files changed, 26 insertions(+), 13 deletions(-) diff --git a/core-server/src/main/java/jersey/repackaged/org/objectweb/asm/AnnotationVisitor.java b/core-server/src/main/java/jersey/repackaged/org/objectweb/asm/AnnotationVisitor.java index 33293bb473..8ca2039014 100644 --- a/core-server/src/main/java/jersey/repackaged/org/objectweb/asm/AnnotationVisitor.java +++ b/core-server/src/main/java/jersey/repackaged/org/objectweb/asm/AnnotationVisitor.java @@ -131,9 +131,9 @@ public AnnotationVisitor visitAnnotation(final String name, final String descrip } /** - * Visits an array value of the annotation. Note that arrays of primitive types (such as byte, + * Visits an array value of the annotation. Note that arrays of primitive values (such as byte, * boolean, short, char, int, long, float or double) can be passed as value to {@link #visit - * visit}. This is what {@link ClassReader} does. + * visit}. This is what {@link ClassReader} does for non empty arrays of primitive values. * * @param name the value name. * @return a visitor to visit the actual array value elements, or {@literal null} if this visitor diff --git a/core-server/src/main/java/jersey/repackaged/org/objectweb/asm/ClassReader.java b/core-server/src/main/java/jersey/repackaged/org/objectweb/asm/ClassReader.java index 25015fdd18..a46fdad3e1 100644 --- a/core-server/src/main/java/jersey/repackaged/org/objectweb/asm/ClassReader.java +++ b/core-server/src/main/java/jersey/repackaged/org/objectweb/asm/ClassReader.java @@ -100,8 +100,10 @@ public class ClassReader { @Deprecated // DontCheck(MemberName): can't be renamed (for backward binary compatibility). public final byte[] b; + /** The offset in bytes of the ClassFile's access_flags field. */ public final int header; + /** * A byte array containing the JVMS ClassFile structure to be parsed. The content of this array * must not be modified. This field is intended for {@link Attribute} sub classes, and is normally @@ -112,6 +114,7 @@ public class ClassReader { * ClassFile element offsets within this byte array. */ final byte[] classFileBuffer; + /** * The offset in bytes, in {@link #classFileBuffer}, of each cp_info entry of the ClassFile's * constant_pool array, plus one. In other words, the offset of constant pool entry i is @@ -119,16 +122,19 @@ public class ClassReader { * 1]. */ private final int[] cpInfoOffsets; + /** * The String objects corresponding to the CONSTANT_Utf8 constant pool items. This cache avoids * multiple parsing of a given CONSTANT_Utf8 constant pool item. */ private final String[] constantUtf8Values; + /** * The ConstantDynamic objects corresponding to the CONSTANT_Dynamic constant pool items. This * cache avoids multiple parsing of a given CONSTANT_Dynamic constant pool item. */ private final ConstantDynamic[] constantDynamicValues; + /** * The start offsets in {@link #classFileBuffer} of each element of the bootstrap_methods array * (in the BootstrapMethods attribute). @@ -137,6 +143,7 @@ public class ClassReader { * 4.7.23 */ private final int[] bootstrapMethodOffsets; + /** * A conservative estimate of the maximum length of the strings contained in the constant pool of * the class. @@ -184,7 +191,7 @@ public ClassReader( this.b = classFileBuffer; // Check the class' major_version. This field is after the magic and minor_version fields, which // use 4 and 2 bytes respectively. - if (checkClassVersion && readShort(classFileOffset + 6) > Opcodes.V16) { + if (checkClassVersion && readShort(classFileOffset + 6) > Opcodes.V17) { throw new IllegalArgumentException( "Unsupported class file major version " + readShort(classFileOffset + 6)); } @@ -499,6 +506,9 @@ public void accept( } else if (Constants.SYNTHETIC.equals(attributeName)) { accessFlags |= Opcodes.ACC_SYNTHETIC; } else if (Constants.SOURCE_DEBUG_EXTENSION.equals(attributeName)) { + if (attributeLength > classFileBuffer.length - currentAttributeOffset) { + throw new IllegalArgumentException(); + } sourceDebugExtension = readUtf(currentAttributeOffset, attributeLength, new char[attributeLength]); } else if (Constants.RUNTIME_INVISIBLE_ANNOTATIONS.equals(attributeName)) { @@ -1509,6 +1519,9 @@ private void readCode( final int maxLocals = readUnsignedShort(currentOffset + 2); final int codeLength = readInt(currentOffset + 4); currentOffset += 8; + if (codeLength > classFileBuffer.length - currentOffset) { + throw new IllegalArgumentException(); + } // Read the bytecode 'code' array to create a label for each referenced instruction. final int bytecodeStartOffset = currentOffset; @@ -3438,7 +3451,6 @@ final int getFirstAttributeOffset() { private int[] readBootstrapMethodsAttribute(final int maxStringLength) { char[] charBuffer = new char[maxStringLength]; int currentAttributeOffset = getFirstAttributeOffset(); - int[] currentBootstrapMethodOffsets = null; for (int i = readUnsignedShort(currentAttributeOffset - 2); i > 0; --i) { // Read the attribute_info's attribute_name and attribute_length fields. String attributeName = readUTF8(currentAttributeOffset, charBuffer); @@ -3446,17 +3458,17 @@ private int[] readBootstrapMethodsAttribute(final int maxStringLength) { currentAttributeOffset += 6; if (Constants.BOOTSTRAP_METHODS.equals(attributeName)) { // Read the num_bootstrap_methods field and create an array of this size. - currentBootstrapMethodOffsets = new int[readUnsignedShort(currentAttributeOffset)]; + int[] result = new int[readUnsignedShort(currentAttributeOffset)]; // Compute and store the offset of each 'bootstrap_methods' array field entry. int currentBootstrapMethodOffset = currentAttributeOffset + 2; - for (int j = 0; j < currentBootstrapMethodOffsets.length; ++j) { - currentBootstrapMethodOffsets[j] = currentBootstrapMethodOffset; + for (int j = 0; j < result.length; ++j) { + result[j] = currentBootstrapMethodOffset; // Skip the bootstrap_method_ref and num_bootstrap_arguments fields (2 bytes each), // as well as the bootstrap_arguments array field (of size num_bootstrap_arguments * 2). currentBootstrapMethodOffset += 4 + readUnsignedShort(currentBootstrapMethodOffset + 2) * 2; } - return currentBootstrapMethodOffsets; + return result; } currentAttributeOffset += attributeLength; } diff --git a/core-server/src/main/java/jersey/repackaged/org/objectweb/asm/Opcodes.java b/core-server/src/main/java/jersey/repackaged/org/objectweb/asm/Opcodes.java index f9beb52256..9e9bdd770d 100644 --- a/core-server/src/main/java/jersey/repackaged/org/objectweb/asm/Opcodes.java +++ b/core-server/src/main/java/jersey/repackaged/org/objectweb/asm/Opcodes.java @@ -133,7 +133,7 @@ public interface Opcodes { *
    * public class StuffVisitor {
    *   @Deprecated public void visitOldStuff(int arg, ...) {
-   *     visitNewStuf(arg | SOURCE_DEPRECATED, ...);
+   *     visitNewStuff(arg | SOURCE_DEPRECATED, ...);
    *   }
    *   public void visitNewStuff(int argAndSource...) {
    *     if ((argAndSource & SOURCE_DEPRECATED) == 0) {
@@ -155,7 +155,7 @@ public interface Opcodes {
    * 

and there are two cases: * *

    - *
  • call visitOldSuff: in the call to super.visitOldStuff, the source is set to + *
  • call visitOldStuff: in the call to super.visitOldStuff, the source is set to * SOURCE_DEPRECATED and visitNewStuff is called. Here 'do stuff' is run because the source * was previously set to SOURCE_DEPRECATED, and execution eventually returns to * UserStuffVisitor.visitOldStuff, where 'do user stuff' is run. @@ -282,6 +282,7 @@ public interface Opcodes { int V14 = 0 << 16 | 58; int V15 = 0 << 16 | 59; int V16 = 0 << 16 | 60; + int V17 = 0 << 16 | 61; /** * Version flag indicating that the class is using 'preview' features. diff --git a/core-server/src/main/java/org/glassfish/jersey/server/internal/scanning/AnnotationAcceptingListener.java b/core-server/src/main/java/org/glassfish/jersey/server/internal/scanning/AnnotationAcceptingListener.java index 5efc6bae45..96e840c1c2 100644 --- a/core-server/src/main/java/org/glassfish/jersey/server/internal/scanning/AnnotationAcceptingListener.java +++ b/core-server/src/main/java/org/glassfish/jersey/server/internal/scanning/AnnotationAcceptingListener.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012, 2020 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2012, 2021 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0, which is available at @@ -303,7 +303,7 @@ private Class getClassForName(final String className) { private static class ClassReaderWrapper { private static final Logger LOGGER = Logger.getLogger(ClassReader.class.getName()); - private static final int WARN_VERSION = Opcodes.V16; + private static final int WARN_VERSION = Opcodes.V17; private static final int INPUT_STREAM_DATA_CHUNK_SIZE = 4096; private final byte[] b; diff --git a/pom.xml b/pom.xml index adffc3425c..1fc6714b58 100644 --- a/pom.xml +++ b/pom.xml @@ -2068,7 +2068,7 @@ ${project.version} - 9.0 + 9.1 2.3.6 1.1 3.3.2