RFR: 8370865: Incorrect parser error for compact source files and multi-variable declarations

Jan Lahoda jlahoda at openjdk.org
Wed Oct 29 13:57:29 UTC 2025


Consider code like:

int f1, f2;
void main() {}


When javac's parser accepts `f1`, it sees `,`, but it won't parse this as top-level field declarations, failing with:

/tmp/F.java:1: error: class, interface, annotation type, enum, record, method or field expected
int f1, f2;
^
1 error


This PR changes the parser to also accept the `,` as the next token when parsing top-level fields.

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

Commit messages:
 - 8370865: Incorrect parser error for compact source files and multi-variable declarations

Changes: https://git.openjdk.org/jdk/pull/28044/files
  Webrev: https://webrevs.openjdk.org/?repo=jdk&pr=28044&range=00
  Issue: https://bugs.openjdk.org/browse/JDK-8370865
  Stats: 155 lines in 3 files changed: 153 ins; 0 del; 2 mod
  Patch: https://git.openjdk.org/jdk/pull/28044.diff
  Fetch: git fetch https://git.openjdk.org/jdk.git pull/28044/head:pull/28044

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


More information about the compiler-dev mailing list