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

Bug 333136

Summary: NullPointerException in DirtyResourceFactory.getIndex()
Product: [Modeling] EMF Reporter: Axel Uhl <eclipse>
Component: Query2Assignee: Project Inbox <emf.query2-inbox>
Status: RESOLVED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: eclipse, saurav.sarkar1
Version: unspecified   
Target Milestone: ---   
Hardware: PC   
OS: Windows 7   
Whiteboard:

Description Axel Uhl CLA 2010-12-23 05:05:02 EST
Build Identifier: CVS Head as of 2010-12-23

During a query, the dirtyIndex field in DirtyResourceFactory turns out to be null and gives a NullPointerException in EmfHelper.getReferringElementsWithTypeAndInScope(...). It is not clear to me which initialization I'm probably missing.


Thread [main] (Suspended)	
	DirtyResourceFactory.getIndex() line: 74	
	EmfHelper.getBackwardNavIndex() line: 242	
	EmfHelper.getReferringElementsWithTypeAndInScope(EObject, URI, Set<URI>, Set<EClass>, Set<URI>) line: 252	
	BasicQueryProcessorMemoryImpl.getLinkedObjectsAndFilterByPartitions(EmfHelper, EObject, URI, Set<URI>, Set<EClass>, Set<URI>) line: 256	
	BasicQueryProcessorMemoryImpl.getLinkedObjects(EmfHelper, EObject, URI, Set<URI>, Set<URI>, Set<URI>) line: 163	
	ClusterNavigationPlan.getLinkedElementObjectsWithAttributeCheck(EObject, URI, Set<URI>, Set<URI>, Set<URI>, SpiAttributeExpression) line: 911	
	ClusterNavigationPlan.calculateLinkedObjects(int) line: 888	
	ClusterNavigationPlan.updateNavigationTarget(int) line: 1113	
	ClusterNavigationPlan.nextTupleNoCheckForOtherLinkExpressions() line: 1187	
	ClusterNavigationPlan.nextTuple() line: 1126	
	ClusterEvaluator.evaluateClusterAuxiliary(Object, int, int) line: 202	
	ClusterEvaluator.evaluateCluster(SpiSelectExpression, int, int) line: 108	
	BasicQueryProcessorMemoryImpl.execute(EmfHelper, SpiFacilityQueryClientScope, SpiSelectExpression, int, int) line: 98	
	InterpreterImpl.executeLeafQuery(LeafQuery, Map<SelectEntry,PositionRecord>, int) line: 403	
	InterpreterImpl.executeInternalQuery(InternalQuery, Map<SelectEntry,PositionRecord>, int) line: 259	
	InterpreterImpl.executeResultUnion(ResultUnion, Map<SelectEntry,PositionRecord>, int) line: 297	
	InterpreterImpl.executeInternalQuery(InternalQuery, Map<SelectEntry,PositionRecord>, int) line: 246	
	InterpreterImpl.executeNodeQuery(NodeQuery, Map<SelectEntry,PositionRecord>, int) line: 575	
	InterpreterImpl.executeInternalQuery(InternalQuery, Map<SelectEntry,PositionRecord>, int) line: 250	
	InterpreterImpl.executeNodeQuery(NodeQuery, Map<SelectEntry,PositionRecord>, int) line: 575	
	InterpreterImpl.executeInternalQuery(InternalQuery, Map<SelectEntry,PositionRecord>, int) line: 250	
	InterpreterImpl.execute(InternalQuery, int, int) line: 136	
	QueryProcessorImpl.executeSecuredInternal(PreparedQuery, EmfHelper, boolean, boolean, URI[], URI[], int) line: 502	
	QueryProcessorImpl.access$0(QueryProcessorImpl, PreparedQuery, EmfHelper, boolean, boolean, URI[], URI[], int) line: 461	
	QueryProcessorImpl$1.execute(QueryExecutor) line: 453	
	PageableIndexImpl.executeQueryCommand(QueryCommand) line: 95	
	QueryProcessorImpl.executeInternal(PreparedQuery, EmfHelper, boolean, boolean, QueryContext, URI[], int) line: 457	
	QueryProcessorImpl.execute(String, QueryContext, int) line: 663	
	QueryProcessorImpl.execute(String, QueryContext) line: 614	
	ContextAndForeachHelper.getCommonBaseClassForContextTag(ConcreteSyntax, String) line: 104	
	ContextAndForeachHelper.getParsingContext(String, Template) line: 170	
	AbstractFurcasOCLBasedModelUpdater.createOCLHelper(String, Template, OppositeEndFinder) line: 94	
	SimplePropertyInitUpdater.<init>(LookupPropertyInit, EPackage$Registry, OppositeEndFinder) line: 26	
	SyntaxRegistry.registerInjectorActions(Collection<InjectorAction>, TriggerManager, ParserFactory<ObservableInjectingParser,Lexer>, Registry, OppositeEndFinder, IProgressMonitor) line: 133	
	SyntaxRegistry.fillTriggerManagerForSyntax(TriggerManager, ConcreteSyntax, ParserFactory<ObservableInjectingParser,Lexer>, Registry, OppositeEndFinder, IProgressMonitor) line: 90	
	SyntaxRegistry.getTriggerManagerForSyntax(ConcreteSyntax, Registry, OppositeEndFinder, IProgressMonitor, ParserFactory<ObservableInjectingParser,Lexer>) line: 77	
	AbstractBibtexTestWithTextBlocks.setupParser(File, String) line: 83	
	TestPropertyInitReEvaluationWithContextInForeachTriggeredTemplate.setupParser() line: 48	
	NativeMethodAccessorImpl.invoke0(Method, Object, Object[]) line: not available [native method]	
	NativeMethodAccessorImpl.invoke(Object, Object[]) line: not available	
	DelegatingMethodAccessorImpl.invoke(Object, Object[]) line: not available	
	Method.invoke(Object, Object...) line: not available	
	FrameworkMethod$1.runReflectiveCall() line: 44	
	FrameworkMethod$1(ReflectiveCallable).run() line: 15	
	FrameworkMethod.invokeExplosively(Object, Object...) line: 41	
	RunBefores.evaluate() line: 27	
	BlockJUnit4ClassRunner(ParentRunner<T>).run(RunNotifier) line: 236	
	JUnit4TestClassReference(JUnit4TestReference).run(TestExecution) line: 49	
	TestExecution.run(ITestReference[]) line: 38	
	RemotePluginTestRunner(RemoteTestRunner).runTests(String[], String, TestExecution) line: 467	
	RemotePluginTestRunner(RemoteTestRunner).runTests(TestExecution) line: 683	
	RemotePluginTestRunner(RemoteTestRunner).run() line: 390	
	RemotePluginTestRunner.main(String[]) line: 62	
	CoreTestApplication.run(Object) line: 23	
	NativeMethodAccessorImpl.invoke0(Method, Object, Object[]) line: not available [native method]	
	NativeMethodAccessorImpl.invoke(Object, Object[]) line: not available	
	DelegatingMethodAccessorImpl.invoke(Object, Object[]) line: not available	
	Method.invoke(Object, Object...) line: not available	
	EclipseAppContainer.callMethodWithException(Object, String, Class[], Object[]) line: 587	
	EclipseAppHandle.run(Object) line: 198	
	EclipseAppLauncher.runApplication(Object) line: 110	
	EclipseAppLauncher.start(Object) line: 79	
	EclipseStarter.run(Object) line: 369	
	EclipseStarter.run(String[], Runnable) line: 179	
	NativeMethodAccessorImpl.invoke0(Method, Object, Object[]) line: not available [native method]	
	NativeMethodAccessorImpl.invoke(Object, Object[]) line: not available	
	DelegatingMethodAccessorImpl.invoke(Object, Object[]) line: not available	
	Method.invoke(Object, Object...) line: not available	
	Main.invokeFramework(String[], URL[]) line: 619	
	Main.basicRun(String[]) line: 574	
	Main.run(String[]) line: 1407	
	Main.main(String[]) line: 1383	


