Question on JDK-8215470: Bad EnclosingMethod attribute
Sergei Ustimenko
merkel05 at gmail.com
Fri Jan 4 12:08:20 UTC 2019
Hi compiler-dev,
Recently I was working on the following bug:
https://bugs.openjdk.java.net/browse/JDK-8213465
It is mainly about anonymous classes that miss
type variable information if declared inside lambda expression.
It leads to a bug in the javac compiler
https://bugs.openjdk.java.net/browse/JDK-8215470 which
emits `EnclosingMethod` attribute that points to the synthetic
method for anonymous classes if declared inside lambda.
I was experimenting with it a bit and want to know compiler-dev's
opinion on what would be the best way to fix it.
So my goal in the end is to have `EnclosingMethod` for anonymous
classes, as well as for class declarations inside lambda expressions,
to have `EnclosingMethod` attribute pointing to the nearest lexically
enclosing method (not the synthetic method!)
I see a couple of options to probably achieve the goal:
1) Skip the lambdas when assigning the owner (e.g. use `owner(true)`)
http://hg.openjdk.java.net/jdk/sandbox/file/6f2d65f29de3/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/LambdaToMethod.java#l1388
that approach requires additional changes in other compiler
parts. I cannot say for sure how big the changes could be.
2) When compiler writes a classfile, identify the `EnclosingMethod`
attribute that point to synthetic method and repoint it to a lexically
enclosing method.
Does anybody have any suggestions? Should I at all try either of
options above? Is there any better way to do it? Please let me know.
Thanks,
Sergei
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.java.net/pipermail/compiler-dev/attachments/20190104/fc18b9fd/attachment.html>
More information about the compiler-dev
mailing list