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.
Summary: | Convert "ifs" to "switch" incorrectly generated code | ||
---|---|---|---|
Product: | java | Reporter: | ibeaumont <ibeaumont> |
Component: | Hints | Assignee: | Svata Dedic <sdedic> |
Status: | RESOLVED FIXED | ||
Severity: | normal | CC: | ibeaumont |
Priority: | P2 | ||
Version: | 8.1 | ||
Hardware: | PC | ||
OS: | Windows 8.1 | ||
Issue Type: | DEFECT | Exception Reporter: |
Description
ibeaumont
2016-05-20 14:57:07 UTC
Couldn't you prepare some fragment of code to test ? I've tried an +- equivalent structure in dev trunk and it seems to work, although the break (which is missing in your case) is wrongly indented. Ok, here is simplified test that shows the problem. package test; import java.util.ArrayList; import java.util.List; import java.util.Map; public class FormatIssue { public enum Day { SUNDAY, MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY } public class DayHolder { Day day; Day getDay() { return day; } } public void test(Map<Integer, Day> evaluateExpressions) throws Exception { List<DayHolder> params = new ArrayList<>(); for (int i = 0; i < params.size(); i++) { DayHolder p = params.get(i); if (evaluateExpressions.get(i) != null) { if (evaluateExpressions.get(i) == Day.SUNDAY) { // Do something 1 } else if (evaluateExpressions.get(i) == Day.MONDAY) { switch (p.getDay()) { case SUNDAY: break; default: throw new Exception("xxx"); } } else if (evaluateExpressions.get(i) == Day.TUESDAY) { // Do something 2 } } } } } Great thanks for the example. The issue is a little more serious just that one hint - the IDE's idea of whether the execution escapes (throws, returns or breaks out to an outer statement) from a given piece of code produces incorrect results. Possibly affects refactoring or other hints. Fixed in jet-main#56de4b373b04 Integrated into 'main-silver', will be available in build *201605260002* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress) Changeset: http://hg.netbeans.org/main-silver/rev/56de4b373b04 User: Svata Dedic <sdedic@netbeans.org> Log: #262167: fixed bad escape analysis causing if-to-switch not generate break. Added testcases |