Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 202384

Summary: can not reload text file encoding prefs
Product: [Eclipse Project] Platform Reporter: Vloa Jen <frfrw32>
Component: ResourcesAssignee: Szymon Ptaszkiewicz <sptaszkiewicz>
Status: RESOLVED FIXED QA Contact:
Severity: normal    
Priority: P5 CC: daniel_megert, dj.houghton, eclipse, jgarms, krzysztof.michalski, markus.kell.r, sptaszkiewicz, Szymon.Brandys
Version: 3.4Keywords: helpwanted
Target Milestone: 3.7 M5Flags: Szymon.Brandys: review+
Hardware: PC   
OS: Windows XP   
Whiteboard:
Bug Depends on:    
Bug Blocks: 334241, 335591    
Attachments:
Description Flags
Patch v.0.1
none
Patch v.0.2
none
Patch v.0.3, minor changes added
none
Patch v.0.4
none
Patch v.0.5
none
Patch v.0.6, rebased to HEAD
none
Patch v.0.6 changed
none
Patch v.0.7 Szymon.Brandys: iplog+

Description Vloa Jen CLA 2007-09-06 02:33:54 EDT
steps:
1. change the project "text file encoding"  to Other->UTF-8
2. close the project, then close eclipse
3. open eclipse, then open the project
4. the "text file encoding" setting reset to "Inherited from container (MS950)
Comment 1 Walter Harley CLA 2007-09-06 14:50:43 EDT
Bug was categorized as JDT/APT - I don't think it has anything to do with either.  I'll attempt to recategorize it.
Comment 2 Krzysztof Michalski CLA 2007-09-10 06:52:50 EDT
I can't reproduce it on Build id: I20070809-1105. Could you check if it still occurs on the newest version?
Comment 3 Vloa Jen CLA 2007-09-12 08:43:00 EDT
yes, i tried , it works fine.
And i was thinking about why it happened at that time...
finally i got the point:
if we have viewed the "text file encoding" property 
before opening the project (as step 3.),
after opened the project,
the encoding will reset to "Inherited from container (MS950)"
Comment 4 Szymon Brandys CLA 2007-09-17 07:59:58 EDT
I can reproduce the issue indeed. I'm changing the priority since the team has other issues to address. A patch would be accepted.
Comment 5 Szymon Ptaszkiewicz CLA 2010-12-14 07:29:02 EST
Created attachment 185125 [details]
Patch v.0.1

The problem is that ProjectPreferences are initialized only upon creation so changing open-close state of project cannot change already initialized preferences. What we should do is to initialize project preferences each time the project is opened. The attached patch solves the problem. There is still an issue with line delimiter but the preference for line delimiter is handled directly from UI so it needs a separate bug.

Szymon B., do you think we could fix this in 3.7 M5?
Comment 6 Szymon Ptaszkiewicz CLA 2010-12-14 09:50:09 EST
Created attachment 185134 [details]
Patch v.0.2

Patch that fixes problems with encoding and with line delimiter.
Comment 7 Szymon Ptaszkiewicz CLA 2010-12-14 10:15:46 EST
Created attachment 185139 [details]
Patch v.0.3, minor changes added
Comment 8 Szymon Ptaszkiewicz CLA 2010-12-17 09:27:30 EST
Created attachment 185424 [details]
Patch v.0.4
Comment 9 Szymon Ptaszkiewicz CLA 2010-12-20 09:36:58 EST
Created attachment 185543 [details]
Patch v.0.5
Comment 10 Szymon Brandys CLA 2010-12-21 20:38:25 EST
Szymon, could you sync the patch to HEAD?
Comment 11 Szymon Ptaszkiewicz CLA 2010-12-22 08:04:21 EST
Created attachment 185703 [details]
Patch v.0.6, rebased to HEAD
Comment 12 Szymon Brandys CLA 2010-12-22 10:59:35 EST
Created attachment 185720 [details]
Patch v.0.6 changed

If there are two (or more) threads accessing project prefs, each may create a ProjectPreferences instance and only one of these will be added to the preferences tree. I think there is a chance that a wrong instance will be initialized during project opening. 

My patch seems to be safer.
Comment 13 Szymon Brandys CLA 2010-12-22 11:01:07 EST
Dj, could you look at the 'patch v.0.6 (rebased to HEAD)' and 'patch v.0.6 changed' and comment.
Comment 14 Szymon Ptaszkiewicz CLA 2010-12-22 11:11:18 EST
I opened separate bug 333101 for UI part.
Comment 15 Szymon Brandys CLA 2010-12-22 12:17:26 EST
I found one more issue with ProjectPreferences. 

If a project is closed and LineDelimiterEditor tries to get preferences (it creates nodes during  look up), ProjectPreferences#load is called and silently returns, because the pref file is not accessible. Right after that ProjectPreferences#loaded is called and it adds core.runtime.prefs to the list of loaded nodes, what is wrong.

Of course the fix for bug 333101 hides the problem, however there may be other places where people create nodes on look up. #loaded should not add anything to loadedNodes if #load fails.
Comment 16 Szymon Ptaszkiewicz CLA 2011-01-10 06:42:36 EST
Created attachment 186377 [details]
Patch v.0.7

Added changes from comment 15.
Comment 17 Szymon Ptaszkiewicz CLA 2011-01-10 06:43:46 EST
*** Bug 162818 has been marked as a duplicate of this bug. ***
Comment 18 Szymon Brandys CLA 2011-01-11 05:36:24 EST
The fix is in HEAD. Thanks.
Comment 19 Dani Megert CLA 2011-01-14 05:14:42 EST
The bug is nicely fixed! There's one remaining issue though, see bug 334362.