Bug 565254 - [java 14] java.lang.IllegalArgumentException at aj.org.objectweb.asm.ClassReader.readConst(ClassReader.java:3617)
Summary: [java 14] java.lang.IllegalArgumentException at aj.org.objectweb.asm.ClassRea...
Status: NEW
Alias: None
Product: AspectJ
Classification: Tools
Component: LTWeaving (show other bugs)
Version: 1.9.5   Edit
Hardware: PC Linux
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: aspectj inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-07-15 17:43 EDT by Marek Jagielski CLA
Modified: 2020-07-19 07:47 EDT (History)
1 user (show)

See Also:


Attachments
LTW java 14 asm fails on readConst (7.07 KB, text/x-java)
2020-07-15 17:43 EDT, Marek Jagielski CLA
no flags Details
dumb1 (43.89 KB, text/plain)
2020-07-16 14:55 EDT, Marek Jagielski CLA
no flags Details
dump2 (43.89 KB, text/plain)
2020-07-16 14:56 EDT, Marek Jagielski CLA
no flags Details
dump3 (51.80 KB, text/plain)
2020-07-16 14:56 EDT, Marek Jagielski CLA
no flags Details
dump4 (43.74 KB, text/plain)
2020-07-16 14:56 EDT, Marek Jagielski CLA
no flags Details
dump5 (43.74 KB, text/plain)
2020-07-16 14:57 EDT, Marek Jagielski CLA
no flags Details
dump6 (43.60 KB, text/plain)
2020-07-16 14:57 EDT, Marek Jagielski CLA
no flags Details
Class being parsed when error happen (8.88 KB, application/java-vm)
2020-07-18 12:49 EDT, Marek Jagielski CLA
no flags Details
Jar needed on classpath to parse class (126.94 KB, application/x-java-archive)
2020-07-18 12:52 EDT, Marek Jagielski CLA
no flags Details
parse method groovy script (10.61 KB, text/x-groovy)
2020-07-18 12:57 EDT, Marek Jagielski CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Marek Jagielski CLA 2020-07-15 17:43:35 EDT
Created attachment 283612 [details]
LTW java 14 asm fails on readConst

I recently upgraded my tycho project to java 14. I use LTWeaving in my integration tests to simulate corner or error cases.

After upgrade to java 14 target when running test by tycho-surefire-plugin with aspectjweaver as my agent I get below error:

AspectJ Internal Error: unable to add stackmap attributes. null
java.lang.IllegalArgumentException
	at aj.org.objectweb.asm.ClassReader.readConst(ClassReader.java:3617)
	at aj.org.objectweb.asm.ClassReader.readCode(ClassReader.java:2193)
	at aj.org.objectweb.asm.ClassReader.readMethod(ClassReader.java:1284)
	at aj.org.objectweb.asm.ClassReader.accept(ClassReader.java:688)
	at aj.org.objectweb.asm.ClassReader.accept(ClassReader.java:400)
	at org.aspectj.weaver.bcel.asm.StackMapAdder.addStackMaps(StackMapAdder.java:45)

Debuging tells me that it fails in context of constructor of attached class that is supposed to be weaved.
I tried also this version https://repo.spring.io/snapshot/org/aspectj/aspectjweaver/1.9.6.BUILD-SNAPSHOT/ with the same results.

Do java 14 is not yet supported at all even if I do not use java 14 specific syntax?
Comment 1 Andrew Clement CLA 2020-07-15 18:03:08 EDT
Hey - you will need 1.9.6 for Java14. The latest snapshot is 1.9.6.BUILD-SNAPSHOT which is in the Spring repo: 

<repository>
<id>snapshots</id>
<name>snapshots</name>
<url>https://repo.spring.io/snapshot</url>
</repository>

I was waiting for a bit of extra feedback on a particular issue before formally releasing it but I think I've waited long enough so I'll do the release soon.
Comment 2 Andrew Clement CLA 2020-07-15 18:03:39 EDT
Although I see the end of your comment says you tried it, interesting.
Comment 3 Andrew Clement CLA 2020-07-15 18:05:34 EDT
Possibly the ASM that is being used isn't recent enough (see the stacktrace is mentioning the shaded copy of asm included in AspectJ). Maybe it is  lucky I haven't done the full release :) I'll see what version we are on of that library and see if I can update it.
Comment 4 Marek Jagielski CLA 2020-07-16 14:55:48 EDT
Created attachment 283616 [details]
dumb1
Comment 5 Marek Jagielski CLA 2020-07-16 14:56:08 EDT
Created attachment 283617 [details]
dump2
Comment 6 Marek Jagielski CLA 2020-07-16 14:56:24 EDT
Created attachment 283618 [details]
dump3
Comment 7 Marek Jagielski CLA 2020-07-16 14:56:52 EDT
Created attachment 283619 [details]
dump4
Comment 8 Marek Jagielski CLA 2020-07-16 14:57:31 EDT
Created attachment 283620 [details]
dump5
Comment 9 Marek Jagielski CLA 2020-07-16 14:57:52 EDT
Created attachment 283621 [details]
dump6
Comment 10 Marek Jagielski CLA 2020-07-16 15:09:00 EDT
I attached files that are being generated when I run tests. Before upgrade those files haven't been generated.
The error in one file:

