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 239465

Summary: “String.indexOf can be replaced with String.contains” poor advice on char arguments
Product: java Reporter: Jesse Glick <jglick>
Component: HintsAssignee: Svata Dedic <sdedic>
Status: RESOLVED FIXED    
Severity: normal    
Priority: P3    
Version: 8.0   
Hardware: PC   
OS: Linux   
Issue Type: DEFECT Exception Reporter:

Description Jesse Glick 2013-12-13 12:58:02 UTC
Product Version = NetBeans IDE Dev (Build 20131211-ca7d20f516e1)
Operating System = Linux version 3.8.0-34-generic running on i386
Java; VM; Vendor = 1.7.0_45
Runtime = Java HotSpot(TM) Client VM 24.45-b08

String url = …;
boolean hasQueryParam = url.indexOf('?') >= 0;

The IDE warned me about this line. I accepted the hint to convert it, which produced

boolean hasQueryParam = url.contains('?');

which does not compile.

boolean hasQueryParam = url.contains("?");

does compile, but this is not a great replacement since it is slower (I suppose) than the original; for some code that may be an acceptable tradeoff for better readability, but such a hint should then not be shown by default as a warning.
Comment 1 Svata Dedic 2014-01-24 18:07:24 UTC
Constrained to indexOf(String) in jet-main#89b9ce525c90
Comment 2 Quality Engineering 2014-01-31 02:40:17 UTC
Integrated into 'main-silver', will be available in build *201401310001* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress)

Changeset: http://hg.netbeans.org/main-silver/rev/89b9ce525c90
User: Svata Dedic <sdedic@netbeans.org>
Log: #239465: constrained to just indexOf(String)