asm issueshttps://gitlab.ow2.org/asm/asm/-/issues2020-12-19T07:57:58Zhttps://gitlab.ow2.org/asm/asm/-/issues/317922InstructionAdapter shall throw consistent exceptions2020-12-19T07:57:58ZHao ZhongInstructionAdapter shall throw consistent exceptionsWhen api is below ASM5, InstructionAdapter.visitLdcInsn throws UnsupportedOperationException:
` public void visitLdcInsn(final Object value) {
if (api < Opcodes.ASM5
&& (value instanceof Handle
|| (value instance...When api is below ASM5, InstructionAdapter.visitLdcInsn throws UnsupportedOperationException:
` public void visitLdcInsn(final Object value) {
if (api < Opcodes.ASM5
&& (value instanceof Handle
|| (value instanceof Type && ((Type) value).getSort() == Type.METHOD))) {
throw new UnsupportedOperationException("This feature requires ASM5");
}...`
However, some other methods of this class throw different exceptions. For example, invokevirtual is as follows:
`public void invokevirtual(
final String owner, final String name, final String descriptor, final boolean isInterface) {
if (api < Opcodes.ASM5) {
if (isInterface) {
throw new IllegalArgumentException("INVOKEVIRTUAL on interfaces require ASM 5");
}
invokevirtual(owner, name, descriptor);
return;
}
mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, owner, name, descriptor, isInterface);
}`
As a result, my code fails to catch the exception, and I have to analyze the message to determine the problem. Can ASM throw the identical exception for the same problem?https://gitlab.ow2.org/asm/asm/-/issues/317921Make Analyzer not require correct maxs or calculate maxs fast2020-12-21T07:06:28ZAura LeeMake Analyzer not require correct maxs or calculate maxs fastI am writing bytecode using the tree api and want to analyze the code afterwards. I can't calculate maxs during that process. Basically I have to do it like this to avoid "Insufficient maximum ... size":
```java
public static Frame<Bas...I am writing bytecode using the tree api and want to analyze the code afterwards. I can't calculate maxs during that process. Basically I have to do it like this to avoid "Insufficient maximum ... size":
```java
public static Frame<BasicValue>[] getFrames(ClassNode c, MethodNode m) {
m.maxStack = 999; // we don't want insufficient stack size
Analyzer<BasicValue> a = new Analyzer<>(new BasicInterpreter());
try {
a.analyze(c.name, m);
} catch (Throwable e) {
logger.error("Failed analysis in {}, {}", c.name, m.name);
return null;
}
return a.getFrames();
}
```
Always using a high max stack value causes the analyzer to be slow on many classes. I don't want to do a hacky try catch block recursion with ` if (String.valueOf(e.getMessage()).contains("Insufficient maximum")) { ... } `. Is there a fast way to calculate the maxs beforehand using the tree api, so i can use the correct values before analyzing, or would it be faster to update the analyzer to be independent from the defined max values? Is there something like a MaxsEvaluator?https://gitlab.ow2.org/asm/asm/-/issues/317920Gradle Meta-Data on Maven Central specifies Java 8 as supported version2020-11-11T10:45:57ZPeter GafertGradle Meta-Data on Maven Central specifies Java 8 as supported versionI saw that for the newest ASM version (9.0) you have published some Gradle meta-data to Maven Central: https://repo1.maven.org/maven2/org/ow2/asm/asm/9.0/asm-9.0.module
As far as I understand ASM is still compatible to older Java versio...I saw that for the newest ASM version (9.0) you have published some Gradle meta-data to Maven Central: https://repo1.maven.org/maven2/org/ow2/asm/asm/9.0/asm-9.0.module
As far as I understand ASM is still compatible to older Java versions, so I wonder why these meta-data files specify `{"org.gradle.jvm.version": 8}`?
My current problem is, that for https://github.com/TNG/ArchUnit I still try to support Java 7, but specifying this dependency in my Gradle build now pulls in this `asm-9.0.module` meta-data and consequently complains
```
Could not resolve org.ow2.asm:asm:9.0
> No matching variant of org.ow2.asm:asm:9.0 was found. The consumer was configured to find a runtime of a library compatible with Java 7, packaged as a jar, and its dependencies declared externally but:
> ... Incompatible because this component declares an API of a component compatible with Java 8 and the consumer needed a runtime of a component compatible with Java 7
```
Was this a conscious decision? (I'm asking, because I had published this meta-data by accident in the past and it caused some problems back then)https://gitlab.ow2.org/asm/asm/-/issues/317918TypeNotPresentException with COMPUTE_FRAMES when generating class2020-10-17T09:54:48ZFlorian NückeTypeNotPresentException with COMPUTE_FRAMES when generating classWhen using `COMPUTE_FRAMES` I stumbled upon a case where frame computation will cause a `TypeNotPresentException` due to it trying to load the class that is currently being generated. This is on version 9.0 but happens in earlier version...When using `COMPUTE_FRAMES` I stumbled upon a case where frame computation will cause a `TypeNotPresentException` due to it trying to load the class that is currently being generated. This is on version 9.0 but happens in earlier versions, too (originally found in 7.2).
Here's the stacktrace:
```
Exception in thread "main" java.lang.TypeNotPresentException: Type Test$Modified not present
at org.objectweb.asm.ClassWriter.getCommonSuperClass(ClassWriter.java:1025)
at org.objectweb.asm.SymbolTable.addMergedType(SymbolTable.java:1202)
at org.objectweb.asm.Frame.merge(Frame.java:1299)
at org.objectweb.asm.Frame.merge(Frame.java:1244)
at org.objectweb.asm.MethodWriter.computeAllFrames(MethodWriter.java:1610)
at org.objectweb.asm.MethodWriter.visitMaxs(MethodWriter.java:1546)
at org.objectweb.asm.MethodVisitor.visitMaxs(MethodVisitor.java:773)
at org.objectweb.asm.ClassReader.readCode(ClassReader.java:2629)
at org.objectweb.asm.ClassReader.readMethod(ClassReader.java:1481)
at org.objectweb.asm.ClassReader.accept(ClassReader.java:711)
at org.objectweb.asm.ClassReader.accept(ClassReader.java:394)
```
Here is a repro case:
```java
interface TestInterface { }
class Test implements TestInterface {
TestInterface a;
Test(TestInterface x) {
a = x != null ? x : this; // the cause
}
}
public static void main(String[] args) throws Throwable {
ClassReader reader = new ClassReader(Test.class.getName());
ClassWriter writer = new ClassWriter(ClassWriter.COMPUTE_FRAMES);
reader.accept(new ClassRemapper(writer, new Remapper() {
public String map(final String internalName) {
return internalName.equals(Type.getInternalName(Test.class))
? internalName + "$Modified"
: super.map(internalName);
}
}), 0);
}
```
The part that causes the exception is the assignment in the constructor. For the frame computation, an attempt is made to find the superclass of `TestInterface` and `Test$Modified`, the latter being the class being generated, so `Class.forName` fails.
For now my workaround is to do `a = x != null ? x : (TestInterface)(Object)this;` instead.
For the record, my actual use-case is that I have a "template" class of which I create a copy with some generated code injected into an existing method. Imagine `TestInterface` having a method, `Test` implementing it and in that method implementation I'd inject some generated code.
Anyway. I'm not sure this is expected behavior, so I thought I'd report it. Don't know if this can be robustly handled, really. If the workaround isn't workaround and how that's supposed to be done, great. If there are other approaches that ideally work on older versions, too, please let me know. Thanks!https://gitlab.ow2.org/asm/asm/-/issues/317917org.objectweb.asm.Type#getReturnType(final String methodDescriptor)2020-12-21T15:19:48ZHan Chunlinorg.objectweb.asm.Type#getReturnType(final String methodDescriptor)Hello!
When i try to parse a method descriptor which contains 'L' in method name(such as "isLast()Ljava/lang/Boolean;"), it will be fail.Hello!
When i try to parse a method descriptor which contains 'L' in method name(such as "isLast()Ljava/lang/Boolean;"), it will be fail.https://gitlab.ow2.org/asm/asm/-/issues/317916Visit code attributes without visiting code itself2020-12-20T07:54:15ZRemi ForaxVisit code attributes without visiting code itselfFrom Tagir Valeev (IntelliJ)
Hello!
Is it possible to have a MethodVisitor that visits code attributes (in
particular, visitLocalVariable) but without spending time on visiting
the code itself? When we build the index of class files in...From Tagir Valeev (IntelliJ)
Hello!
Is it possible to have a MethodVisitor that visits code attributes (in
particular, visitLocalVariable) but without spending time on visiting
the code itself? When we build the index of class files in the
project, we need to get all the methods with parameter names and
annotations but we are not interested in method code. If the class was
compiled with debug info but without -parameters, then we take
parameter names from debug info. Unfortunately, visitLocalVariable is
not called in SKIP_CODE mode, so we have to omit this option and ASM
spends quite a significant amount of time decoding the instructions
despite we don't need them. Probably it's possible to introduce
another mode that skips the code itself but visits the code
attributes?Eric BrunetonEric Brunetonhttps://gitlab.ow2.org/asm/asm/-/issues/317914java.lang.VerifyError: Stack map does not match the one at exception handler ...2020-09-27T11:08:59ZIonuț Ursuleanujava.lang.VerifyError: Stack map does not match the one at exception handler with java 14Hi,
I'm using [glowroot](https://glowroot.org/) with java 8 & 11 and it's working fine. I guess with 12 & 13 too. But, with java 14 it throws
> java.lang.VerifyError: Stack map does not match the one at exception handler
I tried to u...Hi,
I'm using [glowroot](https://glowroot.org/) with java 8 & 11 and it's working fine. I guess with 12 & 13 too. But, with java 14 it throws
> java.lang.VerifyError: Stack map does not match the one at exception handler
I tried to update the asm dependency to the latest version 8.0.1 and the same error appears. Same with the beta version
[demo-binaries.zip](/uploads/6de337cf28eadcb8ddf6da90e0000cd9/demo-binaries.zip)
[demo-sources.zip](/uploads/d95af02cd3f68fdb8414a75e2204f55a/demo-sources.zip)
Here's the output by running the attached spring-boot sample app configured to be monitored by glowroot. Unzip demo-binaries & run:
> java -javaagent:./glowroot/glowroot.jar -jar ./demo-0.0.1-SNAPSHOT.jar
```
ionutursuleanu@192-168-0-101 sample % java -javaagent:./glowroot/glowroot.jar -jar ./demo-0.0.1-SNAPSHOT.jar
OpenJDK 64-Bit Server VM warning: Sharing is only supported for boot loader classes because bootstrap classpath has been appended
OpenJDK 64-Bit Server VM warning: Sharing is only supported for boot loader classes because bootstrap classpath has been appended
2020-07-18 20:56:10.000 INFO org.glowroot - Glowroot version: 0.13.6, built 2020-07-18 11:25:53 +0000
2020-07-18 20:56:10.003 INFO org.glowroot - Java version: 14.0.2 (AdoptOpenJDK / Mac OS X)
2020-07-18 20:56:10.004 INFO org.glowroot - Java args: -javaagent:./glowroot/glowroot.jar
OpenJDK 64-Bit Server VM warning: Sharing is only supported for boot loader classes because bootstrap classpath has been appended
2020-07-18 20:56:12.411 INFO org.glowroot - creating glowroot schema...
2020-07-18 20:56:12.733 INFO org.glowroot - glowroot schema created
2020-07-18 20:56:13.069 INFO org.glowroot - UI listening on 127.0.0.1:4000 (to access the UI from remote machines, change the bind address to 0.0.0.0, either in the Glowroot UI under Configuration > Web or directly in the admin.json file, and then restart JVM to take effect)
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.3.1.RELEASE)
2020-07-18 20:56:14.293 INFO 24836 --- [ main] com.example.demo.DemoApplication : Starting DemoApplication on 192-168-0-101.rdsnet.ro with PID 24836 (/Users/ionutursuleanu/Downloads/sample/demo-0.0.1-SNAPSHOT.jar started by ionutursuleanu in /Users/ionutursuleanu/Downloads/sample)
2020-07-18 20:56:14.299 INFO 24836 --- [ main] com.example.demo.DemoApplication : No active profile set, falling back to default profiles: default
2020-07-18 20:56:15.321 INFO 24836 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JPA repositories in DEFERRED mode.
2020-07-18 20:56:15.472 INFO 24836 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 128ms. Found 1 JPA repository interfaces.
2020-07-18 20:56:16.403 INFO 24836 --- [ main] o.s.s.concurrent.ThreadPoolTaskExecutor : Initializing ExecutorService 'applicationTaskExecutor'
2020-07-18 20:56:16.421 INFO 24836 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Starting...
2020-07-18 20:56:16.874 INFO 24836 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Start completed.
2020-07-18 20:56:16.925 WARN 24836 --- [ main] s.c.a.AnnotationConfigApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean]: Factory method 'entityManagerFactory' threw exception; nested exception is java.lang.VerifyError: Stack map does not match the one at exception handler 156
Exception Details:
Location:
com/sun/proxy/$Proxy69.prepareStatement(Ljava/lang/String;[I)Ljava/sql/PreparedStatement; @156: iload_3
Reason:
Type 'java/lang/Throwable' (current frame, locals[1]) is not assignable to 'java/lang/String' (stack map, locals[1])
Current Frame:
bci: @112
flags: { }
locals: { 'com/sun/proxy/$Proxy69', 'java/lang/Throwable', '[I', integer, 'org/glowroot/agent/bytecode/api/ThreadContextThreadLocal$Holder', 'org/glowroot/agent/bytecode/api/ThreadContextPlus', integer, 'org/glowroot/agent/plugin/api/Timer', 'java/lang/String' }
stack: { 'java/lang/Throwable' }
Stackmap Frame:
bci: @156
flags: { }
locals: { 'com/sun/proxy/$Proxy69', 'java/lang/String', '[I', integer, 'org/glowroot/agent/bytecode/api/ThreadContextThreadLocal$Holder', 'org/glowroot/agent/bytecode/api/ThreadContextPlus', integer, 'org/glowroot/agent/plugin/api/Timer', 'java/lang/String' }
stack: { 'java/lang/Throwable' }
Bytecode:
0000000: 033e 013a 0401 3a05 0236 0601 3a07 2b3a
0000010: 0819 04c7 0008 b800 9a3a 0419 04b6 00a2
0000020: 593a 05c6 001f 1905 b900 a501 0059 3606
0000030: 12a6 9f00 1019 0512 a6b9 00aa 0200 04a7
0000040: 0004 033e 1d99 000a 1905 b801 053a 072a
0000050: b400 592a b201 0705 bd00 7159 032b 5359
0000060: 042c 53b9 0061 0400 c001 09a7 000e bf4c
0000070: bb00 6859 2bb7 006b bf1d 9900 0959 1908
0000080: b801 0c1d 9900 0819 07b8 0110 1506 029f
0000090: 000c 1905 1506 b900 aa02 00b0 1d99 0008
00000a0: 1907 b801 1015 0602 9f00 0c19 0515 06b9
00000b0: 00aa 0200 bf
Exception Handler Table:
bci [79, 110] => handler: 110
bci [79, 110] => handler: 110
bci [79, 110] => handler: 110
bci [79, 110] => handler: 111
bci [79, 121] => handler: 156
Stackmap Table:
full_frame(@27,{Object[#2],Object[#125],Object[#254],Integer,Object[#156],Object[#158],Integer,Object[#256],Object[#125]},{})
same_frame(@66)
same_locals_1_stack_item_frame(@67,Integer)
same_frame(@79)
same_locals_1_stack_item_frame(@110,Object[#85])
same_locals_1_stack_item_frame(@111,Object[#85])
same_locals_1_stack_item_frame(@121,Object[#265])
same_locals_1_stack_item_frame(@131,Object[#265])
same_locals_1_stack_item_frame(@140,Object[#265])
same_locals_1_stack_item_frame(@155,Object[#265])
same_locals_1_stack_item_frame(@156,Object[#85])
same_locals_1_stack_item_frame(@165,Object[#85])
same_locals_1_stack_item_frame(@180,Object[#85])
2020-07-18 20:56:16.927 INFO 24836 --- [ main] o.s.s.concurrent.ThreadPoolTaskExecutor : Shutting down ExecutorService 'applicationTaskExecutor'
2020-07-18 20:56:16.928 INFO 24836 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Shutdown initiated...
2020-07-18 20:56:16.930 INFO 24836 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Shutdown completed.
2020-07-18 20:56:16.951 INFO 24836 --- [ main] ConditionEvaluationReportLoggingListener :
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2020-07-18 20:56:16.965 ERROR 24836 --- [ main] o.s.boot.SpringApplication : Application run failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean]: Factory method 'entityManagerFactory' threw exception; nested exception is java.lang.VerifyError: Stack map does not match the one at exception handler 156
Exception Details:
Location:
com/sun/proxy/$Proxy69.prepareStatement(Ljava/lang/String;[I)Ljava/sql/PreparedStatement; @156: iload_3
Reason:
Type 'java/lang/Throwable' (current frame, locals[1]) is not assignable to 'java/lang/String' (stack map, locals[1])
Current Frame:
bci: @112
flags: { }
locals: { 'com/sun/proxy/$Proxy69', 'java/lang/Throwable', '[I', integer, 'org/glowroot/agent/bytecode/api/ThreadContextThreadLocal$Holder', 'org/glowroot/agent/bytecode/api/ThreadContextPlus', integer, 'org/glowroot/agent/plugin/api/Timer', 'java/lang/String' }
stack: { 'java/lang/Throwable' }
Stackmap Frame:
bci: @156
flags: { }
locals: { 'com/sun/proxy/$Proxy69', 'java/lang/String', '[I', integer, 'org/glowroot/agent/bytecode/api/ThreadContextThreadLocal$Holder', 'org/glowroot/agent/bytecode/api/ThreadContextPlus', integer, 'org/glowroot/agent/plugin/api/Timer', 'java/lang/String' }
stack: { 'java/lang/Throwable' }
Bytecode:
0000000: 033e 013a 0401 3a05 0236 0601 3a07 2b3a
0000010: 0819 04c7 0008 b800 9a3a 0419 04b6 00a2
0000020: 593a 05c6 001f 1905 b900 a501 0059 3606
0000030: 12a6 9f00 1019 0512 a6b9 00aa 0200 04a7
0000040: 0004 033e 1d99 000a 1905 b801 053a 072a
0000050: b400 592a b201 0705 bd00 7159 032b 5359
0000060: 042c 53b9 0061 0400 c001 09a7 000e bf4c
0000070: bb00 6859 2bb7 006b bf1d 9900 0959 1908
0000080: b801 0c1d 9900 0819 07b8 0110 1506 029f
0000090: 000c 1905 1506 b900 aa02 00b0 1d99 0008
00000a0: 1907 b801 1015 0602 9f00 0c19 0515 06b9
00000b0: 00aa 0200 bf
Exception Handler Table:
bci [79, 110] => handler: 110
bci [79, 110] => handler: 110
bci [79, 110] => handler: 110
bci [79, 110] => handler: 111
bci [79, 121] => handler: 156
Stackmap Table:
full_frame(@27,{Object[#2],Object[#125],Object[#254],Integer,Object[#156],Object[#158],Integer,Object[#256],Object[#125]},{})
same_frame(@66)
same_locals_1_stack_item_frame(@67,Integer)
same_frame(@79)
same_locals_1_stack_item_frame(@110,Object[#85])
same_locals_1_stack_item_frame(@111,Object[#85])
same_locals_1_stack_item_frame(@121,Object[#265])
same_locals_1_stack_item_frame(@131,Object[#265])
same_locals_1_stack_item_frame(@140,Object[#265])
same_locals_1_stack_item_frame(@155,Object[#265])
same_locals_1_stack_item_frame(@156,Object[#85])
same_locals_1_stack_item_frame(@165,Object[#85])
same_locals_1_stack_item_frame(@180,Object[#85])
at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:655) ~[spring-beans-5.2.7.RELEASE.jar!/:5.2.7.RELEASE]
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:635) ~[spring-beans-5.2.7.RELEASE.jar!/:5.2.7.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1338) ~[spring-beans-5.2.7.RELEASE.jar!/:5.2.7.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1177) ~[spring-beans-5.2.7.RELEASE.jar!/:5.2.7.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:557) ~[spring-beans-5.2.7.RELEASE.jar!/:5.2.7.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:517) ~[spring-beans-5.2.7.RELEASE.jar!/:5.2.7.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:323) ~[spring-beans-5.2.7.RELEASE.jar!/:5.2.7.RELEASE]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:226) ~[spring-beans-5.2.7.RELEASE.jar!/:5.2.7.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:321) ~[spring-beans-5.2.7.RELEASE.jar!/:5.2.7.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202) ~[spring-beans-5.2.7.RELEASE.jar!/:5.2.7.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1109) ~[spring-context-5.2.7.RELEASE.jar!/:5.2.7.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:869) ~[spring-context-5.2.7.RELEASE.jar!/:5.2.7.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:551) ~[spring-context-5.2.7.RELEASE.jar!/:5.2.7.RELEASE]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:758) ~[spring-boot-2.3.1.RELEASE.jar!/:2.3.1.RELEASE]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:750) ~[spring-boot-2.3.1.RELEASE.jar!/:2.3.1.RELEASE]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397) ~[spring-boot-2.3.1.RELEASE.jar!/:2.3.1.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:315) ~[spring-boot-2.3.1.RELEASE.jar!/:2.3.1.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1237) ~[spring-boot-2.3.1.RELEASE.jar!/:2.3.1.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1226) ~[spring-boot-2.3.1.RELEASE.jar!/:2.3.1.RELEASE]
at com.example.demo.DemoApplication.main(DemoApplication.java:16) ~[classes!/:na]
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na]
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:na]
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na]
at java.base/java.lang.reflect.Method.invoke(Method.java:564) ~[na:na]
at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:49) ~[demo-0.0.1-SNAPSHOT.jar:na]
at org.springframework.boot.loader.Launcher.launch(Launcher.java:109) ~[demo-0.0.1-SNAPSHOT.jar:na]
at org.springframework.boot.loader.Launcher.launch(Launcher.java:58) ~[demo-0.0.1-SNAPSHOT.jar:na]
at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:88) ~[demo-0.0.1-SNAPSHOT.jar:na]
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean]: Factory method 'entityManagerFactory' threw exception; nested exception is java.lang.VerifyError: Stack map does not match the one at exception handler 156
Exception Details:
Location:
com/sun/proxy/$Proxy69.prepareStatement(Ljava/lang/String;[I)Ljava/sql/PreparedStatement; @156: iload_3
Reason:
Type 'java/lang/Throwable' (current frame, locals[1]) is not assignable to 'java/lang/String' (stack map, locals[1])
Current Frame:
bci: @112
flags: { }
locals: { 'com/sun/proxy/$Proxy69', 'java/lang/Throwable', '[I', integer, 'org/glowroot/agent/bytecode/api/ThreadContextThreadLocal$Holder', 'org/glowroot/agent/bytecode/api/ThreadContextPlus', integer, 'org/glowroot/agent/plugin/api/Timer', 'java/lang/String' }
stack: { 'java/lang/Throwable' }
Stackmap Frame:
bci: @156
flags: { }
locals: { 'com/sun/proxy/$Proxy69', 'java/lang/String', '[I', integer, 'org/glowroot/agent/bytecode/api/ThreadContextThreadLocal$Holder', 'org/glowroot/agent/bytecode/api/ThreadContextPlus', integer, 'org/glowroot/agent/plugin/api/Timer', 'java/lang/String' }
stack: { 'java/lang/Throwable' }
Bytecode:
0000000: 033e 013a 0401 3a05 0236 0601 3a07 2b3a
0000010: 0819 04c7 0008 b800 9a3a 0419 04b6 00a2
0000020: 593a 05c6 001f 1905 b900 a501 0059 3606
0000030: 12a6 9f00 1019 0512 a6b9 00aa 0200 04a7
0000040: 0004 033e 1d99 000a 1905 b801 053a 072a
0000050: b400 592a b201 0705 bd00 7159 032b 5359
0000060: 042c 53b9 0061 0400 c001 09a7 000e bf4c
0000070: bb00 6859 2bb7 006b bf1d 9900 0959 1908
0000080: b801 0c1d 9900 0819 07b8 0110 1506 029f
0000090: 000c 1905 1506 b900 aa02 00b0 1d99 0008
00000a0: 1907 b801 1015 0602 9f00 0c19 0515 06b9
00000b0: 00aa 0200 bf
Exception Handler Table:
bci [79, 110] => handler: 110
bci [79, 110] => handler: 110
bci [79, 110] => handler: 110
bci [79, 110] => handler: 111
bci [79, 121] => handler: 156
Stackmap Table:
full_frame(@27,{Object[#2],Object[#125],Object[#254],Integer,Object[#156],Object[#158],Integer,Object[#256],Object[#125]},{})
same_frame(@66)
same_locals_1_stack_item_frame(@67,Integer)
same_frame(@79)
same_locals_1_stack_item_frame(@110,Object[#85])
same_locals_1_stack_item_frame(@111,Object[#85])
same_locals_1_stack_item_frame(@121,Object[#265])
same_locals_1_stack_item_frame(@131,Object[#265])
same_locals_1_stack_item_frame(@140,Object[#265])
same_locals_1_stack_item_frame(@155,Object[#265])
same_locals_1_stack_item_frame(@156,Object[#85])
same_locals_1_stack_item_frame(@165,Object[#85])
same_locals_1_stack_item_frame(@180,Object[#85])
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:185) ~[spring-beans-5.2.7.RELEASE.jar!/:5.2.7.RELEASE]
at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:650) ~[spring-beans-5.2.7.RELEASE.jar!/:5.2.7.RELEASE]
... 27 common frames omitted
Caused by: java.lang.VerifyError: Stack map does not match the one at exception handler 156
Exception Details:
Location:
com/sun/proxy/$Proxy69.prepareStatement(Ljava/lang/String;[I)Ljava/sql/PreparedStatement; @156: iload_3
Reason:
Type 'java/lang/Throwable' (current frame, locals[1]) is not assignable to 'java/lang/String' (stack map, locals[1])
Current Frame:
bci: @112
flags: { }
locals: { 'com/sun/proxy/$Proxy69', 'java/lang/Throwable', '[I', integer, 'org/glowroot/agent/bytecode/api/ThreadContextThreadLocal$Holder', 'org/glowroot/agent/bytecode/api/ThreadContextPlus', integer, 'org/glowroot/agent/plugin/api/Timer', 'java/lang/String' }
stack: { 'java/lang/Throwable' }
Stackmap Frame:
bci: @156
flags: { }
locals: { 'com/sun/proxy/$Proxy69', 'java/lang/String', '[I', integer, 'org/glowroot/agent/bytecode/api/ThreadContextThreadLocal$Holder', 'org/glowroot/agent/bytecode/api/ThreadContextPlus', integer, 'org/glowroot/agent/plugin/api/Timer', 'java/lang/String' }
stack: { 'java/lang/Throwable' }
Bytecode:
0000000: 033e 013a 0401 3a05 0236 0601 3a07 2b3a
0000010: 0819 04c7 0008 b800 9a3a 0419 04b6 00a2
0000020: 593a 05c6 001f 1905 b900 a501 0059 3606
0000030: 12a6 9f00 1019 0512 a6b9 00aa 0200 04a7
0000040: 0004 033e 1d99 000a 1905 b801 053a 072a
0000050: b400 592a b201 0705 bd00 7159 032b 5359
0000060: 042c 53b9 0061 0400 c001 09a7 000e bf4c
0000070: bb00 6859 2bb7 006b bf1d 9900 0959 1908
0000080: b801 0c1d 9900 0819 07b8 0110 1506 029f
0000090: 000c 1905 1506 b900 aa02 00b0 1d99 0008
00000a0: 1907 b801 1015 0602 9f00 0c19 0515 06b9
00000b0: 00aa 0200 bf
Exception Handler Table:
bci [79, 110] => handler: 110
bci [79, 110] => handler: 110
bci [79, 110] => handler: 110
bci [79, 110] => handler: 111
bci [79, 121] => handler: 156
Stackmap Table:
full_frame(@27,{Object[#2],Object[#125],Object[#254],Integer,Object[#156],Object[#158],Integer,Object[#256],Object[#125]},{})
same_frame(@66)
same_locals_1_stack_item_frame(@67,Integer)
same_frame(@79)
same_locals_1_stack_item_frame(@110,Object[#85])
same_locals_1_stack_item_frame(@111,Object[#85])
same_locals_1_stack_item_frame(@121,Object[#265])
same_locals_1_stack_item_frame(@131,Object[#265])
same_locals_1_stack_item_frame(@140,Object[#265])
same_locals_1_stack_item_frame(@155,Object[#265])
same_locals_1_stack_item_frame(@156,Object[#85])
same_locals_1_stack_item_frame(@165,Object[#85])
same_locals_1_stack_item_frame(@180,Object[#85])
at java.base/java.lang.Class.getDeclaredConstructors0(Native Method) ~[na:na]
at java.base/java.lang.Class.privateGetDeclaredConstructors(Class.java:3215) ~[na:na]
at java.base/java.lang.Class.getConstructor0(Class.java:3420) ~[na:na]
at java.base/java.lang.Class.getConstructor(Class.java:2165) ~[na:na]
at java.base/java.lang.reflect.Proxy$ProxyBuilder.build(Proxy.java:660) ~[na:na]
at java.base/java.lang.reflect.Proxy.lambda$getProxyConstructor$0(Proxy.java:424) ~[na:na]
at java.base/jdk.internal.loader.AbstractClassLoaderValue$Memoizer.get(AbstractClassLoaderValue.java:329) ~[na:na]
at java.base/jdk.internal.loader.AbstractClassLoaderValue.computeIfAbsent(AbstractClassLoaderValue.java:205) ~[na:na]
at java.base/java.lang.reflect.Proxy.getProxyConstructor(Proxy.java:422) ~[na:na]
at java.base/java.lang.reflect.Proxy.newProxyInstance(Proxy.java:1015) ~[na:na]
at org.springframework.jdbc.core.JdbcTemplate.createConnectionProxy(JdbcTemplate.java:355) ~[spring-jdbc-5.2.7.RELEASE.jar!/:5.2.7.RELEASE]
at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:327) ~[spring-jdbc-5.2.7.RELEASE.jar!/:5.2.7.RELEASE]
at org.springframework.boot.jdbc.EmbeddedDatabaseConnection.isEmbedded(EmbeddedDatabaseConnection.java:120) ~[spring-boot-2.3.1.RELEASE.jar!/:2.3.1.RELEASE]
at org.springframework.boot.autoconfigure.orm.jpa.HibernateDefaultDdlAutoProvider.getDefaultDdlAuto(HibernateDefaultDdlAutoProvider.java:42) ~[spring-boot-autoconfigure-2.3.1.RELEASE.jar!/:2.3.1.RELEASE]
at org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaConfiguration.lambda$getVendorProperties$1(HibernateJpaConfiguration.java:130) ~[spring-boot-autoconfigure-2.3.1.RELEASE.jar!/:2.3.1.RELEASE]
at org.springframework.boot.autoconfigure.orm.jpa.HibernateSettings.getDdlAuto(HibernateSettings.java:41) ~[spring-boot-autoconfigure-2.3.1.RELEASE.jar!/:2.3.1.RELEASE]
at org.springframework.boot.autoconfigure.orm.jpa.HibernateProperties.determineDdlAuto(HibernateProperties.java:136) ~[spring-boot-autoconfigure-2.3.1.RELEASE.jar!/:2.3.1.RELEASE]
at org.springframework.boot.autoconfigure.orm.jpa.HibernateProperties.getAdditionalProperties(HibernateProperties.java:102) ~[spring-boot-autoconfigure-2.3.1.RELEASE.jar!/:2.3.1.RELEASE]
at org.springframework.boot.autoconfigure.orm.jpa.HibernateProperties.determineHibernateProperties(HibernateProperties.java:94) ~[spring-boot-autoconfigure-2.3.1.RELEASE.jar!/:2.3.1.RELEASE]
at org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaConfiguration.getVendorProperties(HibernateJpaConfiguration.java:132) ~[spring-boot-autoconfigure-2.3.1.RELEASE.jar!/:2.3.1.RELEASE]
at org.springframework.boot.autoconfigure.orm.jpa.JpaBaseConfiguration.entityManagerFactory(JpaBaseConfiguration.java:133) ~[spring-boot-autoconfigure-2.3.1.RELEASE.jar!/:2.3.1.RELEASE]
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na]
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:na]
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na]
at java.base/java.lang.reflect.Method.invoke(Method.java:564) ~[na:na]
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154) ~[spring-beans-5.2.7.RELEASE.jar!/:5.2.7.RELEASE]
... 28 common frames omitted
```https://gitlab.ow2.org/asm/asm/-/issues/317913Issue when using LocalVariablesSorter2020-07-19T15:30:55ZManuel CarrascoIssue when using LocalVariablesSorterHello everyone!
I'm trying to use `LocalVariablesSorter` to transform a function in such a way local variable indexes are used consecutively. I checked the [test cases](https://gitlab.ow2.org/asm/asm/-/blob/master/asm-commons/src/test/j...Hello everyone!
I'm trying to use `LocalVariablesSorter` to transform a function in such a way local variable indexes are used consecutively. I checked the [test cases](https://gitlab.ow2.org/asm/asm/-/blob/master/asm-commons/src/test/java/org/objectweb/asm/commons/LocalVariablesSorterTest.java#L192) but I have no luck to make it work. My code yields exactly the same input bytecode. Kindly, I'd like to ask you if you could tell me what I'm missing.
Bytecode:
```
public static int foo(long, int);
Code:
0: lload_0
1: iload_2
2: invokestatic #3 // Method java/lang/Long.toString:(JI)Ljava/lang/String;
5: astore_3
6: aload_3
7: invokestatic #4 // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
10: ireturn
```
My intent is to generate a new function in which we use local variable indexes: 0, 1 and 2 instead of 0, 2 and 3.
```
ClassReader cr = new ClassReader(stream);
ClassWriter cw = new ClassWriter(cr, 0);
ClassVisitor classVisitor = new ClassVisitor(Opcodes.ASM8, cw){
@Override
public MethodVisitor visitMethod(
final int access,
final String name,
final String descriptor,
final String signature,
final String[] exceptions) {
MethodVisitor methodVisitor =
super.visitMethod(access, name, descriptor, signature, exceptions);
return new LocalVariablesSorter(access, descriptor, methodVisitor);
}
};
cr.accept(classVisitor, ClassReader.EXPAND_FRAMES);
FileUtils.writeByteArrayToFile(new File("mypath/..."), cw.toByteArray());
```
Best,
Manuel.https://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/317910Iterating over a InsnList with an iterator traverses the list twice2020-07-05T12:14:03ZOskar Haarklou VeileborgIterating over a InsnList with an iterator traverses the list twiceWhen you traverse an InsnList either with a for-each loop or explicitly with an iterator:
```java
void iter(InsnList insns) {
for(AbstractInsnNode insn : insns) { /* ... */ }
// Or
ListIterator<AbstractInsnNode> it = insns.i...When you traverse an InsnList either with a for-each loop or explicitly with an iterator:
```java
void iter(InsnList insns) {
for(AbstractInsnNode insn : insns) { /* ... */ }
// Or
ListIterator<AbstractInsnNode> it = insns.iterator();
while(it.hasNext()) {
AbstractInsnNode insn = it.next();
/* ... */
}
}
```
The InsnList is traversed twice, as the call to `InsnList.iterator()` calls `InsnList.get(0)` internally, which populates the instruction cache by traversing the instruction list.
This is a waste of time and space if the cache is unneeded.
I'll happily submit a Merge Request unless there's a good reason that the implementation should stay as it is.https://gitlab.ow2.org/asm/asm/-/issues/317909Analyzer fails on zero division2020-06-13T08:32:42ZAura LeeAnalyzer fails on zero divisionAnalyzing the bytecode of the following code leads to an AnalyzerException:
```java
public static void main(String[] args) {
try {
int ignored = 0 / 0; // or x % 0
} catch (ArithmeticException e) {
System.out.printl...Analyzing the bytecode of the following code leads to an AnalyzerException:
```java
public static void main(String[] args) {
try {
int ignored = 0 / 0; // or x % 0
} catch (ArithmeticException e) {
System.out.println("continue code normally");
...
}
}
```
`org.objectweb.asm.tree.analysis.AnalyzerException: Error at instruction 4: / by zero, Cause: [java.lang.ArithmeticException: / by zero]`https://gitlab.ow2.org/asm/asm/-/issues/317908Some suggestions2020-06-06T06:42:13ZAura LeeSome suggestionsIt is pretty annoying that some classes like Subroutine are final and non-public. Because of that, I cannot extend the Analyzer class. You may think that users won't need to extend the Analyzer class because there is an Interpreter inter...It is pretty annoying that some classes like Subroutine are final and non-public. Because of that, I cannot extend the Analyzer class. You may think that users won't need to extend the Analyzer class because there is an Interpreter interface, but in my case need it, as i want to handle edges of jumps with a known outcome differently. The same applies to MethodWriter and other classes.
Another thing that bothers me is that InvokeDynamicInsnNode has a public bsmArgs[], but ConstantDynamic only has a private one with get / set methods. This is pretty annoying when i want to iterate over the args.
Also think about implementing those methods in the Type class:
```java
public Type toArray(int dimensions)
public static Type getOpcodeReturnType(int opcode)
public static Type[] getOpcodeArgumentTypes(int opcode)
public static Type getGenericType(int sort)
```https://gitlab.ow2.org/asm/asm/-/issues/317907ASM incorrectly expands frames in some cases.2020-06-06T06:42:57ZraphwASM incorrectly expands frames in some cases.When instrumenting classes from JBoss Weld, expanding frames can cause ASM to throw an exception upon reprocessing it's own class files. Here is a simple reproduction for a sample class file (attached):
```
ClassReader classReader = new...When instrumenting classes from JBoss Weld, expanding frames can cause ASM to throw an exception upon reprocessing it's own class files. Here is a simple reproduction for a sample class file (attached):
```
ClassReader classReader = new ClassReader(new FileInputStream("sample.class"));
ClassWriter classWriter = new ClassWriter(ClassWriter.COMPUTE_FRAMES);
CheckClassAdapter classVisitor = new CheckClassAdapter(classWriter, true);
classReader.accept(new TraceClassVisitor(classVisitor, new PrintWriter(System.out)), ClassReader.EXPAND_FRAMES);
```
When removing the `EXPAND_FRAMES` option, the class file can be reprocessed without issues.https://gitlab.ow2.org/asm/asm/-/issues/317906[question] ASM exceptions policy2020-05-28T18:49:53ZVsevolod Tolstopyatov[question] ASM exceptions policyHi, we at JetBrains are developing coverage-based fuzzer and decided to give it a test try on ASM `ClassReader`.
We've immediately caught a lot of `IllegalArgumentException` (which seems to be ok and a lot of code in the wild handle it)...Hi, we at JetBrains are developing coverage-based fuzzer and decided to give it a test try on ASM `ClassReader`.
We've immediately caught a lot of `IllegalArgumentException` (which seems to be ok and a lot of code in the wild handle it), a bunch of `ArrayIndexOutOfBoundsException` and even `NegativeArraySizeException` in a first few minutes of fuzzing.
But [documentation](https://www.javadoc.io/doc/org.ow2.asm/asm/latest/org/objectweb/asm/ClassReader.html) does not state anything about exception types, so maybe these exceptions are completely okay and expected on garbage (~corrupted) inputs.
Is it worth reporting any inputs that produce exceptions other than `IllegalArgumentException`?https://gitlab.ow2.org/asm/asm/-/issues/317905Issues with JSRInlinerAdapter and LocalVariableTable size2020-05-28T18:52:29ZAndres LuukIssues with JSRInlinerAdapter and LocalVariableTable sizeA client of mine got a following error:
java.lang.ClassFormatError: LocalVariableTable has wrong length in class file cfdump2ecfm851157132$funcDUMPOBJECT
I tracked the issue down to the JSRInlinerAdapter we use.
The issue is that the fai...A client of mine got a following error:
java.lang.ClassFormatError: LocalVariableTable has wrong length in class file cfdump2ecfm851157132$funcDUMPOBJECT
I tracked the issue down to the JSRInlinerAdapter we use.
The issue is that the failing class is a generated class (made by ColdFusion) with old file format that contains a lot of jsr/ret instructions and a lot of local variables that are all defined though the entire class.
for example:
```
0 27121 114 t114 Ljava/lang/Throwable;
```
So after the inlining 478 will became 116513 items. For example:
```
4 27427 114 t114 Ljava/lang/Throwable;
27431 10 114 t114 Ljava/lang/Throwable;
27441 10 114 t114 Ljava/lang/Throwable;
27451 10 114 t114 Ljava/lang/Throwable;
...
```
My current fix is that I simply cap the size of LocalVariableTable to 65565 after JSRInlinerAdapter:
```
if (localVariables != null && localVariables.size() > 65535) {
localVariables = localVariables.subList(0, 65535);
}
```
I think it would also be possible to try to merge the new frames because currently they still cover the entire method, but they are split into pieces.
We can still have the old frame and add only a single new one for the inlined part (this would reduce the number a lot), inside JSRInlinerAdapter, but this will probably be more complex.
The fix of capping the number of lines is currently sufficient fix for us. But I made this case, in case you want to make some fix into ASM for other users of the JSRInlinerAdapter.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/317902Transformation triggered by Java agent only executed if writing/flushing Syst...2020-05-28T18:53:25ZAlexander KriegischTransformation triggered by Java agent only executed if writing/flushing System.out/err beforeToday I used ASM (version 8.0.1) for the first time and implemented a super simple Java agent which can definalise (remove `final` modifier) classes and methods. This works perfectly. It was much easier to implement than in Javassist or ...Today I used ASM (version 8.0.1) for the first time and implemented a super simple Java agent which can definalise (remove `final` modifier) classes and methods. This works perfectly. It was much easier to implement than in Javassist or ByteBuddy, in both of which I implemented the same thing before in order to compare how it feels to work with those tools.
My agent looks like this:
```java
package de.scrum_master.agent;
import org.objectweb.asm.ClassReader;
import org.objectweb.asm.ClassVisitor;
import org.objectweb.asm.ClassWriter;
import org.objectweb.asm.MethodVisitor;
import java.lang.instrument.ClassFileTransformer;
import java.lang.instrument.Instrumentation;
import java.lang.reflect.Modifier;
import java.security.ProtectionDomain;
import static org.objectweb.asm.ClassReader.SKIP_DEBUG;
import static org.objectweb.asm.ClassReader.SKIP_FRAMES;
import static org.objectweb.asm.Opcodes.ASM8;
public class MyAgent {
public static void premain(String configFile, Instrumentation instrumentation) {
transform(configFile, instrumentation);
}
private static void transform(String configFile, Instrumentation instrumentation) {
// System.out.println("MyAgent");
// System.out.flush();
// System.err.println("xxx");
instrumentation.addTransformer(new ClassFileTransformer() {
@Override
public byte[] transform(ClassLoader loader, String className, Class<?> classBeingRedefined, ProtectionDomain protectionDomain, byte[] classfileBuffer) {
ClassReader classReader = new ClassReader(classfileBuffer);
// We just change class/method modifiers -> no need to visit all parts of the code
int flags = SKIP_DEBUG | SKIP_FRAMES;
ClassWriter classWriter = new ClassWriter(classReader, flags);
classReader.accept(new RemoveFinalVisitor(classWriter), flags);
return classWriter.toByteArray();
}
});
}
public static class RemoveFinalVisitor extends ClassVisitor {
public RemoveFinalVisitor(ClassVisitor cv) {
super(ASM8, cv);
}
@Override
public void visit(int version, int access, String name, String signature, String superName, String[] interfaces) {
cv.visit(version, access & ~Modifier.FINAL, name, signature, superName, interfaces);
}
@Override
public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) {
return super.visitMethod(access & ~Modifier.FINAL, name, desc, signature, exceptions);
}
}
}
```
I am creating my agent incl. manifest with Maven in the usual way:
```xml
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.2.0</version>
<configuration>
<archive>
<manifestEntries>
<Agent-Class>de.scrum_master.agent.MyAgent</Agent-Class>
<Premain-Class>de.scrum_master.agent.MyAgent</Premain-Class>
<Can-Redefine-Classes>true</Can-Redefine-Classes>
<Can-Retransform-Classes>true</Can-Retransform-Classes>
<Can-Set-Native-Method-Prefix>true</Can-Set-Native-Method-Prefix>
</manifestEntries>
</archive>
</configuration>
</plugin>
```
Then I test if definalisation of a JRE class which usually is not loaded before starting an agent works or not:
```java
package de.scrum_master.agent;
import java.lang.reflect.Modifier;
import java.util.UUID;
public class TestApplication {
public static void main(String[] args) {
System.out.println(Modifier.toString(UUID.class.getModifiers()));
}
}
```
This prints `public final`, i.e. the transformation has not been performed. It is the same when testing this with with an application class on the normal classpath (not bootstrap classpath). Now just uncomment any single one of these lines in the agent and rebuild the agent JAR:
```java
// System.out.println("MyAgent");
// System.out.flush();
// System.err.println("xxx");
```
As long as any standard/error output stream is flushed or written to **before** calling `instrumentation.addTransformer(...)`, this magically makes the ASM transformation work, I have absolutely no idea why. But when running `TestApplication` now, the console log says `public`, i.e. the `final` is gone as expected.https://gitlab.ow2.org/asm/asm/-/issues/317901How could I add a new constructor to a class?2020-05-28T18:53:48ZChad EstiocoHow could I add a new constructor to a class?I am migrating an old framework that used ow2.asm extensively for unit tests from Java 7 to Java 11. It creates "proxy" classes on the fly based from an interface. My problem is that it now fails when it tries to add a constructor and I'...I am migrating an old framework that used ow2.asm extensively for unit tests from Java 7 to Java 11. It creates "proxy" classes on the fly based from an interface. My problem is that it now fails when it tries to add a constructor and I'm not sure how ow2.asm is _supposed_ to add constructors in the first place.
Here's a minimal trace of how this framework uses ow2.asm. I've ensured that the framework is using v8.0.1 (updated from version 5):
```java
// We start with this method which abstracts the creation of proxy classes
// from the given interface.
defineProxyClass(Class<?> interf, String packageName, String clazzName) {
ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS | ClassWriter.COMPUTE_FRAMES);
// some strings are constructed
// The code does this but I think this can be ignored in new Java versions?
ClassVisitor cv = cw;
// I'm unsure if these calls are relevant
cv.visit(51, Opcodes.ACC_PUBLIC | Opcodes.ACC_FINAL, fullClazzName, null, "java/lang/Object",
new String[] { interfInternalName } // Interfaces
);
// Add field that holds reference to proxied object
cv.visitField(Opcodes.ACC_PRIVATE | Opcodes.ACC_FINAL, "proxiedObject", Type.getType(interf).getDescriptor(), null,
null);
// This is the problematic method
addConstructor(cv, fullClazzName, interfInternalName);
// Nothing more relevant follows, as far as I can tell
}
```
Now the problematic method does as follows:
```java
void addConstructor(ClassVisitor cv, String clazzIntName, String paramDesc) {
// This is the constructor this is supposed to create and add
MethodVisitor mv = cv.visitMethod(1, "<init>", "(L" + paramDesc + ";)V", (String)null, (String[])null);
mv.visitCode();
mv.visitVarInsn(25, 0);
mv.visitMethodInsn(183, "java/lang/Object", "<init>", "()V", false);
mv.visitVarInsn(25, 0);
mv.visitVarInsn(25, 1);
mv.visitFieldInsn(181, clazzIntName, "proxiedObject", "L" + paramDesc + ";");
mv.visitInsn(177);
mv.visitMaxs(2, 2);
mv.visitEnd();
}
```
Now, it seems to me that this code is "incomplete"; the `addConstructor` method visits/creates the desired constructor but does not actually "add" them to `cv`. Is the call to `visitMethod` above enough?
I tried adding a call to `ClassWriter.newMethod` but the resulting test error just changed but I think it's just my ignorance in using `newMethod` properly. Are there examples available of what I am trying to achieve? Is this possible with ow2.asm at all?https://gitlab.ow2.org/asm/asm/-/issues/317900Javadoc of ClassVisitor does not specify order of visitRecordComponent.2020-05-28T19:04:18ZraphwJavadoc of ClassVisitor does not specify order of visitRecordComponent.It's minor but I stumbled over it. The javadoc does not mention when visitRecordComponent would be called in the order of methods.It's minor but I stumbled over it. The javadoc does not mention when visitRecordComponent would be called in the order of methods.https://gitlab.ow2.org/asm/asm/-/issues/317899Record without components is not processed correctly2020-05-28T18:54:09ZraphwRecord without components is not processed correctlyUnfortunately, the JVM only recognizes a record as such if a record attribute is present in the class file. ASM only generates such an attribute if at least one record component is defined. As a consequence, the following record is not p...Unfortunately, the JVM only recognizes a record as such if a record attribute is present in the class file. ASM only generates such an attribute if at least one record component is defined. As a consequence, the following record is not processed correctly: `record EmptyRecord() {}`.
This can be validated easily by replaying an ASMified record:
ClassReader reader = new ClassReader(EmptyRecord.class.getName());
reader.accept(new TraceClassVisitor(null, new ASMifier(), new PrintWriter(System.out)), 0);
I suggest adding an additional `ClassVisitor` method: `visitRecord` with no arguments.
On a side note, the `ClassVisitor` javaDoc does not mention the order in which the new method should be invoked.
For reference, the the code in OpenJDK:
bool is_record() const { return _record_components != NULL; }