[Ask for sponsoring] Fix another NPE in jdk.compiler/com.sun.tools.javac.jvm.Code.emitop0(Code.java:571)
JiaYanwei
jiaywe at gmail.com
Wed Dec 23 04:49:06 UTC 2020
Great! I think it's the best solution and can also be directly backported
to 16, 11 & 8.
Should I close (i.e. stop/cancel) the Github PR, or may I commit this code
with you(B. Blaser) as the author - just like what Jan Lahoda did in Github
PR 1221?
B. Blaser <bsrbnd at gmail.com> 于2020年12月22日周二 上午8:56写道:
> Hi,
>
> On Sun, 20 Dec 2020 at 10:49, JiaYanwei <jiaywe at gmail.com> wrote:
> >
> > Hi all,
> >
> > I had found & fixed a javac issue like
> https://bugs.openjdk.java.net/browse/JDK-8229862 , and created a PR on
> Github: https://github.com/openjdk/jdk/pull/1479 .
> >
> > I have no account to create JIRA issue, and I'm not sure whether the
> code style as well as the solution itself are appropriate. Could anyone
> sponsor me? Thanks a lot.
> >
> > Best Regards.
>
> The problem seems to be that 'lambdaTranslationMap' links the
> untranslated local variable to its capture. So, what do you think of
> the following solution to keep the translated local variable's mapping
> with the original symbol (both examples and langtools:tier1 are OK on
> jdk14u)?
>
> Thanks,
> Bernard
>
> diff --git
> a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/LambdaToMethod.java
>
> b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/LambdaToMethod.java
> ---
> a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/LambdaToMethod.java
> +++
> b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/LambdaToMethod.java
> @@ -2057,7 +2057,13 @@
> };
> break;
> case LOCAL_VAR:
> - ret = new VarSymbol(sym.flags() & FINAL,
> sym.name, sym.type, translatedSym);
> + ret = new VarSymbol(sym.flags() & FINAL,
> sym.name, sym.type, translatedSym) {
> + @Override
> + public Symbol baseSymbol() {
> + //keep mapping with original symbol
> + return sym;
> + }
> + };
> ((VarSymbol) ret).pos = ((VarSymbol) sym).pos;
> break;
> case PARAM:
> diff --git
> a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Lower.java
> b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Lower.java
> --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Lower.java
> +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Lower.java
> @@ -1221,7 +1221,7 @@
> //sym is a local variable - check the lambda translation
> map to
> //see if sym has been translated to something else in
> the current
> //scope (by LambdaToMethod)
> - Symbol translatedSym = lambdaTranslationMap.get(sym);
> + Symbol translatedSym =
> lambdaTranslationMap.get(sym.baseSymbol());
> if (translatedSym != null) {
> tree = make.at(tree.pos).Ident(translatedSym);
> }
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.java.net/pipermail/compiler-dev/attachments/20201223/ebd984a2/attachment.htm>
More information about the compiler-dev
mailing list