History | Log In     View a printable version of the current page.  
Issue Details (XML | Word | Printable)

Key: IDEABKL-3367
Type: Bug Bug
Status: Open Open
Priority: Normal Normal
Assignee: Bas Leijdekkers
Reporter: Nikita
Votes: 1
Watchers: 1
Available Workflow Actions

Mark as Stalled
Operations

If you were logged in you would be able to see more operations.
IDEA: Backlog

"'defult' branch is unnecessary" inspection error

Created: 19 Jul 05 17:40   Updated: 23 Feb 07 22:43
Component/s: Code Analysis. Inspection
Affects Version/s: None
Fix Version/s: None

Original Estimate: Unknown Remaining Estimate: Unknown Time Spent: Unknown

Build: 3,408
Severity: Medium


 Description  « Hide
I have enum.. for example
enum Nums{
ONE,TWO,THREE;
}
And in code I use switch case ...
///////////////////
String result;
Nums var = <any varriable>;
switch(var){
case ONE: result = "111" break;
case TWO: result ="49756" break;
case THREE : result ="9384567" break;
default : result ="kdghsfg";
}
JLabel label=new JLabel(result);
/////////////
In this way ispector offered me to delete defult branch...
but if I delete it compiler error said that 'result' may have not been initialized.....

 All   Comments   Work Log   Change History      Sort Order:
Maxim Shafirov - 19 Jul 05 18:02
I'd rather say this is javac bug since default case is indeed unreachable.

Nikita - 19 Jul 05 18:08
But IDEA shows it as error too..

Maxim Shafirov - 19 Jul 05 18:27
Yep, because it's complaint with javac, in this case
-------------------
Maxim Shafirov
http://www.jetbrains.com
"Develop with pleasure!"

Nikita - 19 Jul 05 18:35
ok....
I have reported this bug on java.sun.com.....

Maxim Shafirov - 31 Jul 05 00:53
Yep, because it's complaint with javac, in this case
-------------------
Maxim Shafirov
http://www.jetbrains.com
"Develop with pleasure!"

Maxim Shafirov - 14 Dec 05 19:55
Yep, because it's complaint with javac, in this case
-------------------
Maxim Shafirov
http://www.jetbrains.com
"Develop with pleasure!"

Nathaniel Manista - 28 Jun 06 18:19
Using return statements instead of field assignments seems to be a variant form of this:

public final class DefaultBranchUnnecessary
{
public static int prioritize(final String[] args)
{
final Bird bird = Bird.valueOf(args[0]);
switch (bird)

{ case DUCK: return 3; case GOOSE: return 2; default: return 0; }

}

enum Bird { DUCK, GOOSE, }
}

What's the sun bug number?


Nikita - 07 Jul 06 16:59
I don't remember bug number((
I think it may not be not a bug... its a feature. In case if we will add one more element to the enum and then recompile ONLY enum class. after this JRE will may crash in switch because handler will not exist.

Maxim Shafirov - 27 Dec 06 21:40
Yep, because it's complaint with javac, in this case
-------------------
Maxim Shafirov
http://www.jetbrains.com
"Develop with pleasure!"

Nathaniel Manista - 23 Feb 07 22:43
It looks like the sun bug is #6398226, located here: http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6398226.