Skip to content

Commit cb36ca3

Browse files
committed
Upgrade to ASM master
1 parent edd66d9 commit cb36ca3

File tree

2 files changed

+34
-13
lines changed

2 files changed

+34
-13
lines changed

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

+6-7
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ private static byte[] readStream(final InputStream inputStream, final boolean cl
313313
if (inputStream == null) {
314314
throw new IOException("Class not found");
315315
}
316-
int bufferSize = calculateBufferSize(inputStream);
316+
int bufferSize = computeBufferSize(inputStream);
317317
try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) {
318318
byte[] data = new byte[bufferSize];
319319
int bytesRead;
@@ -336,13 +336,12 @@ private static byte[] readStream(final InputStream inputStream, final boolean cl
336336
}
337337
}
338338

339-
private static int calculateBufferSize(final InputStream inputStream) throws IOException {
339+
private static int computeBufferSize(final InputStream inputStream) throws IOException {
340340
int expectedLength = inputStream.available();
341341
/*
342-
* Some implementations can return 0 while holding available data
343-
* (e.g. new FileInputStream("/proc/a_file"))
344-
* Also in some pathological cases a very small number might be returned,
345-
* and in this case we use default size
342+
* Some implementations can return 0 while holding available data (e.g. new
343+
* FileInputStream("/proc/a_file")). Also in some pathological cases a very small number might
344+
* be returned, and in this case we use a default size.
346345
*/
347346
if (expectedLength < 256) {
348347
return INPUT_STREAM_DATA_CHUNK_SIZE;
@@ -861,7 +860,7 @@ private void readModuleAttributes(
861860
currentOffset += 2;
862861
}
863862

864-
// Read the 'provides_count' and 'provides' fields.
863+
// Read the 'provides_count' and 'provides' fields.
865864
int providesCount = readUnsignedShort(currentOffset);
866865
currentOffset += 2;
867866
while (providesCount-- > 0) {

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

+28-6
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,12 @@ public class ClassWriter extends ClassVisitor {
6565
*/
6666
public static final int COMPUTE_FRAMES = 2;
6767

68+
/**
69+
* The flags passed to the constructor. Must be zero or more of {@link #COMPUTE_MAXS} and {@link
70+
* #COMPUTE_FRAMES}.
71+
*/
72+
private final int flags;
73+
6874
// Note: fields are ordered as in the ClassFile structure, and those related to attributes are
6975
// ordered as in Section 4.7 of the JVMS.
7076

@@ -248,23 +254,39 @@ public ClassWriter(final int flags) {
248254
* @param classReader the {@link ClassReader} used to read the original class. It will be used to
249255
* copy the entire constant pool and bootstrap methods from the original class and also to
250256
* copy other fragments of original bytecode where applicable.
251-
* @param flags option flags that can be used to modify the default behavior of this class.Must be
252-
* zero or more of {@link #COMPUTE_MAXS} and {@link #COMPUTE_FRAMES}. <i>These option flags do
253-
* not affect methods that are copied as is in the new class. This means that neither the
257+
* @param flags option flags that can be used to modify the default behavior of this class. Must
258+
* be zero or more of {@link #COMPUTE_MAXS} and {@link #COMPUTE_FRAMES}. <i>These option flags
259+
* do not affect methods that are copied as is in the new class. This means that neither the
254260
* maximum stack size nor the stack frames will be computed for these methods</i>.
255261
*/
256262
public ClassWriter(final ClassReader classReader, final int flags) {
257263
super(/* latest api = */ Opcodes.ASM9);
264+
this.flags = flags;
258265
symbolTable = classReader == null ? new SymbolTable(this) : new SymbolTable(this, classReader);
259266
if ((flags & COMPUTE_FRAMES) != 0) {
260-
this.compute = MethodWriter.COMPUTE_ALL_FRAMES;
267+
compute = MethodWriter.COMPUTE_ALL_FRAMES;
261268
} else if ((flags & COMPUTE_MAXS) != 0) {
262-
this.compute = MethodWriter.COMPUTE_MAX_STACK_AND_LOCAL;
269+
compute = MethodWriter.COMPUTE_MAX_STACK_AND_LOCAL;
263270
} else {
264-
this.compute = MethodWriter.COMPUTE_NOTHING;
271+
compute = MethodWriter.COMPUTE_NOTHING;
265272
}
266273
}
267274

275+
// -----------------------------------------------------------------------------------------------
276+
// Accessors
277+
// -----------------------------------------------------------------------------------------------
278+
279+
/**
280+
* Returns true if all the given flags were passed to the constructor.
281+
*
282+
* @param flags some option flags. Must be zero or more of {@link #COMPUTE_MAXS} and {@link
283+
* #COMPUTE_FRAMES}.
284+
* @return true if all the given flags, or more, were passed to the constructor.
285+
*/
286+
public boolean hasFlags(final int flags) {
287+
return (this.flags & flags) == flags;
288+
}
289+
268290
// -----------------------------------------------------------------------------------------------
269291
// Implementation of the ClassVisitor abstract class
270292
// -----------------------------------------------------------------------------------------------

0 commit comments

Comments
 (0)