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

Bug 363921

Summary: [Query 2] exception when index bundle is stopped
Product: [Modeling] EMF Reporter: Sébastien Gandon <sgandon>
Component: Query2Assignee: saurav sarkar <saurav.sarkar1>
Status: ASSIGNED --- QA Contact:
Severity: normal    
Priority: P3 CC: saurav.sarkar1
Version: unspecified   
Target Milestone: ---   
Hardware: Macintosh   
OS: Mac OS X - Carbon (unsup.)   
Whiteboard:

Description Sébastien Gandon CLA 2011-11-16 10:05:25 EST
Build Identifier: 

We are using emf query in a rcp app and have an exception when closing the application cause but the stop method implemetation of 
    org.eclipse.emf.query.index.Activator
See the stack at the bottom.
Here is the stop method : 
 public void stop(BundleContext context) throws Exception {
        plugin = null;
        // Dumping of Indexes at the close of IDE, so that when the IDE is
        // started for the next time, indices must not be build again and
        // instead loaded from saved ones.
        IndexFactory.dumpIndexes();
        super.stop(context);
    }
The problems comes from the fact that  IndexFactory.dumpIndexes(); needs to call back Activator.getDefault() to find the a folder to related the the bundle to store the index. But the plugin has be set to null before that. So the Activator.getDefault() returns null and then no folder is calculated.
here is the simple patch.

 public void stop(BundleContext context) throws Exception {
        // Dumping of Indexes at the close of IDE, so that when the IDE is
        // started for the next time, indices must not be build again and
        // instead loaded from saved ones.
        IndexFactory.dumpIndexes();
        plugin = null;
        super.stop(context);
    }



Here is the stack : 
Caused by: java.lang.IllegalStateException: Base path not set
	at org.eclipse.emf.query.index.internal.impl.PageFileProviderImpl.getFileForElement(PageFileProviderImpl.java:41)
	at org.eclipse.emf.query.index.internal.impl.PageFileProviderImpl.getOutputFile(PageFileProviderImpl.java:36)
	at org.eclipse.emf.query.index.internal.impl.PagingStrategyImpl.pageOut(PagingStrategyImpl.java:297)
	at org.eclipse.emf.query.index.internal.impl.PagingStrategyImpl.flush(PagingStrategyImpl.java:338)
	at org.eclipse.emf.query.index.internal.impl.PagingResourceDescriptorMap.flush(PagingResourceDescriptorMap.java:105)
	at org.eclipse.emf.query.index.internal.impl.PageableIndexImpl.save(PageableIndexImpl.java:126)
	at org.eclipse.emf.query.index.IndexFactory.dumpIndexes(IndexFactory.java:98)
	at org.eclipse.emf.query.index.Activator.stop(Activator.java:49)
	at org.eclipse.osgi.framework.internal.core.BundleContextImpl$2.run(BundleContextImpl.java:843)
	at java.security.AccessController.doPrivileged(Native Method)
	at org.eclipse.osgi.framework.internal.core.BundleContextImpl.stop(BundleContextImpl.java:836)

Reproducible: Always