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 234134 - [Replace with StringBuilder] Hint removes user comment
Summary: [Replace with StringBuilder] Hint removes user comment
Status: VERIFIED FIXED
Alias: None
Product: java
Classification: Unclassified
Component: Hints (show other bugs)
Version: 7.4
Hardware: PC Windows 7
: P2 normal (vote)
Assignee: Svata Dedic
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-08-08 12:18 UTC by Jiri Prox
Modified: 2014-03-26 17:07 UTC (History)
2 users (show)

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 Jiri Prox 2013-08-08 12:18:37 UTC
Replace with StringBuilder hint removes user inline comment

Steps to reproduce:
1) have a code:
StringBuffer s = new StringBuffer(x);  //Hint: Replace with StringBuilder

2) apply hint

StringBuilder s = new StringBuilder(x);  

-> comment is removed



Product Version: NetBeans IDE Dev (Build 201308042300)
Java: 1.8.0-ea; Java HotSpot(TM) 64-Bit Server VM 25.0-b40
Runtime: Java(TM) SE Runtime Environment 1.8.0-ea-b98
System: Windows 7 version 6.1 running on amd64; Cp1250; en_US (nb)
User directory: C:\Users\jprox\AppData\Roaming\NetBeans\dev
Cache directory: C:\Users\jprox\AppData\Local\NetBeans\Cache\dev
Comment 1 Svata Dedic 2013-11-25 15:29:41 UTC
Uses RewriteFix. Fixed in http://hg.netbeans.org/jet-main/rev/c6f518969ecb
Comment 2 Jiri Prox 2013-12-03 14:37:55 UTC
Unfortunately I can still reproduce this problem. But now it happens only sometimes (about 50%). 

I guess it happens after another change in editor (e.g. user types and the quickly invokes the hint), but I have no reliable steps.


Product Version: NetBeans IDE Dev (Build 20131202-95d36d354e99)
Updates: Updates available
Java: 1.8.0-ea; Java HotSpot(TM) 64-Bit Server VM 25.0-b49
Runtime: Java(TM) SE Runtime Environment 1.8.0-ea-b107
System: Windows 7 version 6.1 running on amd64; Cp1250; en_US (nb)
User directory: C:\Users\jprox\AppData\Roaming\NetBeans\dev
Cache directory: C:\Users\jprox\AppData\Local\NetBeans\Cache\dev
Comment 3 Svata Dedic 2013-12-04 13:30:39 UTC
The reason for randomness of the defect is that Trees to be rewritten are put into IdentityHashMap; the Map is then iterated and in each iteration one place is rewritten with the replacement. The Fix implementation records a replacement of the matched Tree with the template, then records replacements of individual placeholders in the template.

When iterating and doing actual replace AND copying comments, the original order of incremental rewrites is not preserved, so it may be possible that a comment is copied out of a newly created Tree 'x' earlier than the x rewrites original Tree absorbing its comments. 

The iteration order depends on object identity (assuming memory location) and is unpredictable. This potentially affects more refactorings that use JavaFixUtilities.rewriteFix, so the priority should be increased - but only comments are affected. As all the rewrites are collected and processed at the end, code output should be always the same.

Should be fixed by http://hg.netbeans.org/jet-main/rev/8c4e76914f62
Comment 4 Jiri Prox 2013-12-05 09:47:48 UTC
verified in trunk
Comment 5 Quality Engineering 2013-12-08 02:14:30 UTC
Integrated into 'main-silver', will be available in build *201312080002* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress)

Changeset: http://hg.netbeans.org/main-silver/rev/8c4e76914f62
User: Svata Dedic <sdedic@netbeans.org>
Log: #234134: rewrites are ordered so that comment propagate to the surviving Trees
Comment 6 Svata Dedic 2013-12-13 13:26:24 UTC
Grafted into 7.4 as #a074fb70b808
Comment 7 Quality Engineering 2014-03-26 17:07:48 UTC
Integrated into 'releases/release74', will be available in build *201403261440* or newer. Wait for official and publicly available build.

Changeset: http://hg.netbeans.org/releases/rev/4d90f068f418
User: Svata Dedic <sdedic@netbeans.org>
Log: #237313, #234134: rewrite fix preserves comments for (only!) the replaced nodes