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 257103 - "Fix Imports" corrupts imports
Summary: "Fix Imports" corrupts imports
Status: REOPENED
Alias: None
Product: java
Classification: Unclassified
Component: Editor (show other bugs)
Version: 8.1
Hardware: PC Linux
: P3 normal (vote)
Assignee: Dusan Balek
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-12-10 17:06 UTC by mclaborn
Modified: 2017-06-30 15:48 UTC (History)
1 user (show)

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments
IDE log (275.54 KB, text/plain)
2015-12-10 17:06 UTC, mclaborn
Details
Before corruption (40.61 KB, image/png)
2016-10-12 14:36 UTC, mclaborn
Details
After corruption (37.11 KB, image/png)
2016-10-12 14:36 UTC, mclaborn
Details
Log file from today (822.32 KB, text/x-log)
2016-10-12 14:37 UTC, mclaborn
Details
hints on wrong line (22.39 KB, image/png)
2016-10-12 15:12 UTC, mclaborn
Details

Note You need to log in before you can comment on or make changes to this bug.
Description mclaborn 2015-12-10 17:06:40 UTC
Product Version = NetBeans IDE 8.1 (Build 201510222201)
Operating System = Linux version 3.13.0-71-generic running on amd64
Java; VM; Vendor = 1.8.0_51
Runtime = Java HotSpot(TM) 64-Bit Server VM 25.51-b03

Reproducibility: Happens sometimes, but not always

This happens occasionally. Can't reproduce at will. Once it starts happening in a given file, it continues to happen in that file until the file is closed and re-opened. 
Invoking the "Fix Imports" function really garbles up the imports.  Below is a before and after of one such occurrence. 

BEFORE:
import com.csc.mm.commonbase.MiscUtil;
import com.csc.mm.commonbase.StringUtil;
import com.csc.mm.commonjson.JSONArrayWrapper;
import com.csc.mm.commonjson.JSONAware;
import com.csc.mm.commonjson.JSONAwareList;
import com.csc.mm.commonjson.JSONWrapper2;
import com.mitchclaborn.hatcherymgr.common.cache.BreedCacheWeb;
import com.mitchclaborn.hatcherymgr.common.cache.ClientCustomerFlagDefCacheWeb;
import com.mitchclaborn.hatcherymgr.common.cache.ClientOptionCacheWeb;
import com.mitchclaborn.hatcherymgr.common.cache.ClientOrderDetailOptionCacheWeb;
import com.mitchclaborn.hatcherymgr.common.cache.CompanyCacheWeb;
import com.mitchclaborn.hatcherymgr.common.cache.HatchEventCacheWeb;
import com.mitchclaborn.hatcherymgr.common.cache.OperatorCacheWeb;
import com.mitchclaborn.hatcherymgr.common.cache.PartnerCacheWeb;
import com.mitchclaborn.hatcherymgr.common.cache.PricingTypeCacheWeb;
import com.mitchclaborn.hatcherymgr.common.cache.ProductCacheWeb;
import com.mitchclaborn.hatcherymgr.common.cache.RouteCacheWeb;
import com.mitchclaborn.hatcherymgr.common.cache.SKUCacheWeb;
import com.mitchclaborn.hatcherymgr.common.cache.ShipMethodCacheWeb;
import com.mitchclaborn.hatcherymgr.common.cache.ShipRateTypeCacheWeb;
import com.mitchclaborn.hatcherymgr.common.cache.SKUTypeCacheWeb;
import com.mm.server.framework.lib.FrameworkGenericAction;
import com.mm.server.framework.lib.ServerFunctionException;
import java.math.BigInteger;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;



