Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use ASM9 API #1097

Merged
merged 2 commits into from Sep 29, 2020
Merged

Use ASM9 API #1097

merged 2 commits into from Sep 29, 2020

Conversation

Godin
Copy link
Member

@Godin Godin commented Sep 29, 2020

For following Example.java

sealed class Shape
    permits Circle
{
}

final class Circle extends Shape {
}

compiled as

javac --enable-preview --release 15 -d classes Example.java

by

openjdk version "15" 2020-09-15
OpenJDK Runtime Environment (build 15+36-1562)
OpenJDK 64-Bit Server VM (build 15+36-1562, mixed mode, sharing)

Execution of

java -jar jacococli.jar instrument classes --dest instrumented

succeeds when using released JaCoCo 0.8.6,
however fails when using snapshot after #1094

Exception in thread "main" java.io.IOException: Error while instrumenting /private/tmp/j/classes/Shape.class.
        at org.jacoco.cli.internal.core.instr.Instrumenter.instrumentError(Instrumenter.java:160)
        at org.jacoco.cli.internal.core.instr.Instrumenter.instrument(Instrumenter.java:110)
        at org.jacoco.cli.internal.core.instr.Instrumenter.instrument(Instrumenter.java:135)
        at org.jacoco.cli.internal.core.instr.Instrumenter.instrument(Instrumenter.java:155)
        at org.jacoco.cli.internal.core.instr.Instrumenter.instrumentAll(Instrumenter.java:194)
        at org.jacoco.cli.internal.commands.Instrument.instrument(Instrument.java:89)
        at org.jacoco.cli.internal.commands.Instrument.instrumentRecursive(Instrument.java:78)
        at org.jacoco.cli.internal.commands.Instrument.instrumentRecursive(Instrument.java:74)
        at org.jacoco.cli.internal.commands.Instrument.execute(Instrument.java:61)
        at org.jacoco.cli.internal.Main.execute(Main.java:90)
        at org.jacoco.cli.internal.Main.main(Main.java:105)
Caused by: java.lang.UnsupportedOperationException: PermittedSubclasses requires ASM9
        at org.jacoco.cli.internal.asm.ClassVisitor.visitPermittedSubclass(ClassVisitor.java:266)
        at org.jacoco.cli.internal.asm.ClassReader.accept(ClassReader.java:673)
        at org.jacoco.cli.internal.asm.ClassReader.accept(ClassReader.java:394)
        at org.jacoco.cli.internal.core.instr.Instrumenter.instrument(Instrumenter.java:90)
        at org.jacoco.cli.internal.core.instr.Instrumenter.instrument(Instrumenter.java:108)
        ... 9 more

And will succeed after this change.

@Godin Godin added this to the 0.8.7 milestone Sep 29, 2020
@Godin Godin requested a review from marchof September 29, 2020 12:28
@Godin Godin self-assigned this Sep 29, 2020
@Godin Godin added this to Implementation in Current work items via automation Sep 29, 2020
@Godin
Copy link
Member Author

Godin commented Sep 29, 2020

@marchof during review of #1094 I overlooked missing update of InstrSupport.ASM_API_VERSION, sorry.

@Godin Godin moved this from Implementation to Review in Current work items Sep 29, 2020
@Godin Godin merged commit 8f9250a into master Sep 29, 2020
Current work items automation moved this from Review to Done Sep 29, 2020
@Godin Godin deleted the asm9 branch September 29, 2020 16:28
@Godin
Copy link
Member Author

Godin commented Sep 29, 2020

@marchof BTW for fun and for the record:
while ASM 8.0.1 was trying to restrict the ability to handle Java 15 class files before the actual release of Java 15
specifically Java 15 sealed classes preview feature (https://openjdk.java.net/jeps/360)
by requiring use of Opcodes.ASM9_EXPERIMENTAL
(see https://gitlab.ow2.org/asm/asm/-/blob/ASM_8_0_1/asm/src/main/java/org/objectweb/asm/ClassVisitor.java#L256-272)
which in his turn requires compilation with --enable-preview
(see https://gitlab.ow2.org/asm/asm/-/blob/ASM_8_0_1/asm/src/main/java/org/objectweb/asm/ClassVisitor.java#L69-80 and https://gitlab.ow2.org/asm/asm/-/blob/ASM_8_0_1/asm/src/main/java/org/objectweb/asm/Constants.java#L185-220)
it perfectly works in the case of JaCoCo 0.8.6 because
eventually the name of the attribute implemented in javac is PermittedSubclasses
(https://hg.openjdk.java.net/jdk/jdk/rev/843695160574#l57.50)
and not PermittedSubtypes
(https://gitlab.ow2.org/asm/asm/-/blob/ASM_8_0_1/asm/src/main/java/org/objectweb/asm/Constants.java#L76)
😉 😆

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Development

Successfully merging this pull request may close these issues.

None yet

2 participants