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 269774 - Hint "Replace StringBuffer/Builder by String" breaks code when StringBuilder-specific method is used
Summary: Hint "Replace StringBuffer/Builder by String" breaks code when StringBuilder-...
Status: RESOLVED FIXED
Alias: None
Product: java
Classification: Unclassified
Component: Hints (show other bugs)
Version: 8.1
Hardware: PC All
: P3 normal (vote)
Assignee: Svata Dedic
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-02-08 10:12 UTC by MCEmperor
Modified: 2017-03-16 02:50 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 MCEmperor 2017-02-08 10:12:20 UTC
PROBLEM

The "Replace StringBuffer/Builder by String" hint breaks some code, when a StringBuilder-specific method is used.

PROBLEM EXAMPLE

This snippet of code produces a hint to replace the StringBuilder with a String:

    String str = "Hello World!";
    StringBuilder sb = new StringBuilder(str);
    sb.deleteCharAt(5);

When the suggested replacement is applied, the snippet is changed to this:

    String str = "Hello World!";
    String sb = str;
    sb.deleteCharAt(5);

But then a compile error arises, because, of course, sb.deleteCharAt() doesn't exist.

SUGGESTED CHANGE

The hint should be suppressed when a StringBuilder-specific method is used.

FURTHER INFORMATION

This bug looks like bug #239082.

Here are my system details, however, I don't think they have something to do with the bug.

Product Version: NetBeans IDE 8.1 (Build 201510222201)
Updates: NetBeans IDE is updated to version NetBeans 8.1 Patch 1
Java: 1.8.0_74; Java HotSpot(TM) 64-Bit Server VM 25.74-b02
Runtime: Java(TM) SE Runtime Environment 1.8.0_74-b02
System: Windows 10 version 10.0 running on amd64; UTF-8; nl_NL (nb)
Comment 1 Svata Dedic 2017-02-08 10:40:49 UTC
This is a defect.
Comment 2 Svata Dedic 2017-03-09 14:26:13 UTC
The 'bad' method names are enumerated, and deleteChars was missing from the list. Fixed in jet-main#054c426c86d3
Comment 3 Quality Engineering 2017-03-16 02:50:46 UTC
Integrated into 'main-silver', will be available in build *201703160002* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress)

Changeset: http://hg.netbeans.org/main-silver/rev/054c426c86d3
User: Svata Dedic <sdedic@netbeans.org>
Log: #269774: added missing SBuilder mutating method