Bug 560187

Summary: Threading issue in ProjectDescription
Product: [Eclipse Project] Platform Reporter: Marc M <MarcMiltenberger>
Component: ResourcesAssignee: Platform-Resources-Inbox <platform-resources-inbox>
Status: NEW --- QA Contact:
Severity: normal    
Priority: P3 CC: loskutov
Version: 3.8.2   
Target Milestone: ---   
Hardware: PC   
OS: Linux   
Whiteboard:

Description Marc M CLA 2020-02-16 04:34:55 EST
I got an IO exception while adding natures to a project:
Caused by: org.eclipse.core.internal.resources.ResourceException: File not found: Foo/.project.
	at org.eclipse.core.internal.localstore.FileSystemResourceManager.read(FileSystemResourceManager.java:834)
	at org.eclipse.core.internal.resources.File.getContents(File.java:275)
	at org.eclipse.core.internal.localstore.FileSystemResourceManager.descriptionChanged(FileSystemResourceManager.java:382)
	at org.eclipse.core.internal.localstore.FileSystemResourceManager.internalWrite(FileSystemResourceManager.java:651)
	at org.eclipse.core.internal.resources.Project.writeDescription(Project.java:1383)
	at org.eclipse.core.internal.resources.Project.setDescription(Project.java:1275)
	at org.eclipse.core.internal.resources.Project.setDescription(Project.java:1298)



Apparently the static isWriting, isReading flags in the ProjectDescription are responsible to note on whether any thread reads or writes a project description at the moment.

	protected static boolean isReading = false;

	//flags to indicate when we are in the middle of reading or writing a
	// workspace description
	//these can be static because only one description can be read at once.
	protected static boolean isWriting = false;


However, since the fields are not marked volatile, written changes to the the fields may not be propagated to others threads, so that two threads can write concurrently nontheless.

But even then it seems that two or more threads may write descriptions concurrently, since no checks or waiting-loop exists in Project.writeDescription before starting writing.
Comment 1 Andrey Loskutov CLA 2020-02-16 12:49:09 EST
I have no code at hand right now, but I wonder if the writer is supposed to run with a workspace lock? But static global variables is a nonsense anyway in multiple ways.

Is the exception you get reproducible, and can you attach the code snippet causing it?