RFR: JDK-8220041: NullPointerException at jdk.compiler/com.sun.tools.javac.jvm.Code.emitop0

Maurizio Cimadamore maurizio.cimadamore at oracle.com
Tue Jul 9 15:39:48 UTC 2019


Looks good

Maurizio

On 09/07/2019 15:54, Jan Lahoda wrote:
> Hi,
>
> Consider code like:
> ---
>     I<String> lambdaCapture1(int i) {
>         I<String> r = switch (i) {
>             default -> {
>                 String k = "D";
>                 yield () -> k; //need to capture k here
>             }
>         };
>
>         return r;
>     }
>
>     interface I<T> {
>         public T t();
>     }
> ---
>
> "k" needs to be captured, but LambdaToMethod fails to recognize that, 
> as the enclosing Frame is for a variable declaration, which does not 
> check the definitions under the variable decl (since before switch 
> expressions, this could not happen). This then eventually leads either 
> to a compiler crash, or a failure at runtime. The proposed solution is 
> to check local variables in the variables frame, to see if they should 
> be captured or not.
>
> JBS: https://bugs.openjdk.java.net/browse/JDK-8220041
> Webrev: http://cr.openjdk.java.net/~jlahoda/8220041/webrev.00/
>
> How does this look?
>
> Thanks,
>     Jan


More information about the compiler-dev mailing list