Bug 52805 - [DCR] Compiler should warn when using if (test);
Summary: [DCR] Compiler should warn when using if (test);
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.0   Edit
Hardware: PC Windows XP
: P3 enhancement (vote)
Target Milestone: 3.0 M9   Edit
Assignee: Philipe Mulet CLA
QA Contact:
URL:
Whiteboard:
Keywords:
: 28425 (view as bug list)
Depends on:
Blocks:
 
Reported: 2004-02-23 06:17 EST by Markus Keller CLA
Modified: 2006-02-21 11:41 EST (History)
2 users (show)

See Also:


Attachments
Warn when empty statement (809 bytes, patch)
2004-04-08 23:53 EDT, Michael Fraenkel CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Markus Keller CLA 2004-02-23 06:17:27 EST
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").
Comment 1 Philipe Mulet CLA 2004-02-23 06:41:16 EST
Good suggestion. We should likely flag all undocumented empty statements which 
aren't unnecessary. 

e.g.  if (b); else;
      while (b);
      for (;;);
      
Comment 2 Philipe Mulet CLA 2004-03-25 06:44:01 EST
Will reconsider post 3.0
Comment 3 Philipe Mulet CLA 2004-03-25 06:45:48 EST
Actually, will give it a try.
Comment 4 Michael Fraenkel CLA 2004-04-08 23:53:50 EDT
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.
Comment 5 Philipe Mulet CLA 2004-04-26 11:07:45 EDT
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.
Comment 6 Philipe Mulet CLA 2004-04-26 11:49:43 EDT
Adding new problem message: Empty control-flow statement.
Comment 7 Michael Fraenkel CLA 2004-04-26 23:43:12 EDT
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.
Comment 8 Philipe Mulet CLA 2004-04-27 16:41:40 EDT
Fixed. Entered separate defect for JDT/UI to change the wording of the option 
(unnecessary semicolon).
Comment 9 Olivier Thomann CLA 2004-05-18 13:46:55 EDT
Verified in 200405180816
Comment 10 Markus Keller CLA 2006-02-21 11:41:14 EST
*** Bug 28425 has been marked as a duplicate of this bug. ***