asm issueshttps://gitlab.ow2.org/asm/asm/-/issues2020-07-07T15:14:45Zhttps://gitlab.ow2.org/asm/asm/-/issues/317911Add support for Java 162020-07-07T15:14:45ZSam BrannenAdd support for Java 16Current attempts to use ASM with `openjdk version "16-ea" 2021-03-16` result in an exception along the lines of:
> Unsupported class file major version 60
Please add milestone support for Java 16 early access builds.Current attempts to use ASM with `openjdk version "16-ea" 2021-03-16` result in an exception along the lines of:
> Unsupported class file major version 60
Please add milestone support for Java 16 early access builds.https://gitlab.ow2.org/asm/asm/-/issues/317815ASM 6.1: ClassReader.readCode() throws NullPointerException2018-03-26T23:33:46ZSemyon LevinASM 6.1: ClassReader.readCode() throws NullPointerException```java
class ClassReader {
// ...
private void readCode(
final MethodVisitor methodVisitor, final Context context, final int codeOffset) {
// ...
if (invisibleTypeAnnotationOffsets != null) { // <-- **in**visibleTypeAn...```java
class ClassReader {
// ...
private void readCode(
final MethodVisitor methodVisitor, final Context context, final int codeOffset) {
// ...
if (invisibleTypeAnnotationOffsets != null) { // <-- **in**visibleTypeAnnotationOffsets here
for (int i = 0; i < invisibleTypeAnnotationOffsets.length; ++i) { // <-- **in**visibleTypeAnnotationOffsets here
int targetType = readByte(visibleTypeAnnotationOffsets[i]); // <-- visibleTypeAnnotationOffsets here (line 2354)
// ...
}
}
// ...
}
// ...
}
```
As you can see we check that **in**visibleTypeAnnotationOffsets is not null, but then we read a byte from visibleTypeAnnotationOffsets. It can be a misprint...
ASM 6.0 works correctly.https://gitlab.ow2.org/asm/asm/-/issues/317609Enhance ClassWriter to take a class loader for use with getCommonSuperClass2018-06-16T14:32:51ZnmccloudEnhance ClassWriter to take a class loader for use with getCommonSuperClass```
Would it be possible to add another constructor to
org.objectweb.asm.ClassWriter to take a ClassLoader that will be used with
getCommonSuperClass. This will eliminate the need to extend this class by
the end-developer. Both Clas...```
Would it be possible to add another constructor to
org.objectweb.asm.ClassWriter to take a ClassLoader that will be used with
getCommonSuperClass. This will eliminate the need to extend this class by
the end-developer. Both ClassWriter(ClassReader, int, ClassLoader) and
ClassWriter(int, ClassLoader) could be created easily.
Thanks,
Ken
```https://gitlab.ow2.org/asm/asm/-/issues/317988Interface not being added to class2022-11-27T09:17:18ZAlex HoweInterface not being added to classI'm trying to make the Minecraft class implement my MinecraftBridge interface using
```kt
node.interfaces.add(Type.getInternalName(MinecraftBridge::class.java))
```
When I add it to my own MinecraftBridgeImpl class it adds fine using the...I'm trying to make the Minecraft class implement my MinecraftBridge interface using
```kt
node.interfaces.add(Type.getInternalName(MinecraftBridge::class.java))
```
When I add it to my own MinecraftBridgeImpl class it adds fine using the same code but when I try to add it to the Minecraft class it doesnt add it. No errors are thrown it just writes it without the added interface.
### Expected Behavior
The MinecraftBridge interface is added to the Minecraft class.
### Current Behavior
The MinecraftBridge interface is not added to the Minecraft class.
### Steps to Reproduce
This is the MinecraftBridge interface I'm trying to implement along with the LocalPlayerBridge
```java
public interface LocalPlayerBridge {
void addChatMessage(String msg);
}
public interface MinecraftBridge {
LocalPlayerBridge getLocalPlayer();
}
```
```kt
val reader = ClassReader(/* The Minecraft class bytes */)
val node = ClassNode()
reader.accept(node, 0)
node.interfaces.add(Type.getInternalName(MinecraftBridge::class.java))
val cw = ClassWriter(reader, ClassWriter.COMPUTE_FRAMES)
node.accept(cw)
val bytes = cw.toByteArray()
```
## Example Class Files
The .class is the original class I'm trying to add the interface to. The .modif.class is what ow2.asm
[MinecraftPatch.class](/uploads/c94326e95463a70cd4484194cb31e7fa/MinecraftPatch.class)
[MinecraftPatch.modif.class](/uploads/5a8bf5abcae41b50095c2d78574d040c/MinecraftPatch.modif.class)
[MinecraftBridgeImplPatch.class](/uploads/532a199c44b0463256f905721dc9de1a/MinecraftBridgeImplPatch.class)
[MinecraftBridgeImplPatch.modif.class](/uploads/dcac94cee0b0a2a6d26be642b6ab282c/MinecraftBridgeImplPatch.modif.class)https://gitlab.ow2.org/asm/asm/-/issues/317985Erroneous stack map frame exception after move from 9.3 to 9.42022-11-10T16:16:03ZDavid GoodenoughErroneous stack map frame exception after move from 9.3 to 9.4I have come code that takes existing classes and adds extra methods (one normal method and one constructor) to those classes.
The existing classes are produced by Scala 3.2.0 (I have not tried earlier versions).
When processing the vis...I have come code that takes existing classes and adds extra methods (one normal method and one constructor) to those classes.
The existing classes are produced by Scala 3.2.0 (I have not tried earlier versions).
When processing the visitEnd I get:-
Exception in thread "main" java.lang.IllegalArgumentException: Error at instruction 14: Stack map frame incompatible with frame at instruction 32 (incompatible types at local 3: . and R) $anonfun$6(Luk/co/dga/pdf2odoo/ScanData;Luk/co/dga/pdf2odoo/ItemLine;)Luk/co/dga/pdf2odoo/ScanData;
00000 R R R . . . : : L0
00001 R R . . . . : : LINENUMBER 383 L0
00002 R R . . . . : : ALOAD 1
00003 R R . . . . : R : INVOKEVIRTUAL uk/co/dga/pdf2odoo/ItemLine.newLine ()Z
00004 R R . . . . : I : IFEQ L1
00005 R R . . . . : : L2
00006 R R . . . . : : LINENUMBER 384 L2
00007 R R . . . . : : ALOAD 0
00008 R R . . . . : R : INVOKEVIRTUAL uk/co/dga/pdf2odoo/ScanData.pending ()Lscala/Option;
00009 R R . . . . : R : ASTORE 2
00010 R R R . . . : : L3
00011 R R R . . . : : LINENUMBER 385 L3
00012 R R R . . . : : ALOAD 2
00013 R R R . . . : R : INSTANCEOF scala/Some
00014 R R R . . . : I : IFEQ L4
00015 ? : ALOAD 2
00016 ? : CHECKCAST scala/Some
00017 ? : INVOKEVIRTUAL scala/Some.value ()Ljava/lang/Object;
00018 ? : CHECKCAST uk/co/dga/pdf2odoo/ItemLine
00019 ? : ASTORE 3
00020 ? : L5
00021 ? : GETSTATIC uk/co/dga/pdf2odoo/ScanData$.MODULE$ : Luk/co/dga/pdf2odoo/ScanData$;
00022 ? : ALOAD 0
00023 ? : INVOKEVIRTUAL uk/co/dga/pdf2odoo/ScanData.list ()Lscala/collection/immutable/List;
00024 ? : ALOAD 3
00025 ? : INVOKEVIRTUAL scala/collection/immutable/List.$colon$plus (Ljava/lang/Object;)Ljava/lang/Object;
00026 ? : CHECKCAST scala/collection/immutable/List
00027 ? : GETSTATIC scala/Some$.MODULE$ : Lscala/Some$;
00028 ? : ALOAD 1
00029 ? : INVOKEVIRTUAL scala/Some$.apply (Ljava/lang/Object;)Lscala/Some;
00030 ? : INVOKEVIRTUAL uk/co/dga/pdf2odoo/ScanData$.apply (Lscala/collection/immutable/List;Lscala/Option;)Luk/co/dga/pdf2odoo/ScanData;
00031 ? : ARETURN
00032 R R . R . . : : L4
00033 R R . R . . : : LINENUMBER 386 L4
00034 R R . R . . : : FRAME APPEND [scala/Option]
00035 ? : GETSTATIC scala/None$.MODULE$ : Lscala/None$;
00036 ? : ALOAD 2
when I run with 9.4, but with 9.3 I get no such exception. When I run the code with openjdk-17 or openjdk-11 it runs correctly having been processed with 9.3.https://gitlab.ow2.org/asm/asm/-/issues/317973How do I import asm into a modularized application2022-06-12T09:20:02ZDavid BerkmanHow do I import asm into a modularized applicationI can't seem to come up with a magical set of require statements in a module-info.java file that will capture the use of asm core, tree and util and will not result in being told...
Module 'my.module' reads package 'org.objectweb.asm' f...I can't seem to come up with a magical set of require statements in a module-info.java file that will capture the use of asm core, tree and util and will not result in being told...
Module 'my.module' reads package 'org.objectweb.asm' from both 'org.objectweb.asm' and 'org.objectweb.asm'
Any suggestions? Any possibility of adding module-info to asm to provide a clean import?https://gitlab.ow2.org/asm/asm/-/issues/317972ClassVisitor inner class and outer class documentation confusing2022-11-27T08:15:23ZtoadstreetClassVisitor inner class and outer class documentation confusing### Expected Behavior
The documentation on `ClassVisitor.visitInnerClass` should mention it is a few inner class relations observed by this class. For instance, classes that use `invokedynamic` instructions compiled by `javac` usually ha...### Expected Behavior
The documentation on `ClassVisitor.visitInnerClass` should mention it is a few inner class relations observed by this class. For instance, classes that use `invokedynamic` instructions compiled by `javac` usually have the `MethodHandles.Lookup` described as a nested class (static inner class) of `MethodHandles` upon inspection by `javap`.
It should also mention that the member classes and the enclosing class of this class, if any, **must** be described in this attribute per [JVMS 18 - 4.7.6](https://docs.oracle.com/javase/specs/jvms/se18/html/jvms-4.html#jvms-4.7.6).
The documentation for `ClassVisitor.visitOuterClass` should state it is only called for anonymous or local classes, which are defined in method bodies or initializers. In addition, if the class is defined in an initializer, then the `name` and `descriptor` will be `null`. It is not called for instance inner or nested classes, i.e. classes that are direct members of other classes. Refer to [JVMS 18 - 4.7.7](https://docs.oracle.com/javase/specs/jvms/se18/html/jvms-4.html#jvms-4.7.7).
### Current Behavior
The documentation for `ClassVisitor.visitInnerClass` fails to ask users to supply all the member classes and the enclosing class relations of this class.
The documentation for `ClassVisitor.visitOuterClass` fails to mention that it should only be called for anonymous or local classes (i.e. classes defined in method bodies or initializers in source code), and `null` method name and descriptors mean the class is defined in an initializer as opposed to a regular method.
### Notes
In addition, the documentations for the tree API, such as `ClassNode`, should be updated simultaneously.https://gitlab.ow2.org/asm/asm/-/issues/317956Publish Maven BOM2022-03-14T10:17:56ZDavid PhillipsPublish Maven BOMIt would be great if ASM could publish a Maven [Bill of Materials (BOM)](https://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html#bill-of-materials-bom-poms), making it easier to consume ASM and ensure the s...It would be great if ASM could publish a Maven [Bill of Materials (BOM)](https://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html#bill-of-materials-bom-poms), making it easier to consume ASM and ensure the same version is used for all of the ASM artifacts. Consumers would use the BOM like this:
```xml
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.ow2.asm</groupId>
<artifactId>asm-bom</artifactId>
<version>9.2</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
```
Then they can add dependencies for the various artifacts, without specifying versions:
```xml
<dependencies>
<dependency>
<groupId>org.ow2.asm</groupId>
<artifactId>asm</artifactId>
</dependency>
<dependency>
<groupId>org.ow2.asm</groupId>
<artifactId>asm-util</artifactId>
</dependency>
</dependencies>
```
Here's an example of what a BOM looks like: https://search.maven.org/artifact/org.jdbi/jdbi3-bom/3.23.0/pomhttps://gitlab.ow2.org/asm/asm/-/issues/317937Way to retrieve methods that failed conversion in ClassWriter2021-03-07T15:56:34ZAura LeeWay to retrieve methods that failed conversion in ClassWriterWhen I write a ClassNode using ClassWriter and it fails on e.g. frame generation, I get a thrown exception, but there is no way to retrieve the method that it failed in. Can you implement a method in ClassWriter that returns the method i...When I write a ClassNode using ClassWriter and it fails on e.g. frame generation, I get a thrown exception, but there is no way to retrieve the method that it failed in. Can you implement a method in ClassWriter that returns the method it last visited?https://gitlab.ow2.org/asm/asm/-/issues/317932More details on Frame generation Exceptions / Errors2021-03-13T14:27:36ZAura LeeMore details on Frame generation Exceptions / ErrorsI'm trying to find out why my code throws an AssertionError at org.objectweb.asm.Frame.putAbstractType(Frame.java:1465), but the Error gives no information at all why it even happened. This makes it really hard to find out what is wrong ...I'm trying to find out why my code throws an AssertionError at org.objectweb.asm.Frame.putAbstractType(Frame.java:1465), but the Error gives no information at all why it even happened. This makes it really hard to find out what is wrong with my code (see below).
I was experimenting with try catch blocks and weird flow and got this exception with frame generation:
```
java.lang.AssertionError
at org.objectweb.asm.Frame.putAbstractType(Frame.java:1465)
at org.objectweb.asm.MethodWriter.putAbstractTypes(MethodWriter.java:1959)
at org.objectweb.asm.MethodWriter.putFrame(MethodWriter.java:1943)
at org.objectweb.asm.MethodWriter.visitFrameEnd(MethodWriter.java:1850)
at org.objectweb.asm.Frame.accept(Frame.java:1393)
at org.objectweb.asm.MethodWriter.computeAllFrames(MethodWriter.java:1628)
at org.objectweb.asm.MethodWriter.visitMaxs(MethodWriter.java:1546)
```
This was my code which doesn't work with COMPUTE_FRAMES, but works if i move the `tcbEnd` label before the return instruction. (I thought it doesn't matter to the frames where try catch blocks start and end?)
```java
ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS);
cw.visit(V1_6, ACC_PUBLIC | ACC_SUPER, "WeirdError", null, "java/lang/Object", null);
MethodVisitor mv = cw.visitMethod(ACC_PRIVATE, "test", "(Ljava/lang/Object;)V", null, null);
mv.visitCode();
Label tcbStart = new Label();
Label tcbEnd = new Label();
Label tcbHandler = new Label();
mv.visitTryCatchBlock(tcbStart, tcbEnd, tcbHandler, "java/lang/RuntimeException");
Label startLabel = new Label();
mv.visitLabel(startLabel);
mv.visitInsn(ICONST_1);
Label returnLabel = new Label();
mv.visitJumpInsn(IFEQ, returnLabel);
mv.visitInsn(ACONST_NULL);
mv.visitVarInsn(ASTORE, 2);
mv.visitInsn(ICONST_0);
mv.visitVarInsn(ISTORE, 3);
mv.visitInsn(ICONST_0);
mv.visitVarInsn(ISTORE, 4);
Label startCompare = new Label();
mv.visitLabel(startCompare);
mv.visitVarInsn(ILOAD, 4);
mv.visitVarInsn(ILOAD, 3);
Label label9 = new Label();
mv.visitJumpInsn(IF_ICMPGE, label9);
mv.visitVarInsn(ALOAD, 2);
mv.visitVarInsn(ILOAD, 4);
mv.visitInsn(AALOAD);
mv.visitVarInsn(ASTORE, 8);
Label label10 = new Label();
mv.visitLabel(label10);
mv.visitInsn(ACONST_NULL);
mv.visitLabel(tcbStart);
mv.visitInsn(POP);
mv.visitIincInsn(7, 1);
mv.visitVarInsn(ALOAD, 8);
mv.visitInsn(MONITOREXIT);
mv.visitJumpInsn(GOTO, label10);
mv.visitLabel(label9);
mv.visitJumpInsn(GOTO, startLabel);
mv.visitLabel(returnLabel);
mv.visitInsn(RETURN);
mv.visitLabel(tcbEnd);
mv.visitInsn(ACONST_NULL);
mv.visitInsn(ATHROW);
mv.visitLabel(tcbHandler);
mv.visitInsn(POP);
mv.visitJumpInsn(GOTO, startCompare);
mv.visitMaxs(200, 9);
mv.visitEnd();
cw.visitEnd();
Files.write(new File("WeirdError.class").toPath(), cw.toByteArray());
```
It would be nice to have more information on all thrown Throwables in `Frame.java`. (Or maybe this part of the code should actually not be reached, I don't know)https://gitlab.ow2.org/asm/asm/-/issues/317926Problems with latest JDK 16 builds2020-12-21T15:19:16ZFrancesco ChicchiriccoProblems with latest JDK 16 buildsAfter JDK 16 has [started the rampdown phase](https://lists.apache.org/thread.html/r128877311f13a7d18bdaf4e2af021499b0cd235627e916eaffc72b07%40%3Cdev.syncope.apache.org%3E), we could not get our Spring Boot tests working any more - all u...After JDK 16 has [started the rampdown phase](https://lists.apache.org/thread.html/r128877311f13a7d18bdaf4e2af021499b0cd235627e916eaffc72b07%40%3Cdev.syncope.apache.org%3E), we could not get our Spring Boot tests working any more - all used to work with previous JDK 16 releases.
The reported exception is:
```
org.springframework.beans.factory.BeanDefinitionStoreException: Failed to read candidate component class: file [/home/ilgrosso/work/syncope/syncope/wa/starter/target/test-classes/org/apache/syncope/wa/starter/gauth/token/SyncopeWAGoogleMfaAuthTokenRepositoryTest.class]; nested exception is org.springframework.core.NestedIOException: ASM ClassReader failed to parse class file - probably due to a new Java class file version that isn't supported yet: file [/home/ilgrosso/work/syncope/syncope/wa/starter/target/test-classes/org/apache/syncope/wa/starter/gauth/token/SyncopeWAGoogleMfaAuthTokenRepositoryTest.class]; nested exception is java.lang.IllegalArgumentException: Unsupported class file major version 60
Caused by: org.springframework.core.NestedIOException: ASM ClassReader failed to parse class file - probably due to a new Java class file version that isn't supported yet: file [/home/ilgrosso/work/syncope/syncope/wa/starter/target/test-classes/org/apache/syncope/wa/starter/gauth/token/SyncopeWAGoogleMfaAuthTokenRepositoryTest.class]; nested exception is java.lang.IllegalArgumentException: Unsupported class file major version 60
Caused by: java.lang.IllegalArgumentException: Unsupported class file major version 60
```
I already tried to use ASM 9.0.1-SNAPSHOT with no luck.https://gitlab.ow2.org/asm/asm/-/issues/317904ASM throws ArrayIndexOutOfBoundsException when processing kotlin class file u...2020-07-05T06:54:08ZRamanpreet Singh KhindaASM throws ArrayIndexOutOfBoundsException when processing kotlin class file using both Inline Function and Multiplatform ProjectFirebase Performance received a customer issue which is publicly tracked at https://github.com/firebase/firebase-android-sdk/issues/1556.
> **Note:** When developer integrates Firebase Performance to their app, before application code i...Firebase Performance received a customer issue which is publicly tracked at https://github.com/firebase/firebase-android-sdk/issues/1556.
> **Note:** When developer integrates Firebase Performance to their app, before application code is converted to DEX files, the Performance Monitoring plugin uses the [Transform API](http://tools.android.com/tech-docs/new-build-system/transform-api) and the [ASM bytecode instrumentation framework](https://asm.ow2.io/) to visit the app's compiled class files and to instrument the code (to measure performance). More details [here](https://firebase.google.com/docs/perf-mon/get-started-android).
The issue happens when developer integrates with [Ktor](https://ktor.io/) (which is an asynchronous Web framework for Kotlin) and [Firebase Performance](https://firebase.google.com/docs/perf-mon/get-started-android).
I was able to reproduce the problem with [this](https://github.com/ktorio/ktor-samples/tree/master/other/client-multipart) sample app from Ktor:
```
> Task :app:transformClassesWithFirebasePerformancePluginForDebug
java.lang.ClassNotFoundException: org.codehaus.groovy.control.CompilationFailedException
Can't instrument: io/ktor/client/request/forms/MultiPartFormDataContent.class
java.lang.ArrayIndexOutOfBoundsException: -1
at java.util.ArrayList.elementData(ArrayList.java:422)
at java.util.ArrayList.remove(ArrayList.java:499)
at org.objectweb.asm.commons.AdviceAdapter.popValue(AdviceAdapter.java:604)
at org.objectweb.asm.commons.AdviceAdapter.doVisitMethodInsn(AdviceAdapter.java:474)
at org.objectweb.asm.commons.AdviceAdapter.visitMethodInsn(AdviceAdapter.java:468)
at com.google.firebase.perf.plugin.instrumentation.InstrumentationVisitor$FirebasePerfMethodVisitor.visitMethodInsn(InstrumentationVisitor.java:358)
at org.objectweb.asm.ClassReader.readCode(ClassReader.java:2209)
at org.objectweb.asm.ClassReader.readMethod(ClassReader.java:1275)
at org.objectweb.asm.ClassReader.accept(ClassReader.java:679)
at com.google.firebase.perf.plugin.instrumentation.Instrument.instrument(Instrument.java:170)
at com.google.firebase.perf.plugin.instrumentation.Instrument.instrumentClassesInJar(Instrument.java:117)
at com.google.firebase.perf.plugin.FirebasePerfTransform.performTransformationFor(FirebasePerfTransform.java:563)
at com.google.firebase.perf.plugin.FirebasePerfTransform.transformJarInputs(FirebasePerfTransform.java:445)
at com.google.firebase.perf.plugin.FirebasePerfTransform.transform(FirebasePerfTransform.java:416)
at com.android.build.gradle.internal.pipeline.TransformTask$2.call(TransformTask.java:284)
at com.android.build.gradle.internal.pipeline.TransformTask$2.call(TransformTask.java:247)
at com.android.builder.profile.ThreadRecorder.record(ThreadRecorder.java:106)
at com.android.build.gradle.internal.pipeline.TransformTask.transform(TransformTask.java:242)
```
After debugging further I figured out the factors that cause the issue are:
- [Kotlin Multiplatform Project](https://kotlinlang.org/docs/reference/whatsnew12.html#multiplatform-projects-experimental) - Ktor uses this
- [Kotlin Inline Functions](https://kotlinlang.org/docs/reference/inline-functions.html#inline-functions) - Ktor uses this
A minimal set to reproduce this problem is:
1. Create a Sample android app (you can use [Fireperf Quickstart](https://github.com/firebase/quickstart-android/tree/master/perf) app)
2. Create a class like:
`MultiplatformProjectInlineFunTest.kt`
```
import android.app.Activity
import io.ktor.utils.io.core.BytePacketBuilder
class MultiplatformProjectInlineFunTest : Activity() {
val packet = buildPacket()
inline fun buildPacket(): BytePacketBuilder {
try {
return BytePacketBuilder(10)
} finally {
// this block is required
}
}
}
```
3. Update your `project-level` build.gradle file:
```
buildscript {
repositories {
google()
jcenter()
maven { url "https://dl.bintray.com/kotlin/ktor" }
}
dependencies {
classpath 'com.android.tools.build:gradle:3.6.3'
classpath 'com.google.gms:google-services:4.3.3'
classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.70'
classpath 'com.google.firebase:perf-plugin:1.3.1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
. . .
}
```
4. Update your `app-level` build.gradle file:
```
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'com.google.firebase.firebase-perf'
android { . . . }
dependencies {
. . .
implementation 'com.google.firebase:firebase-perf:19.0.7'
implementation "io.ktor:ktor-client-apache:1.3.2"
}
```
5. Run the gradle `assemble` task and you should see the below error when `transformClassesWithFirebasePerformancePluginForDebug` task is executed:
```
> Task :app:transformClassesWithFirebasePerformancePluginForDebug
Can't instrument /Users/rkhinda/Documents/hackweek-q2-2020/SampleAndroidApp/app/build/tmp/kotlin-classes/debug/com/example/pressthebutton/MultiplatformProjectInlineFunTest.class : null
java.lang.ArrayIndexOutOfBoundsException
. . .
```https://gitlab.ow2.org/asm/asm/-/issues/317894Constants.checkAsm8Experimental prevents using ASM8_EXPERIMENTAL API in class...2020-03-20T19:49:32ZBence SipkaConstants.checkAsm8Experimental prevents using ASM8_EXPERIMENTAL API in classes that were compiled for previous Java major release**Summary**
Can't read class files for Java 14 in classes that were compiled for a previous version.
**Reproducing**
1. Compile a Java class for JDK 14, possibly containing a record. (`Foo.java` -> `Foo.class`)
1. Create a class (`Rea...**Summary**
Can't read class files for Java 14 in classes that were compiled for a previous version.
**Reproducing**
1. Compile a Java class for JDK 14, possibly containing a record. (`Foo.java` -> `Foo.class`)
1. Create a class (`Reader.java`) that reads `Foo.class` using a custom `ClassVisitor` subclass, but compile it to Java 8.
1. Try running `Reader.class` that reads `Foo.class` using the `ASM8_EXPERIMENTAL` API.
1. An `IllegalStateException` is thrown due to the checks in `Constants.java`.
**Expected output**
The successful reading of `Foo.class`, possibly using record visitors.
**Actual output**
`IllegalStateException` as the `ClassVisitor` subclass wasn't compiled with `--enable-preview`.
**Solution**
Remove these checks, or make them bypassable. By having the `ASM8_EXPERIMENTAL` declared as deprecated, it is our responsibility to mitigate possible future API changes, not the library's to enforce its possibly breaking usage.
Another solution is to compile the reading classes for JDK 14, however, that would also require the user of the class to use the `--enable-preview` flag when running `java`, or else the following exception is thrown:
```
java.lang.UnsupportedClassVersionError: Preview features are not enabled for foo/Bar (class file version 58.65535). Try running with '--enable-preview'
```
By the way, the `callerClass.getClassLoader().getResourceAsStream(internalName + ".class")` way of retrieving the bytes of the caller class is prone to breakage, as some classloaders may **not** use conventional class loading mechanisms.
**Use-case**
We're trying to implement Java 14 compilation support for the saker.build system, however, this bug prevents us from properly analyzing the compiled class bytes. ([Related issue](https://github.com/sakerbuild/saker.java.compiler/issues/6))
The solution for passing `--enable-preview` for the `java` process that is running the build is not possible, as it may be embedded in other Java processes (e.g. Eclipse) that we can't have control over.
We also need to be able to run the Java classes that perform the class file reading on older JDK releases.https://gitlab.ow2.org/asm/asm/-/issues/317891Make ClassReader use streams instead of byte arrays2020-03-27T19:11:12ZCubxityMake ClassReader use streams instead of byte arraysWould it be possible to make ClassReader use InputStreams instead of reading them into a byte array? This would make the memory usage less while reading classes.
![image](/uploads/b56d9564f73759611847e821780da38a/image.png)Would it be possible to make ClassReader use InputStreams instead of reading them into a byte array? This would make the memory usage less while reading classes.
![image](/uploads/b56d9564f73759611847e821780da38a/image.png)https://gitlab.ow2.org/asm/asm/-/issues/317871ASM Mirror Descriptor - may be of interest to this project2019-04-06T11:49:35ZJordan ZimmermanASM Mirror Descriptor - may be of interest to this projectI've written a companion library to the OW2 ASM project, https://github.com/soabase/asm-mirror-descriptor. The ASM library has classes that can process Java class files through a Visitor style API allowing users to examine or modify any ...I've written a companion library to the OW2 ASM project, https://github.com/soabase/asm-mirror-descriptor. The ASM library has classes that can process Java class files through a Visitor style API allowing users to examine or modify any part of a class. The ASM Mirror project adds comparable classes to do the same with TypeMirror and Element instances used during Annotation Processing.
If there's interest I could provide a PR to merge it into the ASM project itself. If not, maybe the ASM docs could point interest parties to my library.
Thank you!https://gitlab.ow2.org/asm/asm/-/issues/317858InsnList nodes are removed after "accept"2018-10-27T15:43:12ZTodd WestInsnList nodes are removed after "accept"I noticed this issue recently when trying out ASM 7.0 (snapshot) and I believe I have been able to track it down to the following recent change:
https://gitlab.ow2.org/asm/asm/merge_requests/177
Here is a simple test I've set up that r...I noticed this issue recently when trying out ASM 7.0 (snapshot) and I believe I have been able to track it down to the following recent change:
https://gitlab.ow2.org/asm/asm/merge_requests/177
Here is a simple test I've set up that reproduces the issue that I'm seeing:
```
@Test
public void testAcceptWithLabelInfo() {
MethodNode method = new MethodNode();
method.instructions = new InsnList();
LabelNode labelNode = new LabelNode(new Label());
labelNode.getLabel().info = labelNode;
method.instructions.add(labelNode);
method.instructions.add(new InsnNode(11));
method.instructions.add(new InsnNode(22));
method.instructions.add(new InsnNode(33));
MethodNode otherMethod = new MethodNode();
final InsnList insnList = new InsnList();
method.accept(new MethodVisitor(Opcodes.ASM7, otherMethod) {
@Override
public void visitInsn(int opcode) {
insnList.add(new InsnNode(opcode));
super.visitInsn(opcode);
}
});
assertEquals(3, insnList.size()); // This will fail
assertEquals(11, insnList.get(0).opcode);
assertEquals(22, insnList.get(1).opcode);
assertEquals(33, insnList.get(2).opcode);
}
```
It appears that the change to null out the `nextInsn` field:
https://gitlab.ow2.org/asm/asm/commit/dc8acb48450bbb4aa461fb103916378cd226a6f6#5e3df072b61d74b2fd71d97a1d99188ccc46c1da_235_233
can cause the iteration of this loop to stop before it gets through all of the instruction nodes:
https://gitlab.ow2.org/asm/asm/blob/dc8acb48450bbb4aa461fb103916378cd226a6f6/asm-tree/src/main/java/org/objectweb/asm/tree/InsnList.java#L143-146
It's entirely possible that I may be doing something wrong here so please let me know if that's the case.
In my usage, I tried not using the `info` field on the `Label` and that allowed the instructions to be iterated through but caused a failure when attempting to compute frames later on:
```
java.lang.NullPointerException
at org.objectweb.asm.MethodWriter.computeAllFrames(MethodWriter.java:1581)
at org.objectweb.asm.MethodWriter.visitMaxs(MethodWriter.java:1555)
at org.objectweb.asm.tree.MethodNode.accept(MethodNode.java:806)
```
Any help would be greatly appreciated. Thank you!https://gitlab.ow2.org/asm/asm/-/issues/317854Inconsistent behaviour of ClassReader and ClassVisitor under Java 11 in versi...2018-09-03T08:12:41ZDimitry PolivaevInconsistent behaviour of ClassReader and ClassVisitor under Java 11 in version 6.2.1in asm 6.2.1 ClassVisitor method visitNestMemberExperimental checks that api version is not less than Opcodes.ASM7_EXPERIMENTAL = 17235968
/** @deprecated */
@Deprecated
public void visitNestMemberExperimental(String nestMemb...in asm 6.2.1 ClassVisitor method visitNestMemberExperimental checks that api version is not less than Opcodes.ASM7_EXPERIMENTAL = 17235968
/** @deprecated */
@Deprecated
public void visitNestMemberExperimental(String nestMember) {
if (this.api < 17235968) {
throw new UnsupportedOperationException();
} else {
if (this.cv != null) {
this.cv.visitNestMemberExperimental(nestMember);
}
}
}
but the calling method ClassReader.accept(groovyjarjarasm.asm.ClassVisitor, groovyjarjarasm.asm.Attribute[], int) does not make any checks on it.
if (nestMembersOffset != 0) {
fieldsCount = this.readUnsignedShort(nestMembersOffset);
for(methodsCount = nestMembersOffset + 2; fieldsCount-- > 0; methodsCount += 2) {
classVisitor.visitNestMemberExperimental(this.readClass(methodsCount, charBuffer));
}
}
It leads to issues like https://issues.apache.org/jira/browse/GROOVY-8727.
Example stacktrace:
~~~~
java.lang.UnsupportedOperationException
at groovyjarjarasm.asm.ClassVisitor.visitNestMemberExperimental(ClassVisitor.java:248)
at groovyjarjarasm.asm.ClassReader.accept(ClassReader.java:651)
at groovyjarjarasm.asm.ClassReader.accept(ClassReader.java:391)
at org.codehaus.groovy.ast.decompiled.AsmDecompiler.parseClass(AsmDecompiler.java:83)
at org.codehaus.groovy.control.ClassNodeResolver.findDecompiled(ClassNodeResolver.java:254)
at org.codehaus.groovy.control.ClassNodeResolver.tryAsLoaderClassOrScript(ClassNodeResolver.java:192)
at org.codehaus.groovy.control.ClassNodeResolver.findClassNode(ClassNodeResolver.java:172)
at org.codehaus.groovy.control.ClassNodeResolver.resolveName(ClassNodeResolver.java:128)
at org.codehaus.groovy.control.ResolveVisitor.resolveToOuter(ResolveVisitor.java:744)
at org.codehaus.groovy.control.ResolveVisitor.resolve(ResolveVisitor.java:394)
at org.codehaus.groovy.control.ResolveVisitor.resolveFromDefaultImports(ResolveVisitor.java:522)
at org.codehaus.groovy.control.ResolveVisitor.resolve(ResolveVisitor.java:392)
at org.codehaus.groovy.control.ResolveVisitor.resolve(ResolveVisitor.java:355)
at org.codehaus.groovy.control.ResolveVisitor.resolveOrFail(ResolveVisitor.java:339)
at org.codehaus.groovy.control.ResolveVisitor.resolveOrFail(ResolveVisitor.java:351)
at org.codehaus.groovy.control.ResolveVisitor.transformConstructorCallExpression(ResolveVisitor.java:1141)
at org.codehaus.groovy.control.ResolveVisitor.transform(ResolveVisitor.java:774)
at org.codehaus.groovy.control.ResolveVisitor.transformMethodCallExpression(ResolveVisitor.java:1156)
at org.codehaus.groovy.control.ResolveVisitor.transform(ResolveVisitor.java:770)
at org.codehaus.groovy.control.ResolveVisitor.transformMethodCallExpression(ResolveVisitor.java:1156)
at org.codehaus.groovy.control.ResolveVisitor.transform(ResolveVisitor.java:770)
at org.codehaus.groovy.control.ResolveVisitor.transformBinaryExpression(ResolveVisitor.java:1048)
at org.codehaus.groovy.control.ResolveVisitor.transform(ResolveVisitor.java:768)
at org.codehaus.groovy.control.ResolveVisitor.transformBinaryExpression(ResolveVisitor.java:1109)
at org.codehaus.groovy.control.ResolveVisitor.transform(ResolveVisitor.java:768)
at org.codehaus.groovy.ast.ClassCodeExpressionTransformer.visitExpressionStatement(ClassCodeExpressionTransformer.java:144)
at org.codehaus.groovy.ast.stmt.ExpressionStatement.visit(ExpressionStatement.java:42)
at org.codehaus.groovy.ast.CodeVisitorSupport.visitBlockStatement(CodeVisitorSupport.java:88)
at org.codehaus.groovy.ast.ClassCodeVisitorSupport.visitBlockStatement(ClassCodeVisitorSupport.java:106)
at org.codehaus.groovy.control.ResolveVisitor.visitBlockStatement(ResolveVisitor.java:1430)
at org.codehaus.groovy.ast.stmt.BlockStatement.visit(BlockStatement.java:71)
at org.codehaus.groovy.ast.ClassCodeVisitorSupport.visitClassCodeContainer(ClassCodeVisitorSupport.java:110)
at org.codehaus.groovy.ast.ClassCodeVisitorSupport.visitConstructorOrMethod(ClassCodeVisitorSupport.java:121)
at org.codehaus.groovy.ast.ClassCodeExpressionTransformer.visitConstructorOrMethod(ClassCodeExpressionTransformer.java:55)
at org.codehaus.groovy.control.ResolveVisitor.visitConstructorOrMethod(ResolveVisitor.java:249)
at org.codehaus.groovy.ast.ClassCodeVisitorSupport.visitMethod(ClassCodeVisitorSupport.java:132)
at org.codehaus.groovy.ast.ClassNode.visitContents(ClassNode.java:1103)
at org.codehaus.groovy.ast.ClassCodeVisitorSupport.visitClass(ClassCodeVisitorSupport.java:54)
at org.codehaus.groovy.control.ResolveVisitor.visitClass(ResolveVisitor.java:1375)
at org.codehaus.groovy.control.ResolveVisitor.startResolving(ResolveVisitor.java:222)
at org.codehaus.groovy.control.CompilationUnit$13.call(CompilationUnit.java:691)
at org.codehaus.groovy.control.CompilationUnit.applyToSourceUnits(CompilationUnit.java:968)
at org.codehaus.groovy.control.CompilationUnit.doPhaseOperation(CompilationUnit.java:633)
at org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:582)
at groovy.lang.GroovyClassLoader.doParseClass(GroovyClassLoader.java:354)
at groovy.lang.GroovyClassLoader.access$300(GroovyClassLoader.java:87)
at groovy.lang.GroovyClassLoader$5.provide(GroovyClassLoader.java:323)
at groovy.lang.GroovyClassLoader$5.provide(GroovyClassLoader.java:320)
at org.codehaus.groovy.runtime.memoize.ConcurrentCommonCache.getAndPut(ConcurrentCommonCache.java:147)
at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:318)
~~~~https://gitlab.ow2.org/asm/asm/-/issues/317816ClassReader constructor goes into infinite loop on zero length input streams2018-03-28T09:53:39ZJussi JudinClassReader constructor goes into infinite loop on zero length input streamsFollowing code leads into an infinite loop with ClassReader constructor when args[0] is an empty file:
```java
public class Asm61InfiniteLoop
{
public static void main(String[] args) throws java.io.IOException
{
java.io....Following code leads into an infinite loop with ClassReader constructor when args[0] is an empty file:
```java
public class Asm61InfiniteLoop
{
public static void main(String[] args) throws java.io.IOException
{
java.io.FileInputStream input = new java.io.FileInputStream(args[0]);
new org.objectweb.asm.ClassReader(input);
}
}
```
It looks like the following snippet in the constructor is the culprit where data leads into a zero length array with zero length files and the bytes read from the actual stream never get to -1:
```java
byte[] data = new byte[inputStream.available()];
int bytesRead;
while ((bytesRead = inputStream.read(data, 0, data.length)) != -1) {
outputStream.write(data, 0, bytesRead);
}
```
I would expect this to throw an exception about invalid class data or similar. Other constructors relying on byte[] data being at least 6 elements long lead into out of bounds exception. That is a little bit better, but still weird from user's perspective.https://gitlab.ow2.org/asm/asm/-/issues/317805Regression in 6.1-beta: GeneratorAdapter fails to generate methods that retur...2018-03-17T15:29:06ZEvgeny MandrikovRegression in 6.1-beta: GeneratorAdapter fails to generate methods that return void and arraysWith ASM 6.0 following code
```
import org.objectweb.asm.ClassReader;
import org.objectweb.asm.ClassWriter;
import org.objectweb.asm.Opcodes;
import org.objectweb.asm.Type;
import org.objectweb.asm.commons.GeneratorAdapter;
import org.o...With ASM 6.0 following code
```
import org.objectweb.asm.ClassReader;
import org.objectweb.asm.ClassWriter;
import org.objectweb.asm.Opcodes;
import org.objectweb.asm.Type;
import org.objectweb.asm.commons.GeneratorAdapter;
import org.objectweb.asm.commons.Method;
import org.objectweb.asm.util.Textifier;
import org.objectweb.asm.util.TraceClassVisitor;
import java.io.PrintWriter;
public class Example {
public static void main(String[] args) {
ClassWriter cw = new ClassWriter(Opcodes.ASM6);
cw.visit(Opcodes.V1_5, Opcodes.ACC_PUBLIC, "Example", null, "java/lang/Object", null);
{
Method m = Method.getMethod("void <init> ()");
GeneratorAdapter mg = new GeneratorAdapter(Opcodes.ACC_PUBLIC, m, null, null, cw);
mg.loadThis();
mg.invokeConstructor(Type.getType(Object.class), m);
mg.returnValue();
mg.endMethod();
}
{
Method m = Method.getMethod("[I fun ()");
GeneratorAdapter mg = new GeneratorAdapter(Opcodes.ACC_PUBLIC, m, null, null, cw);
mg.push(0);
mg.newArray(Type.INT_TYPE);
mg.returnValue();
mg.endMethod();
}
cw.visitEnd();
TraceClassVisitor traceClassVisitor = new TraceClassVisitor(null, new Textifier(), new PrintWriter(System.out));
new ClassReader(cw.toByteArray()).accept(traceClassVisitor, 0);
}
}
```
produces
```
// class version 49.0 (49)
// access flags 0x1
public class Example {
// access flags 0x1
public <init>()V
ALOAD 0
INVOKESPECIAL java/lang/Object.<init> ()V
RETURN
MAXSTACK = 0
MAXLOCALS = 0
// access flags 0x1
public fun()Ljava/lang/[I;
ICONST_0
NEWARRAY T_INT
ARETURN
MAXSTACK = 0
MAXLOCALS = 0
}
```
While with ASM 6.1-beta generation of first method fails with
```
java.lang.AssertionError
at org.objectweb.asm.Type.getOpcode(Type.java:829)
at org.objectweb.asm.commons.GeneratorAdapter.returnValue(GeneratorAdapter.java:1097)
```
and second fails with
```
java.lang.UnsupportedOperationException
at org.objectweb.asm.Type.getOpcode(Type.java:827)
at org.objectweb.asm.commons.GeneratorAdapter.returnValue(GeneratorAdapter.java:1097)
```
Seems that this regression is consequence of changes in `org.objectweb.asm.Type.getOpcode` in 4f0da9dbce172213cda99b59b06faddab4ee6ca0 and 6db046e2003c6015c2a4c027db6d0b699b1d5117, reduced test for its change of behavior:
```
assertEquals(Opcodes.RETURN, Type.VOID_TYPE.getOpcode(Opcodes.IRETURN));
assertEquals(Opcodes.ARETURN, Type.getType(int[].class).getOpcode(Opcodes.IRETURN));
```https://gitlab.ow2.org/asm/asm/-/issues/317800Resizing jump instruction adds invalid stack frame to a class without frames2017-12-26T09:26:31ZlauritResizing jump instruction adds invalid stack frame to a class without framesProbably caused by https://gitlab.ow2.org/asm/asm/commit/8648c008d91355420653a072a5146746c293b507
With class version 49 fails with array index out of bounds when reading class, with 50 there is an extra frame that isn't supposed to be th...Probably caused by https://gitlab.ow2.org/asm/asm/commit/8648c008d91355420653a072a5146746c293b507
With class version 49 fails with array index out of bounds when reading class, with 50 there is an extra frame that isn't supposed to be there. Also that extra frame can't be decoded by javap
```java
import org.objectweb.asm.ClassReader;
import org.objectweb.asm.ClassVisitor;
import org.objectweb.asm.ClassWriter;
import org.objectweb.asm.FieldVisitor;
import org.objectweb.asm.Label;
import org.objectweb.asm.MethodVisitor;
import org.objectweb.asm.Opcodes;
public class Main implements Opcodes {
public static void main(String... args) {
ClassWriter cw = new ClassWriter(0);
FieldVisitor fv;
MethodVisitor mv;
cw.visit(49, ACC_PUBLIC + ACC_SUPER, "Test", null, "java/lang/Object", null);
// cw.visit(50, ACC_PUBLIC + ACC_SUPER, "Test", null, "java/lang/Object", null);
{
fv = cw.visitField(0, "b", "Z", null, null);
fv.visitEnd();
}
{
mv = cw.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null);
mv.visitCode();
mv.visitVarInsn(ALOAD, 0);
mv.visitMethodInsn(INVOKESPECIAL, "java/lang/Object", "<init>", "()V", false);
mv.visitInsn(RETURN);
mv.visitMaxs(1, 1);
mv.visitEnd();
}
{
mv = cw.visitMethod(0, "a", "()V", null, null);
mv.visitCode();
Label l0 = new Label();
mv.visitLabel(l0);
mv.visitVarInsn(ALOAD, 0);
mv.visitFieldInsn(GETFIELD, "Test", "b", "Z");
Label l1 = new Label();
mv.visitJumpInsn(IFEQ, l1);
for (int i = 0; i < 40000; i++) {
mv.visitInsn(NOP);
}
mv.visitLabel(l1);
mv.visitInsn(RETURN);
Label l3 = new Label();
mv.visitLabel(l3);
mv.visitLocalVariable("this", "LTest;", null, l0, l3, 0);
mv.visitMaxs(2, 1);
mv.visitEnd();
}
cw.visitEnd();
byte[] bytes = cw.toByteArray();
ClassReader cr = new ClassReader(bytes);
ClassVisitor cv = new ClassVisitor(ASM5) {
@Override
public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) {
return new MethodVisitor(ASM5) {
@Override
public void visitFrame(int type, int nLocal, Object[] local, int nStack, Object[] stack) {
throw new IllegalStateException("no frames expected");
}
};
}
};
cr.accept(cv, 0);
}
}
```