This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 259071 - Enumerations switch hint
Summary: Enumerations switch hint
Status: RESOLVED FIXED
Alias: None
Product: java
Classification: Unclassified
Component: Hints (show other bugs)
Version: 8.1
Hardware: PC Windows 10
: P3 normal (vote)
Assignee: Svata Dedic
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-04-30 08:07 UTC by henri127
Modified: 2016-05-07 01:59 UTC (History)
0 users

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description henri127 2016-04-30 08:07:11 UTC
Product Version = NetBeans IDE 8.1 (Build 201510222201)
Operating System = Windows 10 version 10.0 running on amd64
Java; VM; Vendor = 1.8.0_72
Runtime = Java HotSpot(TM) 64-Bit Server VM 25.72-b15

Reproducibility: Happens every time

STEPS:
  * Open dialog Foo
  * Click on button "Click me"

ACTUAL:
  nothing happens

EXPECTED:
  message pops up

Assume an enumeration

public enumeration testEnum{
	ONE,
	TWO,
	THREE;
}

Assume a method in some class

public String toString(testEnum t) {
	String s;
	if (t == testEnum.ONE) {
		s = "1";
	} else if (t == testEnum.TWO) {
		s = "2";
	} else {
		s = "3";
	}
	return "number is " + s;
}

On the first if statement a hint is given "replace chain of ifs with switch".
Applying this hint will give:

public String toString(testEnum t) {
	String s;
	if (null != t) switch (t) {
		case ONE:
			s = "1";
		case TWO:
			s = "2";
		default:
			s = "3";
	}
	return "number is " + s;
}

First of all now suddenly an error appears in the code because s might not have been initialized. Apart from that, why is there a need for the additional null != t check, because whenever in the initial code
t would be null on entry of the toString function the default switch case/label would have been applied or am I wrong?
Comment 1 Svata Dedic 2016-05-05 12:57:08 UTC
Will be fixed by jet-main#92ded844705a
Comment 2 Svata Dedic 2016-05-05 16:13:30 UTC
Correction: the fix changeset is: jet-main#aa6dec4f79fe
Comment 3 Quality Engineering 2016-05-07 01:59:49 UTC
Integrated into 'main-silver', will be available in build *201605070002* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress)

Changeset: http://hg.netbeans.org/main-silver/rev/92ded844705a
User: Svata Dedic <sdedic@netbeans.org>
Log: #259071: Do not produce any fixes if thrown exceptions are not subclass of caught ones (errorenous sources))