Reproducible: Always

Steps to Reproduce:
Kind of difficult. The query I'm firing is this:

select me from [http://www.eclipse.org/emf/2002/Ecore#//EClassifier] as me,[http://www.furcas.org#//TCS/ContextTemplate] as ct,[http://www.furcas.org#//TCS/ContextTags] as tags,[http://www.furcas.org#//TCS/ConcreteSyntax] as cs in elements {[http://www.furcas.org/transientParsingResource_eH7qUA55EeCSRoxfOLGwIQ#/1]} where ct.concreteSyntax=cs where ct.metaReference=me where ct.contextTags=tags where ct.isContext=true where tags.tags='bibtexfile'

I've checked the broken scenario into a github repository git://github.com/FURCAS-dev/FURCAS.git as branch broken_query2_test. Clone the branch. Open an Eclipse instance with the git repository as your workspace. Hit the update site at http://furcas-dev.github.com/FURCAS/update-site and from the "FURCAS Textual Modelling" group install feature "Workspace Setup". Restart Eclipse. You should see a little white icon in your toolbar tooltipped "Initialize Furcas Workspace". Run it. Then you should find a launch configuration ReferenceResolvingTests. Run it. The setup of TestPropertyInitReEvaluationWithContextInForeachTriggeredTemplate should reproduce the problem.
Comment 1 saurav sarkar CLA 2010-12-23 05:15:51 EST
Hi Axel,

DirtyResourceFactory has been introduced to keep track of the dirty index.
Could you please check this link

https://bugs.eclipse.org/bugs/show_bug.cgi?id=324176

And also the TestQueryBugs.java which contains an example of how the DirtyResourceFactory could be setup.

cheers,
Saurav
Comment 2 Axel Uhl CLA 2010-12-23 05:19:35 EST
It seems the DirtyResourceFactory instance could use some initialization. A tiny ugly patch that fixes it quick/dirty for us is this:

diff --git a/EMF/query2/org.eclipse.emf.query2/plugins/org.eclipse.emf.query2.core/src/org/eclipse/emf/query2/internal/shared/EmfHelper.java b/EMF/query2/org.eclipse.emf.query2/plugins/org.eclipse.emf.query2.core/src/org/eclipse/emf/query2/
internal/shared/EmfHelper.java
index 26b483a..e573fcb 100644
--- a/EMF/query2/org.eclipse.emf.query2/plugins/org.eclipse.emf.query2.core/src/org/eclipse/emf/query2/internal/shared/EmfHelper.java
+++ b/EMF/query2/org.eclipse.emf.query2/plugins/org.eclipse.emf.query2.core/src/org/eclipse/emf/query2/internal/shared/EmfHelper.java
@@ -239,7 +239,7 @@ public class EmfHelper {
        private Index getBackwardNavIndex() {
                if (useDirty) {
                        //The dirty index is maintained by the DirtyResourceFactory
-                       return DirtyResourceFactory.getIndex();
+                       return DirtyResourceFactory.getInstance().getIndex();
                } else {
                        return this.index;
                }
Comment 3 saurav sarkar CLA 2011-01-10 01:32:27 EST
Provided the NPE check in the Query core code where it accesses the DirtyResourceFactory. Hence closing the bug