AFTER:
import com.csc.mm.FunctionResponse;
import com.csc.mm.commonbase.MiscUtil;
import com.csc.mm.commonbase.StringUtil;
import com.csc.mm.commonjson.JSONArrayWrapper;
import com.csc.mm.commonjson.JSONAware;
import com.csc.mm.commonjson.JSONAwareList;
import import com.mitchclaborn.gf.lib.Operator;
com.csc.mm.commonjson.JSONWrapper2;
import com.mitchclaborn.hatcherymgr.common.cache.BreedCacheWeb;
import com.mitchclaborn.hatcherymgr.common.cache.ClientCustomerFlagDefCacheWeb;
import com.mitchclaborn.hatcherymgr.common.cache.ClientOptionCacheWeb;
import com.mitchclaborn.hatcherymgr.common.cache.ClientOrderDetailOptionCacheWeb;
import com.mitchclaborn.hatcherymgr.common.cache.CompanyCacheWeb;
import com.mitchclaborn.hatcherymgr.common.cache.HatchEventCacheWeb;
import com.mitchclaborn.hatcherymgr.common.cache.OperatorCacheWeb;
import com.mitchclaborn.hatcherymgr.common.cache.PartnerCacheWeb;
import com.mitchclaborn.hatcherymgr.common.cache.PricingTypeCacheWeb;
import com.mitchclaborn.hatcherymgr.common.cache.ProductCacheWeb;
import com.mitchclaborn.hatcherymgr.common.cache.RouteCacheWeb;
import com.mitchclaborn.hatcherymgr.common.cache.SKUCacheWeb;
import com.mitchclaborn.hatcherymgr.common.cache.ShipMethodCacheWeb;
import com.mitchclaborn.hatcherymgr.common.cache.ShipRateTypimport com.mitchclaborn.hatcherymgr.common.util.ServerCall;
eCacheWeb;
import com.mitchclaborn.hatcherymgr.common.cache.SKUTypeCacheWeb;
import com.mm.server.framework.lib.FrameworkGenericAction;
import com.mm.server.framework.lib.ServerFunctionException;
import java.math.BigInteger;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
Comment 1 mclaborn 2015-12-10 17:06:45 UTC
Created attachment 157752 [details]
IDE log
Comment 2 Svata Dedic 2016-04-25 14:50:51 UTC
Could not reproduce, sorry.
Comment 3 mclaborn 2016-04-25 15:05:53 UTC
I can't reproduce it either, but it still happens to me 2 - 3 times per week.  
Is there some additional logging that can be enabled to help track this down? 
Or maybe something I should look for in the IDE log?
Comment 4 Svata Dedic 2016-04-26 06:25:22 UTC
When you notice the source became corrupted, undo the operation, *save* the file and retry the operation. If you 'succeed' in corrupting the file again, close the file (reverting the fix import changes to the saved prev state), open again and Fix Imports again. In case you succeed, please attach or send me the file contents before the 'corrupting' operation.
Comment 5 Svata Dedic 2016-07-01 15:59:10 UTC
No response for 2 months, closing as WFM
Comment 6 mclaborn 2016-10-12 14:35:57 UTC
This has continued to be a problem for me, now in 8.2.

I have reproduced the problem as you requested. I prefer not to attach the source file here. Please provide email address and I'll send it directly.
Comment 7 mclaborn 2016-10-12 14:36:22 UTC
Created attachment 162471 [details]
Before corruption
Comment 8 mclaborn 2016-10-12 14:36:40 UTC
Created attachment 162472 [details]
After corruption
Comment 9 mclaborn 2016-10-12 14:37:22 UTC
Created attachment 162473 [details]
Log file from today
Comment 10 mclaborn 2016-10-12 14:37:57 UTC
Note to self: DialogBoxAllocationsForOrder.java
Comment 11 Svata Dedic 2016-10-12 14:39:34 UTC
You can safely use sdedic@netbeans.org alias
Comment 12 mclaborn 2016-10-12 14:49:56 UTC
File sent.
Comment 13 mclaborn 2016-10-12 15:12:48 UTC
Created attachment 162474 [details]
hints on wrong line

Not sure if this helps, but the whole file is just acting weird.  I had problems doing some "introduce constant" refactoring.  Here is a screen shot where the hint icon is not showing on the correct line. Acts like the line numbers are somehow out of sync with the contents??
Comment 14 Svata Dedic 2016-11-09 15:35:39 UTC
I couldn't reproduce the scenario. Perhaps I need an isolated sample. BUT the corruption look as if the first import, "com.csc.mm.FunctionResponse" was inserted, THEN the next import change was computed using an obsoleted CompilationInfo - which can happen, if, for example, a change is committed between the modification task end and modification result commit. Unlikely, but can happen.

Modifications which are done in WORKER thread are OK - it has throughput 1, so parse+commit pairs are serialized. 

But I found a suspicious code in JavaFixAllImports, lines 172-182: this modification is spinned off to some uncontrolled thread (not EDT, nor WORKER) in parallel with displaying the dialog so WORKER and this runOffEDT guardedCommits() can be interleaved.

Dusane - please advise: does the code try to commit partial (non-ambiguous) changes while the dialog shows all changes for confirmation ?
Comment 15 mclaborn 2017-02-07 18:03:16 UTC
I'm fairly certain that 256526, 257103 and 267242 all have the same root cause. There is some action I do regularly that messes up some internal table of line numbers in the Java source file with what is actually present in the editor. (My hypothesis.) Once in this state, Fix Imports, refactoring and error/hint icons are all messed up.  Closing the file and reopening it usually fixes the problem. 

How can I go about capturing what is needed to catch this?
Comment 16 mclaborn 2017-06-30 15:47:35 UTC
See my previous comment. I'm fairly certain that some kind of line number mismatch or out-of-sync problem is behind all these: 267242, 257103, 267282, 267308. 

Just a few minutes ago, I pasted in a large block of code that also had some associated imports. A large number of import statements got corrupted and fix imports made it worse. I deleted the corrupted lines, closed the file, reopened the file then fix imports worked just fine. 

How can I capture debugging information to help figure this out?