Bug 319378 - Preferences->Java Compiler-> Errors/Warnings -> switch case fall through enhancement
Summary: Preferences->Java Compiler-> Errors/Warnings -> switch case fall through enha...
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Doc (show other bugs)
Version: 3.7   Edit
Hardware: PC Windows XP
: P3 enhancement (vote)
Target Milestone: 3.6.1   Edit
Assignee: Olivier Thomann CLA
QA Contact:
URL:
Whiteboard:
Keywords: Documentation
Depends on:
Blocks:
 
Reported: 2010-07-09 08:54 EDT by Daniel Holmes CLA
Modified: 2010-08-27 03:44 EDT (History)
3 users (show)

See Also:


Attachments
Proposed fix (1.06 KB, patch)
2010-07-19 13:24 EDT, Olivier Thomann CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Daniel Holmes CLA 2010-07-09 08:54:12 EDT
Build Identifier: 20100218-1602

The description for this rules reads "When enabled, the compiler will issue an error or a warning whenever it encounters a switch case without a 'break' statement. Empty switch cases are allowed."

I have created similar with a PMD rule, but it seems that it is not just a break that should be allowed in a case.  A case should be able to have a final statement of a continue (explicit intent to fall through), return or throw (which would also not create an inadvertent fall through).  It would be nice if this rule were expanded for these conditions.

Reproducible: Always
Comment 1 Olivier Thomann CLA 2010-07-15 11:13:26 EDT
I don't see what you expect from us. Updating the description ?
If you have a return, throw or continue, the next statement is not reachable so it is not a fallthrough case.
Did I misunderstand something ?
Comment 2 Daniel Holmes CLA 2010-07-15 11:45:07 EDT
I guess from the description, it was not clear until I tried it that the 'break' as mentioned in the description was inclusive of a case exiting due to return or throw conditions vs just specifically a break statement.  

So I guess the rule does cover this condition and maybe the documentation could be more inclusive of this.

Also, did not realize until I just tested it that continue is not allowed in a switch case construct.  I was taking the word of a co-worker on this :-)
Comment 3 Olivier Thomann CLA 2010-07-15 11:52:50 EDT
You can use continue to a label depending on the context. So you expect the description to be improved ?
Comment 4 Daniel Holmes CLA 2010-07-15 12:00:29 EDT
Yes, I'm suggesting to clarify the description.

I understand your point on continue also is the switch happens to be in a loop.
Comment 5 Olivier Thomann CLA 2010-07-19 09:58:56 EDT
Hi Daniel,

> The description for this rules reads "When enabled, the compiler will issue an
> error or a warning whenever it encounters a switch case without a 'break'
> statement. Empty switch cases are allowed."
Are you referring to the description found in:
org.eclipse.jdt.doc.user/reference/preferences/java/compiler/ref-preferences-errors-warnings.htm ?

In the help, I also found this in JDT/Core options:

"When enabled, the compiler will issue an error or a warning when a case may be entered by falling through a preceding, non empty case."

That seems to be better, doesn't it ?
Comment 6 Daniel Holmes CLA 2010-07-19 11:16:18 EDT
(In reply to comment #5)
Yes, I like that.
Comment 7 Olivier Thomann CLA 2010-07-19 13:15:02 EDT
Released for 3.7M1 and 3.6.1.
Comment 8 Olivier Thomann CLA 2010-07-19 13:24:26 EDT
Created attachment 174651 [details]
Proposed fix
Comment 9 Dani Megert CLA 2010-08-27 03:44:18 EDT
Verified in M20100825-0800.