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 210462 - Inspect & Transform cannot apply "strings using ==" hint in desired way
Summary: Inspect & Transform cannot apply "strings using ==" hint in desired way
Status: NEW
Alias: None
Product: java
Classification: Unclassified
Component: Hints (show other bugs)
Version: 7.2
Hardware: PC Linux
: P3 normal (vote)
Assignee: Svata Dedic
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-03-30 19:36 UTC by Jesse Glick
Modified: 2013-09-05 11:48 UTC (History)
0 users

See Also:
Issue Type: ENHANCEMENT
Exception Reporter:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jesse Glick 2012-03-30 19:36:38 UTC
If (in -source 6 code) you have

private static final String K1 = ...;
private static final String K2 = ...;
...
String k = ...; // known to be @NonNull
if (k == K1) {...}
else if (k == K2) {...}
..

and you want to switch to using equals() without a null check using Inspect & Transform, you cannot: the dialog warns that there are multiple fixes and it will just pick the first one. (Which is particularly stupid in this case because the suggested code compares string _constants_ to null!)

Disabling the option "Check for null using ternary conditional operator" in hint prefs does not help.
Comment 1 Jesse Glick 2012-03-30 19:37:17 UTC
Workaround is to manually accept second hint fix on each affected line.
Comment 2 Svata Dedic 2013-09-05 11:48:16 UTC
Could be improved, but only in limited cases, i.e. one side of the comparison is either a literal, or a final reference variable with an initializer. Definite assingment rules could be added, but I am not sure it cover enough cases to weight out the complexity.

Could also work with @NonNull etc annotations (configurable in some other hint)