RFR: 8301374: NullPointerException in MemberEnter.checkReceiver

Jan Lahoda jlahoda at openjdk.org
Tue Feb 14 16:04:13 UTC 2023


On Sun, 12 Feb 2023 03:53:02 GMT, Vicente Romero <vromero at openjdk.org> wrote:

> the following incorrect code is crashing javac:
> 
> public class X {
>   interface F {
>     void apply(E e);
>   }
>   enum E {
>     ONE
>   }
> 
>   F f = (E.ONE) -> {};   // E.ONE?
> }
> 
> there are several issues the incorrect argument to this lambda expression. The proposed solution is to issue a syntax error for the missing parameter name. IMO, this error message would be correct here and this way the compiler fails fast instead of having to deal with an erroneous lambda later on to avoid a crash like the one we have now,
> 
> TIA

src/jdk.compiler/share/classes/com/sun/tools/javac/parser/JavacParser.java line 3726:

> 3724:                 if (pn.hasTag(Tag.IDENT) && ((JCIdent)pn).name != names._this) {
> 3725:                     name = ((JCIdent)pn).name;
> 3726:                 } else if (lambdaParameter) {

I wonder if we could help the error recovery a little bit more, like e.g.:

                } else if (lambdaParameter && type == null) {
                    // we have a lambda parameter that is not an identifier this is a syntax error
                    type = pn;
                    name = names.empty;
                    reportSyntaxError(pos, Errors.Expected(IDENTIFIER));
                } else {


Which would keep the parsed thing as a type for the lambda parameter?

-------------

PR: https://git.openjdk.org/jdk/pull/12523


More information about the compiler-dev mailing list