Double-semicolon in import statements

Alex Buckley alex.buckley at
Thu Aug 1 10:49:07 PDT 2013

Hi Jeremy,

; is a valid TypeDeclaration in JLS 7.6. Since TypeDeclaration's follow 
ImportDeclaration's in CompilationUnit in JLS 7.3, it is legal to have a 
; immediately after the ; of the import declaration.

The rationale for ; being a TypeDeclaration is found in the JLS First 
Edition but was removed in the Second Edition. Here we are, 13 years 
after the Second Edition was published, and the ; is causing confusion. 
This shows that language design is _forever_. I will add the rationale 
back into the JLS.


On 8/1/2013 10:12 AM, Jeremy Manson wrote:
> Hi folks,
> Another one that came up was that javac allows an empty statement
> between import statements.  This doesn't *seem* to be allowed by the
> JLS's grammar (JLS 7.5), so it should probably either be clarified in
> the JLS or fixed.  Example:
> import java.util.HashMap;;
> public class Semicolon {
>    public static void main(String[] args) {
>       System.out.println("This program should not compile");
>    }
> }
> compiles.
> Jeremy

More information about the compiler-dev mailing list