Bug 208609 - Bug in ErrorRecoveryLog.getLocalRandomIdentifier(String path)
Summary: Bug in ErrorRecoveryLog.getLocalRandomIdentifier(String path)
Status: RESOLVED FIXED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: Update (deprecated - use Eclipse>Equinox>p2) (show other bugs)
Version: 3.3   Edit
Hardware: PC Windows XP
: P3 blocker with 3 votes (vote)
Target Milestone: 3.4.1   Edit
Assignee: Andrew Niefer CLA
QA Contact:
URL:
Whiteboard:
Keywords: contributed
Depends on:
Blocks:
 
Reported: 2007-11-02 15:27 EDT by Stephan Merker CLA
Modified: 2008-07-14 15:11 EDT (History)
7 users (show)

See Also:


Attachments
Test program to reproduce the bug (4.28 KB, application/octet-stream)
2007-11-02 15:27 EDT, Stephan Merker CLA
no flags Details
Patch for bug in ErrorRecoveryLog.java (665 bytes, patch)
2007-11-22 12:48 EST, Stephan Merker CLA
aniefer: iplog+
Details | Diff
JUnit test case (1.51 KB, patch)
2008-02-04 13:43 EST, Wayne Beaton CLA
aniefer: iplog+
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Stephan Merker CLA 2007-11-02 15:27:29 EDT
Created attachment 81993 [details]
Test program to reproduce the bug

Build ID: 3.3.0 but also on 3.3.1

Steps To Reproduce:
The bug leads to failed installations of WTP using the update manager on VMWare Images on fast machines with lower clock resolution (15ms instead of 10ms). It may also happen on fast PCs but I have never seen this happen.

It is hard to reproduce, therefore I created a test program by copying the source code of the method from the plugin org.eclipse.update.core.

1. Run the attached test program (add to simple Java project)
2. It prints out 'failed to create file' messages for the org. version of getLocalRandomIdentifier()
3. It doesn't print out 'failed to create file' messages for the fixed version of getLocalRandomIdentifier()
4. In the temp. dir UpdMgrTest you don't find 10 feature.xml files
5. In the temp. dir UpdMgrTestFixed you find 10 feature.xml files.


More information:
ErrorRecoveryLog.getLocalRandomIdentifier() should create  unique filename for every call. It uses a timestamp to make the filename unique and implements a check in file system to see that the file is really unique since clock resolution is not sufficient (e.g. 10 ms on Windows, worse on VMWare images). This check is buggy.

Fix: 
Plugin org.eclipse.update.core                                            
Class: org.eclipse.update.internal.core.ErrorRecoveryLog                  
Method: getLocalRandomIdentifier(String path)                             
                                                                          
Line 98                                                                   
    while (new File(newName).exists()) {                                  
must be replaced by                                                       
    while (new File(file.getParentFile(), newName).exists()) {
Comment 1 Stephan Merker CLA 2007-11-22 08:32:35 EST
Increased severity. Install and update scenarios can't be tested on our standard test infrastructure.

It is simple to fix. Any chance for 3.3.2?
Comment 2 Dejan Glozic CLA 2007-11-22 10:32:57 EST
Can you explain your fix a bit more and provide a patch? We have no developers for Update and can only handle outside contributions.
Comment 3 Stephan Merker CLA 2007-11-22 12:48:13 EST
Created attachment 83552 [details]
Patch for bug in ErrorRecoveryLog.java
Comment 4 Stephan Merker CLA 2007-11-22 12:55:44 EST
For generating unique temp files, the getLocalRandomIdentifier() adds a time stamp to a given file name and then verifies that the new file doesn't yet exist in the file system.
The bug is that the path of the file was forgotten for the test, so the new file seems always unique even if it is not.

I have attached a patch for org.eclipse.update.internal.core.ErrorRecoveryLog.

Best regards,
Stephan
Comment 5 Stephan Merker CLA 2008-01-17 02:25:24 EST
Can you please include my patch into Eclipse 3.3.2? Is there anything missing, where I could help?
Comment 6 Holger Oehm CLA 2008-01-29 08:52:17 EST
Is there a reason that the bug fix is not included yet?
Comment 7 Wayne Beaton CLA 2008-02-04 13:43:30 EST
Created attachment 88805 [details]
JUnit test case

This patch demonstrates the bug (and confirms the patch). Add this to org.eclipse.update.tests.core
Comment 8 Mike Wilson CLA 2008-04-11 17:47:12 EDT
This should be fixed.
Comment 9 DJ Houghton CLA 2008-04-15 13:12:06 EDT
I started to modify the patch to handle the case where #getParentFile returns null and I made the mistake of trying to understand the code. It looks like the code (even before the patch) will return either the path to a file, a directory, or null. 

It doesn't look like any of the callers handle the null case and I'm not even sure the directory case is handled. Dejan, do you remember what this code is doing?
Comment 10 Dejan Glozic CLA 2008-06-19 14:30:39 EDT
(In reply to comment #9)

I *guess* it is creating a unique file name to generate a file and then make a swap by renaming the temp. file with the actual target name. I remember it was done to ensure that the file writing phase does not crash half way leaving a corrupted file.
Comment 11 John Arthorne CLA 2008-07-10 11:56:47 EDT
Andrew, I suggest just releasing the provided patch as-is. There is a theoretical NPE if someone passes the file system root ("/" or "c:\") to this method, but that was the case before the patch as well. It's not clear there is a reasonable alternative result to return in this case, and from looking at the callers it never happens anyway.
Comment 12 Andrew Niefer CLA 2008-07-14 14:38:37 EDT
done in HEAD & 3.4.1 (patch + test)