This morning, after doing a git refresh, IntelliJ complained that my project wasn't compiling clean any more. The culprit:
import javax.naming.Context;;
IntelliJ complains:
Error:(33, 29) java: Syntax error on token ";", delete this token
That code was pushed by a person who is not using IntelliJ, and it passed our backend build.
Question: is javac at fault, or IntelliJ? And what would be the document/spec that clarifies whether the above code should be an error or a warning?
This is IntelliJ 2019.2 CE EAP, running on MacOs.
And just to be precise: there seems to be a mismatch between the IntelliJ "editor compile", and the result of hitting the "build" action. Fun fact: we have "use eclipse compiler" in our project setup. Changing it that to use javac fixes the problem, the double ;; is just a warning then.
Unnecessary semicolons are not an error. They are considered as empty statements. And an empty statement, which does nothing, is not an error.
Cross check your code. It might also be IntelliJ at fault too. Its linting service might not be considering it as a legal statement.
The question is similar to this
Edit 1: The IntelliJ has an option in it's settings to which posts redundant semicolons as error.
According to the Java Language Specification §7.6 ;
is a valid Type Declaration:
A top level type declaration declares a top level class type (§8 (Classes)) or a top level interface type (§9 (Interfaces)).
TypeDeclaration:
- ClassDeclaration
- InterfaceDeclaration
- ;
Extra ";" tokens appearing at the level of type declarations in a compilation unit have no effect on the meaning of the compilation unit. Stray semicolons are permitted in the Java programming language solely as a concession to C++ programmers who are used to placing ";" after a class declaration. They should not be used in new Java code.
If there is no setting in InteliJ that would change this behavior, then the extra semicolon should not produce an error.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With