Skip to content

Commit 2c3618f

Browse files
committed
Updated ASM to 9.2
Signed-off-by: jansupol <[email protected]>
1 parent bb78d64 commit 2c3618f

File tree

6 files changed

+31
-8
lines changed

6 files changed

+31
-8
lines changed

core-server/src/main/java/jersey/repackaged/org/objectweb/asm/ClassReader.java

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,9 @@ public class ClassReader {
8888
*/
8989
static final int EXPAND_ASM_INSNS = 256;
9090

91+
/** The maximum size of array to allocate. */
92+
private static final int MAX_BUFFER_SIZE = 1024 * 1024;
93+
9194
/** The size of the temporary byte array used to read class input streams chunk by chunk. */
9295
private static final int INPUT_STREAM_DATA_CHUNK_SIZE = 4096;
9396

@@ -191,7 +194,7 @@ public ClassReader(
191194
this.b = classFileBuffer;
192195
// Check the class' major_version. This field is after the magic and minor_version fields, which
193196
// use 4 and 2 bytes respectively.
194-
if (checkClassVersion && readShort(classFileOffset + 6) > Opcodes.V17) {
197+
if (checkClassVersion && readShort(classFileOffset + 6) > Opcodes.V18) {
195198
throw new IllegalArgumentException(
196199
"Unsupported class file major version " + readShort(classFileOffset + 6));
197200
}
@@ -310,13 +313,19 @@ private static byte[] readStream(final InputStream inputStream, final boolean cl
310313
if (inputStream == null) {
311314
throw new IOException("Class not found");
312315
}
316+
int bufferSize = calculateBufferSize(inputStream);
313317
try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) {
314-
byte[] data = new byte[INPUT_STREAM_DATA_CHUNK_SIZE];
318+
byte[] data = new byte[bufferSize];
315319
int bytesRead;
316-
while ((bytesRead = inputStream.read(data, 0, data.length)) != -1) {
320+
int readCount = 0;
321+
while ((bytesRead = inputStream.read(data, 0, bufferSize)) != -1) {
317322
outputStream.write(data, 0, bytesRead);
323+
readCount++;
318324
}
319325
outputStream.flush();
326+
if (readCount == 1) {
327+
return data;
328+
}
320329
return outputStream.toByteArray();
321330
} finally {
322331
if (close) {
@@ -325,6 +334,19 @@ private static byte[] readStream(final InputStream inputStream, final boolean cl
325334
}
326335
}
327336

337+
private static int calculateBufferSize(final InputStream inputStream) throws IOException {
338+
int expectedLength = inputStream.available();
339+
/*
340+
* Some implementations can return 0 while holding available data
341+
* (e.g. new FileInputStream("/proc/a_file"))
342+
* Also in some pathological cases a very small number might be returned,
343+
* and in this case we use default size
344+
*/
345+
if (expectedLength < 256) {
346+
return INPUT_STREAM_DATA_CHUNK_SIZE;
347+
}
348+
return Math.min(expectedLength, MAX_BUFFER_SIZE);
349+
}
328350
// -----------------------------------------------------------------------------------------------
329351
// Accessors
330352
// -----------------------------------------------------------------------------------------------

core-server/src/main/java/jersey/repackaged/org/objectweb/asm/ClassVisitor.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@
3030
/**
3131
* A visitor to visit a Java class. The methods of this class must be called in the following order:
3232
* {@code visit} [ {@code visitSource} ] [ {@code visitModule} ][ {@code visitNestHost} ][ {@code
33-
* visitPermittedSubclass} ][ {@code visitOuterClass} ] ( {@code visitAnnotation} | {@code
34-
* visitTypeAnnotation} | {@code visitAttribute} )* ( {@code visitNestMember} | {@code
33+
* visitOuterClass} ] ( {@code visitAnnotation} | {@code visitTypeAnnotation} | {@code
34+
* visitAttribute} )* ( {@code visitNestMember} | [ {@code * visitPermittedSubclass} ] | {@code
3535
* visitInnerClass} | {@code visitRecordComponent} | {@code visitField} | {@code visitMethod} )*
3636
* {@code visitEnd}.
3737
*

core-server/src/main/java/jersey/repackaged/org/objectweb/asm/ClassWriter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public class ClassWriter extends ClassVisitor {
7979

8080
/**
8181
* The access_flags field of the JVMS ClassFile structure. This field can contain ASM specific
82-
* access flags, such as {@link Opcodes#ACC_DEPRECATED} or {}@link Opcodes#ACC_RECORD}, which are
82+
* access flags, such as {@link Opcodes#ACC_DEPRECATED} or {@link Opcodes#ACC_RECORD}, which are
8383
* removed when generating the ClassFile structure.
8484
*/
8585
private int accessFlags;

core-server/src/main/java/jersey/repackaged/org/objectweb/asm/Opcodes.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,7 @@ public interface Opcodes {
283283
int V15 = 0 << 16 | 59;
284284
int V16 = 0 << 16 | 60;
285285
int V17 = 0 << 16 | 61;
286+
int V18 = 0 << 16 | 62;
286287

287288
/**
288289
* Version flag indicating that the class is using 'preview' features.

core-server/src/main/java/org/glassfish/jersey/server/internal/scanning/AnnotationAcceptingListener.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ private Class getClassForName(final String className) {
303303

304304
private static class ClassReaderWrapper {
305305
private static final Logger LOGGER = Logger.getLogger(ClassReader.class.getName());
306-
private static final int WARN_VERSION = Opcodes.V17;
306+
private static final int WARN_VERSION = Opcodes.V18;
307307
private static final int INPUT_STREAM_DATA_CHUNK_SIZE = 4096;
308308

309309
private final byte[] b;

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2086,7 +2086,7 @@
20862086
<jersey.version>${project.version}</jersey.version>
20872087
<!-- asm is now source integrated - keeping this property to see the version -->
20882088
<!-- see core-server/src/main/java/jersey/repackaged/asm/.. -->
2089-
<asm.version>9.1</asm.version>
2089+
<asm.version>9.2</asm.version>
20902090
<bnd.plugin.version>2.3.6</bnd.plugin.version>
20912091
<cdi.api.version>1.1</cdi.api.version>
20922092
<cdi2.api.version>2.0.2</cdi2.api.version>

0 commit comments

Comments
 (0)