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

Bug 363462

Summary: Resource Exception in ModelManager when deleting closed project
Product: [Tools] CDT Reporter: Marko Tomljenovic <marko.tomljenovic>
Component: cdt-coreAssignee: Project Inbox <cdt-core-inbox>
Status: REOPENED --- QA Contact: Jonah Graham <jonah>
Severity: normal    
Priority: P3 CC: john.cortell, malaperle
Version: 7.0.2   
Target Milestone: ---   
Hardware: PC   
OS: Windows XP   
Whiteboard:
Bug Depends on: 366393    
Bug Blocks:    

Description Marko Tomljenovic CLA 2011-11-10 08:50:08 EST
Build Identifier: 7.0.2

If I delete a closed project CModelManager throws the following exception:

org.eclipse.core.internal.resources.ResourceException: Resource '/example_c_cpp' is not open.
	at org.eclipse.core.internal.resources.Project.checkAccessible(Project.java:137)
	at org.eclipse.core.internal.resources.Project.hasNature(Project.java:511)
	at org.eclipse.cdt.internal.core.model.CModelManager.resourceChanged(CModelManager.java:890)
	at org.eclipse.core.internal.events.NotificationManager$2.run(NotificationManager.java:291)
	at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
	at org.eclipse.core.internal.events.NotificationManager.notify(NotificationManager.java:285)
	at org.eclipse.core.internal.events.NotificationManager.handleEvent(NotificationManager.java:261)
	at org.eclipse.core.internal.resources.Workspace.broadcastEvent(Workspace.java:321)
	at org.eclipse.core.internal.resources.Resource.broadcastPreDeleteEvent(Resource.java:1993)
	at org.eclipse.core.internal.resources.Resource.delete(Resource.java:771)
	at org.eclipse.core.internal.resources.Project.delete(Project.java:331)
	at com.bosch.codenav.testutils.util.TestHelper.deleteProjectAndWait(TestHelper.java:878)
	at com.bosch.codenav.testutils.util.TestHelper.clearWorkspace(TestHelper.java:1688)
	at com.bosch.codenav.testutils.profiling.AbstractMemoryTest.finalizeAbstractMemoryTest(AbstractMemoryTest.java:242)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:597)
	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
	at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:37)
	at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
	at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:49)
	at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
	at org.eclipse.pde.internal.junit.runtime.RemotePluginTestRunner.main(RemotePluginTestRunner.java:62)
	at org.eclipse.pde.internal.junit.runtime.UITestApplication$1.run(UITestApplication.java:116)
	at org.eclipse.swt.widgets.RunnableLock.run(RunnableLock.java:35)
	at org.eclipse.swt.widgets.Synchronizer.runAsyncMessages(Synchronizer.java:134)
	at org.eclipse.swt.widgets.Display.runAsyncMessages(Display.java:4041)
	at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3660)
	at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:2640)
	at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2604)
	at org.eclipse.ui.internal.Workbench.access$4(Workbench.java:2438)
	at org.eclipse.ui.internal.Workbench$7.run(Workbench.java:671)
	at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
	at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:664)
	at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149)
	at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:115)
	at org.eclipse.pde.internal.junit.runtime.UITestApplication.start(UITestApplication.java:47)
	at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
	at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:110)
	at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:79)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:369)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:179)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:597)
	at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:620)
	at org.eclipse.equinox.launcher.Main.basicRun(Main.java:575)
	at org.eclipse.equinox.launcher.Main.run(Main.java:1408)
	at org.eclipse.equinox.launcher.Main.main(Main.java:1384)


Reproducible: Always

Steps to Reproduce:
Try to delete a closed project (that is no cdt enabled project).
Comment 1 Marc-André Laperle CLA 2011-11-16 01:06:23 EST
I tried to reproduce this and I'm a little bit confused. The only way I had this exception is if I removed the try catch block in this part

CModelManager.resourceChanged
...

case IResourceChangeEvent.PRE_DELETE :
    try {
        if (resource.getType() == IResource.PROJECT && 	
           ( ((IProject)resource).hasNature(CProjectNature.C_NATURE_ID) ||
          ((IProject)resource).hasNature(CCProjectNature.CC_NATURE_ID) )){
           this.preDeleteProject((IProject) resource);}
    } catch (CoreException e) {
    }
    break;

Also, the line CModelManager.java:890 didn't match to a Project.hasNature call in 7.0.2. Could it be possible that you have a modified version of CDT 7.0.2?
Comment 2 Marko Tomljenovic CLA 2011-11-17 07:05:10 EST
(In reply to comment #1)
> I tried to reproduce this and I'm a little bit confused. The only way I had
> this exception is if I removed the try catch block in this part
> 
> CModelManager.resourceChanged
> ...
> 
> case IResourceChangeEvent.PRE_DELETE :
>     try {
>         if (resource.getType() == IResource.PROJECT &&     
>            ( ((IProject)resource).hasNature(CProjectNature.C_NATURE_ID) ||
>           ((IProject)resource).hasNature(CCProjectNature.CC_NATURE_ID) )){
>            this.preDeleteProject((IProject) resource);}
>     } catch (CoreException e) {
>     }
>     break;
> 
> Also, the line CModelManager.java:890 didn't match to a Project.hasNature call
> in 7.0.2. Could it be possible that you have a modified version of CDT 7.0.2?

I compared "my" version with yours. The only difference is that in my version the catched CoreException is logged where in your version it is simply not regarded at all.
This issue can be closed from my point of view.  The only question is whether not regarding a CoreException here is the right and specified way.
Comment 3 Andrew Gvozdev CLA 2011-12-08 16:48:56 EST
Closing as per last comment. I've seen the trick of ignoring exceptions from closed projects in other places in CDT a well.
Comment 4 John Cortell CLA 2011-12-08 16:57:34 EST
We just recently tweaked Freescale's copy of platform to throw a specialization of CoreException that we check and ignore. CDT shouldn't be reporting exceptions to the Error log when such exceptions are expected and acceptable. The problem is that the way the exception is thrown in the platform doesn't allow CDT to reliably know if it's one of these harmless exceptions or not. I'll ask Serge Beauchamp to pursue contributing the platform change and I'll contribute the CDT part of it.
Comment 5 Andrew Gvozdev CLA 2011-12-08 17:22:31 EST
If you read comment#1 and comment#2 stock CDT doesn't report such an exception. A forked (or older) version of CDT does that. But I don't mind if this gets fixed the right way of course. Is there any bug on platform side?
Comment 6 John Cortell CLA 2011-12-08 17:29:58 EST
(In reply to comment #5)
> If you read comment#1 and comment#2 stock CDT doesn't report such an exception.
> A forked (or older) version of CDT does that. But I don't mind if this gets
> fixed the right way of course. Is there any bug on platform side?

Well, eating any CoreExceptions that can happen in that code is definitely not ideal. We only want to eat the core exception that happens as a result of the project being closed. Again, properly making that distinction isn't possible today but if Serge is on board for contributing the change to the platform, then we can improve the situation in CDT. I or Serge will open a platform bug soon.