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

Bug 337204

Summary: Codan throws ResourceException when adding linked folder to project
Product: [Tools] CDT Reporter: Lukas Felber <l.felber>
Component: cdt-codanAssignee: Project Inbox <cdt-core-inbox>
Status: RESOLVED FIXED QA Contact: Elena Laskavaia <elaskavaia.cdt>
Severity: normal    
Priority: P3 CC: cdtdoug, eclipse.sprigogin, malaperle
Version: 8.0   
Target Milestone: 8.0   
Hardware: PC   
OS: Linux   
Whiteboard:
Bug Depends on: 338041    
Bug Blocks:    

Description Lukas Felber CLA 2011-02-15 07:22:03 EST
Build Identifier: M20100909-0800

When linking a source folder D (containing file F.cpp) of a given project A into another project B and closing project A, codan tries to add markers to the file A/D/F.cpp instead of B/D/F.cpp.

Reproducible: Always

Steps to Reproduce:
1. create new project A and add a source folder D. Add new source file F.cpp to D (and enter some code).
2. create a new project B. Right-click on B and chose "New->Folder" (not "Source Folder")
3. check the "Advanced >>" button and chose "Link to alternative location (Linked Folder)". Browse to project A and select folder D.
4. right-click on project A and chose "Close Project".
5. opening file F.cpp in project A/D causes a ResourceException (trace bellow).

The mistake causing the problem can be found in CodanCReconsiler.reconciled(...). The IWorkspaceRoot is used to findFilesForLocationURI, which returns 2 IFiles whereof the first one is chosen (which is the one located in the closed project A).

A fix for the problem would actually be to loop over the returned files and check if the file's location matches the one location of the current AST.

But this is not possible since the AST.getFilePath also (falsly) points to A/D/F.cpp instead of B/D/F.cpp. So the wrong AST location is probably the problem which should be solved fist.

Checking if resource.exists() would probably be a fix the example above but will most likely cause the codan markers to be displayed in the wrong file (given that project A is not closed).


org.eclipse.core.internal.resources.ResourceException: Resource '/A/sub/A.cpp' does not exist.
	at org.eclipse.core.internal.resources.Resource.checkExists(Resource.java:326)
	at org.eclipse.core.internal.resources.Resource.checkAccessible(Resource.java:200)
	at org.eclipse.core.internal.resources.Resource.findMarkers(Resource.java:1013)
	at org.eclipse.cdt.codan.internal.core.model.CodanMarkerProblemReporter$1.run(CodanMarkerProblemReporter.java:142)
	at org.eclipse.core.internal.resources.Workspace.run(Workspace.java:1975)
	at org.eclipse.cdt.codan.internal.core.model.CodanMarkerProblemReporter.deleteProblems(CodanMarkerProblemReporter.java:140)
	at org.eclipse.cdt.codan.internal.core.CodanBuilder.processResource(CodanBuilder.java:132)
	at org.eclipse.cdt.codan.internal.core.CodanBuilder.runInEditor(CodanBuilder.java:192)
	at org.eclipse.cdt.codan.core.cxx.internal.model.CxxCodanReconciler.reconciledAst(CxxCodanReconciler.java:29)
	at org.eclipse.cdt.codan.internal.ui.cxx.CodanCReconciler.reconciled(CodanCReconciler.java:90)
	at org.eclipse.cdt.internal.ui.editor.CEditor.reconciled(CEditor.java:2979)
	at org.eclipse.cdt.internal.ui.text.CReconcilingStrategy.reconcile(CReconcilingStrategy.java:105)
	at org.eclipse.cdt.internal.ui.text.CReconcilingStrategy.initialReconcile(CReconcilingStrategy.java:127)
	at org.eclipse.cdt.internal.ui.text.CompositeReconcilingStrategy.initialReconcile(CompositeReconcilingStrategy.java:112)
	at org.eclipse.cdt.internal.ui.text.CCompositeReconcilingStrategy.initialReconcile(CCompositeReconcilingStrategy.java:108)
	at org.eclipse.jface.text.reconciler.MonoReconciler.initialProcess(MonoReconciler.java:105)
	at org.eclipse.cdt.internal.ui.text.CReconciler.initialProcess(CReconciler.java:395)
	at org.eclipse.jface.text.reconciler.AbstractReconciler$BackgroundThread.run(AbstractReconciler.java:173)
Comment 1 Elena Laskavaia CLA 2011-05-01 21:01:28 EDT
Looks like it is fixed because I cannot reproduce it anymore (and code you referring too has changed)