Community
Participate
Working Groups
I just fell over this one again: I wrote ... test= false; ... if (test); doSomething(); ... and was completely puzzled when my doSomething() was still executed. That one little semicolon after 'if (test)' is almost always an error and should therefore be flagged by the java compiler as warning (e.g. using the compiler setting for "Undocumented empty block").
Good suggestion. We should likely flag all undocumented empty statements which aren't unnecessary. e.g. if (b); else; while (b); for (;;);
Will reconsider post 3.0
Actually, will give it a try.
Created attachment 9347 [details] Warn when empty statement I believe this should catch all cases where an empty statement is caught. A superfluous semicolon will have preference when detected.
Michael: looking at the patch you produced; why did you check for the undocumented empty block bit in the case of an empty statement ? I will rather generate a different message if a useful (but scary) empty statement is detected. Will use the same severity as unnecessary semicolons.
Adding new problem message: Empty control-flow statement.
I guess one could argue that you should always display the message. Guess I wasn't thinking at the time when I did this. But thats what I am assuming your statement is getting at.
Fixed. Entered separate defect for JDT/UI to change the wording of the option (unnecessary semicolon).
Verified in 200405180816
*** Bug 28425 has been marked as a duplicate of this bug. ***