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 247578 - when netbeans restores opened files they are opened using environment encoding
Summary: when netbeans restores opened files they are opened using environment encoding
Status: REOPENED
Alias: None
Product: projects
Classification: Unclassified
Component: Generic Infrastructure (show other bugs)
Version: 8.0.1
Hardware: PC Windows 8 x64
: P3 normal (vote)
Assignee: Tomas Stupka
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-09-30 06:35 UTC by gameshas
Modified: 2016-07-10 19:22 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 gameshas 2014-09-30 06:35:54 UTC
When netbeans crashes or killed, it restores opened files, and they are opened not using project encoding (utf-8) but environment encoding cp1257 on windows, which leads to corruption of texts with urf-8 characters.

You can reproduce this, by opening a utf-8 encoded file, and then from task manager selecting Kill process tree, then launch netbeans, it will restore the files and text will be garbled. 

Sometimes netbeans even shows a warning that the file cannot bet opened using windows-1257 encoding, although project's encoding is different.

Product Version: NetBeans IDE 8.0.1 (Build 201408251540)
Java: 1.8.0_20; Java HotSpot(TM) 64-Bit Server VM 25.20-b23
Runtime: Java(TM) SE Runtime Environment 1.8.0_20-b26
System: Windows 8 version 6.2 running on amd64; Cp1257; en_GB (nb)
User directory: C:\Users\jusurb\AppData\Roaming\NetBeans\8.0.1
Cache directory: C:\Users\jusurb\AppData\Local\NetBeans\Cache\8.0.1
Comment 1 Marian Petras 2014-12-05 08:41:33 UTC
Bug #248599 ("Editor opens UTF-8 files in wrong encoding (causing data loss)") seems to be related to this one.
Comment 2 Svata Dedic 2015-03-23 13:45:28 UTC
NB maintains a cross-reference of projects owning file(s) outside the project directory. That cross-reference is saved upon IDE's [regular] exit, so in a case of crash/kill, the data is not saved at all.

During the startup, the IDE simply does not know what project the opened file belongs to - unless that project opens.
Comment 3 Vladimir Voskresensky 2015-03-23 13:53:04 UTC
Svata, possible improvement could be to store last seen encoding associated with file. So, when files are reopened on IDE restart we don't use default encoding, but saved one.
Comment 4 Vladimir Voskresensky 2015-03-23 13:55:20 UTC
btw, isn't this bug is dup of P1 https://netbeans.org/bugzilla/show_bug.cgi?id=248599?
Comment 5 Svata Dedic 2015-03-23 13:57:54 UTC
(In reply to Vladimir Voskresensky from comment #4)
> btw, isn't this bug is dup of P1
> https://netbeans.org/bugzilla/show_bug.cgi?id=248599?

Not exactly; that one supposes regular exit+start, which saves the file>project cache. The code seems to contain a race I am going to fix.

This defect supposes crash/kill scenario, I think it should be handled separately - and possibly it's not even P1, since in the anomalous situation the user can simply reopen the file, or recover the good state from local history and/or VCS.
Comment 6 Svata Dedic 2015-03-23 14:08:20 UTC
Moving to projects -- there's a little what can be done on Editor's side:

a/ wait for all projects to load: access to all editors would be blocked during the "Opening projects..." sequence, which may be seen as a perf/usability issue.

b/ load documents using the best knowledge at the time, reload opened editors after all project load, or warn the user if the text has been alredy modified. Drawbacks: Documents are already loaded, might be programatically processed (and then saved broken). Probably requires an additional API.

c/ do not open any files after crash :)
Comment 7 Svata Dedic 2015-03-23 14:11:30 UTC
BTW - the real issue is that FileOwnerQuery provides bad results (= identifies a file as non-project) while projects are opening. Potentially more features than just encoding/loading editor are affected, but the results are not cached so firmly; i.e. parsing will produce correct results once the projects have been loaded and old parser.result is thrown away.
Comment 8 Martin Balin 2016-07-07 08:37:18 UTC
This old bug may not be relevant anymore. If you can still reproduce it in 8.2 development builds please reopen this issue.

Thanks for your cooperation,
NetBeans IDE 8.2 Release Boss
Comment 9 markiewb 2016-07-10 19:22:54 UTC
Still valid in 8.2 dev 
Product Version: NetBeans IDE Dev (Build 201607100002)