RFR: 8305671: javac rejects semicolons in compilation units with no imports [v2]

Jonathan Gibbons jjg at openjdk.org
Tue Apr 18 04:00:44 UTC 2023


On Tue, 18 Apr 2023 03:36:14 GMT, Jonathan Gibbons <jjg at openjdk.org> wrote:

>> I'd rather not mess with it because the existing code is already a customized (i.e., not a straightforward parse) so that it can provide a more helpful error message when duplicate semicolons are found after import statements. See [JDK-8027682](https://bugs.openjdk.org/browse/JDK-8027682) and PR #12448. Doing what you suggest would probably be more straightforward but would risk breaking that.
>
>> Doing what you suggest would probably be more straightforward
> 
> "More straightforward" is the right long term solution for the code.  The proposed patch is obscure and will confuse future developers working on this part of the code.
> 
>> but would risk breaking that.
> 
> You now have tests to ensure you don't break that.
> 
> The previous round of fix was inadequate, for not handling the case of no import statements. It is reasonable to (re)consider the logic for that part of the code.  And, it is reasonable to ensure the set of test cases covers all places where multiple semicolons are bad.

Isn't the logic just

* after a package declaration or import declaration, read and save excess semicolons
* before an import statement, check there are no saved excess semicolons and report if there were any
* (ignore any saved excess semicolons when you encounter the first type declaration (if any) or EOF)

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

PR Review Comment: https://git.openjdk.org/jdk/pull/13361#discussion_r1169462685


More information about the compiler-dev mailing list