RFR: 8312204: unexpected else with statement causes compiler crash

Andrey Turbanov aturbanov at openjdk.org
Fri Aug 4 14:08:30 UTC 2023


On Mon, 31 Jul 2023 08:43:28 GMT, Jan Lahoda <jlahoda at openjdk.org> wrote:

> Compiling (erroneous) code like:
> 
> void main() {
>     else ;
> }
> 
> 
> Leads to:
> 
> $ javac --enable-preview -source 22 /tmp/Test.java 
> An exception has occurred in the compiler (22-internal). Please file a bug against the Java compiler via the Java bug reporting page (https://bugreport.java.com) after checking the Bug Database (https://bugs.java.com) for duplicates. Include your program, the following diagnostic, and the parameters passed to the Java compiler in your report. Thank you.
> java.lang.AssertionError
>         at jdk.compiler/com.sun.tools.javac.parser.VirtualParser$VirtualScanner.errPos(VirtualParser.java:151)
>         at jdk.compiler/com.sun.tools.javac.parser.JavacParser.doRecover(JavacParser.java:3122)
> ...
> 
> 
> The proposed solution is to implement the two corresponding `errPos` methods for `VirtualScanner`.

test/langtools/tools/javac/parser/JavacParserTest.java line 2481:

> 2479: 
> 2480:         for (Diagnostic<? extends JavaFileObject> d : coll.getDiagnostics()) {
> 2481:             codes.add(d.getLineNumber() + ":" + d.getColumnNumber() + ":" +  d.getCode());

Suggestion:

            codes.add(d.getLineNumber() + ":" + d.getColumnNumber() + ":" + d.getCode());

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

PR Review Comment: https://git.openjdk.org/jdk/pull/15086#discussion_r1284469551


More information about the compiler-dev mailing list