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 252576 - Convert to switch for one condition is useless
Summary: Convert to switch for one condition is useless
Status: VERIFIED FIXED
Alias: None
Product: java
Classification: Unclassified
Component: Hints (show other bugs)
Version: 8.1
Hardware: PC Windows 7
: P3 normal (vote)
Assignee: Svata Dedic
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-05-25 15:47 UTC by cezariusz
Modified: 2015-07-27 08:35 UTC (History)
1 user (show)

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments
Convert to switch hint (7.22 KB, image/png)
2015-05-25 15:48 UTC, cezariusz
Details

Note You need to log in before you can comment on or make changes to this bug.
Description cezariusz 2015-05-25 15:47:11 UTC
Product Version: NetBeans IDE Dev (Build 201505220001)
Java: 1.8.0_45; Java HotSpot(TM) 64-Bit Server VM 25.45-b02
Runtime: Java(TM) SE Runtime Environment 1.8.0_45-b14
System: Windows 7 version 6.1 running on amd64; UTF-8; pl_PL (nb)

Consider the following code:

public class IfToCase {

    public boolean isAbc(String val) {
        if (val.equals("abc")) {
            return true;
        } else {
            return false;
        }
    }
}

There is a warning hint to convert to switch over strings, which is useless for a single condition.
The description says: "Marks cascades of ifs which can be converted to switch over Strings" - but there is no cascade of ifs, it's a single if. The hint should be offered only when there are at least two conditions (or make it configurable at the Hints page).
Comment 1 cezariusz 2015-05-25 15:48:51 UTC
Created attachment 153849 [details]
Convert to switch hint
Comment 2 Svata Dedic 2015-06-02 11:38:43 UTC
Fixed as jet-main#675772c51bd5
Comment 3 Quality Engineering 2015-06-05 02:39:22 UTC
Integrated into 'main-silver', will be available in build *201506050001* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress)

Changeset: http://hg.netbeans.org/main-silver/rev/675772c51bd5
User: Svata Dedic <sdedic@netbeans.org>
Log: #252576: added minimum threshold for string-to-switch. Unified with if-to-switch hint
Comment 4 cezariusz 2015-07-27 08:35:30 UTC
Verified with Build 201507240001.