org.aspectj.weaver.BCException: Unable to find Asm for stackmap generation (Looking for 'aj.org.objectweb.asm.ClassReader'). Stackmap generation for woven code is required to avoid verify errors on a Java 1.7 or higher runtime

I see also in the console but after the first one mentioned in the first message. I assume that "Unable to find Asm for stackmap" is a consequence of the first.

I don't see information in stack about asm being used. I will debug so I can confirm the version. 
Seeing pom.xml of weaver I suppose that we expect version 7.2:
    <dependency>
      <groupId>asm</groupId>
      <artifactId>asm</artifactId>
      <version>1.0</version>
      <scope>system</scope>
      <systemPath>${project.basedir}/../lib/asm/asm-7.2.renamed.jar</systemPath>
    </dependency>
Comment 11 Marek Jagielski CLA 2020-07-16 15:49:46 EDT
From: https://asm.ow2.io/versions.html
I see that version 7.3.1 introduced "new V15 constant". Maybe related as my exception is on "readConst".
Comment 12 Andrew Clement CLA 2020-07-16 16:58:04 EDT
I upgraded from 7.2 asm to 8.0 - and published a 1.9.6.BUILD-SNAPSHOT that is worth trying I think.
Comment 13 Marek Jagielski CLA 2020-07-18 11:58:07 EDT
The same problem still persists with the same stack. Dumps file shows that I do use the new version:
---- AspectJ Properties ---
AspectJ Compiler 1.9.6.BUILD-SNAPSHOT built on Thursday Jul 16, 2020 at 12:52:30 PDT

I will try to use asm library to directly to parse my code
Comment 14 Marek Jagielski CLA 2020-07-18 12:49:39 EDT
Created attachment 283638 [details]
Class being parsed when error happen

Class being parsed
Comment 15 Marek Jagielski CLA 2020-07-18 12:52:11 EDT
Created attachment 283639 [details]
Jar needed on classpath to parse class
Comment 16 Marek Jagielski CLA 2020-07-18 12:55:53 EDT
I am able to parse constructor even withasm 7.0:
ALOAD 0
INVOKESPECIAL org/eclipse/ui/wizards/newresource/BasicNewProjectResourceWizard.<init> ()V
RETURN

I am not sure if I do it correctly. I am attaching groovy script with code from stackoverflow: https://stackoverflow.com/questions/7984003/pretty-printing-a-method-in-asm-bytecode
Comment 17 Marek Jagielski CLA 2020-07-18 12:57:32 EDT
Created attachment 283640 [details]
parse method groovy script

groovy -cp org.eclipse.equinox.common_3.12.0.v20200504-1602.jar  asm.groovy CreateProjectWizard.class
Comment 18 Marek Jagielski CLA 2020-07-19 06:51:09 EDT
I tried using directly aspectjweaver and I can parse class (no error):

@Grab(group='org.aspectj', module='aspectjweaver', version='1.9.5')

import aj.org.objectweb.asm.ClassReader;
import aj.org.objectweb.asm.ClassVisitor;
import aj.org.objectweb.asm.ClassWriter;

import org.aspectj.weaver.bcel.BcelWorld
import org.aspectj.weaver.bcel.asm.StackMapAdder.AspectJClassVisitor;
import org.aspectj.weaver.bcel.asm.StackMapAdder.AspectJConnectClassWriter;

FileInputStream is = new FileInputStream(args[0])
ClassReader cr = new ClassReader(is)
ClassWriter cw = new AspectJConnectClassWriter(cr, new BcelWorld(args[1]))
ClassVisitor cv = new AspectJClassVisitor(cw)
cr.accept(cv, 0)
println cw.toByteArray()

groovy asm-aj.groovy CreateProjectWizard.class org.eclipse.equinox.common_3.12.0.v20200504-1602.jar

Does the sate of BcelWorld depends on something more I should try to reproduce the issue?
Comment 19 Marek Jagielski CLA 2020-07-19 07:06:46 EDT
There was one additional information that I should have been mentioned and it looks this is the reason of error. Together with aspecjweaver agent I am using also jacoco agent and jacoco is preceding aspectj. Jacoco is on version 8.5.0 that officially is not supporting java 14. Removing jacoco agent error doesn't appear.
I guess you can close the issue.
Thanks!
Comment 20 Marek Jagielski CLA 2020-07-19 07:47:04 EDT
Just for info. I tried pair with jacoco snapshot agent org.jacoco.agent-0.8.6-20200717.014125-68-runtime.jar:
https://www.jacoco.org/jacoco/trunk/doc/changes.html

The problem exists. It looks like they also use ASM 8.0.1.