From cb36ca31f6a9e973490ac9f698edd3dca99e1ecf Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Fri, 25 Mar 2022 18:07:12 +0100 Subject: [PATCH] Upgrade to ASM master --- .../org/springframework/asm/ClassReader.java | 13 ++++--- .../org/springframework/asm/ClassWriter.java | 34 +++++++++++++++---- 2 files changed, 34 insertions(+), 13 deletions(-) diff --git a/spring-core/src/main/java/org/springframework/asm/ClassReader.java b/spring-core/src/main/java/org/springframework/asm/ClassReader.java index 1b14e0e02a38..725ba340bbe7 100644 --- a/spring-core/src/main/java/org/springframework/asm/ClassReader.java +++ b/spring-core/src/main/java/org/springframework/asm/ClassReader.java @@ -313,7 +313,7 @@ private static byte[] readStream(final InputStream inputStream, final boolean cl if (inputStream == null) { throw new IOException("Class not found"); } - int bufferSize = calculateBufferSize(inputStream); + int bufferSize = computeBufferSize(inputStream); try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) { byte[] data = new byte[bufferSize]; int bytesRead; @@ -336,13 +336,12 @@ private static byte[] readStream(final InputStream inputStream, final boolean cl } } - private static int calculateBufferSize(final InputStream inputStream) throws IOException { + private static int computeBufferSize(final InputStream inputStream) throws IOException { int expectedLength = inputStream.available(); /* - * Some implementations can return 0 while holding available data - * (e.g. new FileInputStream("/proc/a_file")) - * Also in some pathological cases a very small number might be returned, - * and in this case we use default size + * Some implementations can return 0 while holding available data (e.g. new + * FileInputStream("/proc/a_file")). Also in some pathological cases a very small number might + * be returned, and in this case we use a default size. */ if (expectedLength < 256) { return INPUT_STREAM_DATA_CHUNK_SIZE; @@ -861,7 +860,7 @@ private void readModuleAttributes( currentOffset += 2; } - // Read the 'provides_count' and 'provides' fields. + // Read the 'provides_count' and 'provides' fields. int providesCount = readUnsignedShort(currentOffset); currentOffset += 2; while (providesCount-- > 0) { diff --git a/spring-core/src/main/java/org/springframework/asm/ClassWriter.java b/spring-core/src/main/java/org/springframework/asm/ClassWriter.java index de285663ee95..045d57131273 100644 --- a/spring-core/src/main/java/org/springframework/asm/ClassWriter.java +++ b/spring-core/src/main/java/org/springframework/asm/ClassWriter.java @@ -65,6 +65,12 @@ public class ClassWriter extends ClassVisitor { */ public static final int COMPUTE_FRAMES = 2; + /** + * The flags passed to the constructor. Must be zero or more of {@link #COMPUTE_MAXS} and {@link + * #COMPUTE_FRAMES}. + */ + private final int flags; + // Note: fields are ordered as in the ClassFile structure, and those related to attributes are // ordered as in Section 4.7 of the JVMS. @@ -248,23 +254,39 @@ public ClassWriter(final int flags) { * @param classReader the {@link ClassReader} used to read the original class. It will be used to * copy the entire constant pool and bootstrap methods from the original class and also to * copy other fragments of original bytecode where applicable. - * @param flags option flags that can be used to modify the default behavior of this class.Must be - * zero or more of {@link #COMPUTE_MAXS} and {@link #COMPUTE_FRAMES}. These option flags do - * not affect methods that are copied as is in the new class. This means that neither the + * @param flags option flags that can be used to modify the default behavior of this class. Must + * be zero or more of {@link #COMPUTE_MAXS} and {@link #COMPUTE_FRAMES}. These option flags + * do not affect methods that are copied as is in the new class. This means that neither the * maximum stack size nor the stack frames will be computed for these methods. */ public ClassWriter(final ClassReader classReader, final int flags) { super(/* latest api = */ Opcodes.ASM9); + this.flags = flags; symbolTable = classReader == null ? new SymbolTable(this) : new SymbolTable(this, classReader); if ((flags & COMPUTE_FRAMES) != 0) { - this.compute = MethodWriter.COMPUTE_ALL_FRAMES; + compute = MethodWriter.COMPUTE_ALL_FRAMES; } else if ((flags & COMPUTE_MAXS) != 0) { - this.compute = MethodWriter.COMPUTE_MAX_STACK_AND_LOCAL; + compute = MethodWriter.COMPUTE_MAX_STACK_AND_LOCAL; } else { - this.compute = MethodWriter.COMPUTE_NOTHING; + compute = MethodWriter.COMPUTE_NOTHING; } } + // ----------------------------------------------------------------------------------------------- + // Accessors + // ----------------------------------------------------------------------------------------------- + + /** + * Returns true if all the given flags were passed to the constructor. + * + * @param flags some option flags. Must be zero or more of {@link #COMPUTE_MAXS} and {@link + * #COMPUTE_FRAMES}. + * @return true if all the given flags, or more, were passed to the constructor. + */ + public boolean hasFlags(final int flags) { + return (this.flags & flags) == flags; + } + // ----------------------------------------------------------------------------------------------- // Implementation of the ClassVisitor abstract class // -----------------------------------------------------------------------------------------------