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

Bug 399832

Summary: Wrong package nsURI is generated into the globalEiqModel.xmi when using packages from eiqgen
Product: [Modeling] Viatra Reporter: Balazs Grill <balazs.grill>
Component: QueryAssignee: Zoltan Ujhelyi <zoltan.ujhelyi>
Status: CLOSED FIXED QA Contact: Istvan Rath <istvanrath>
Severity: critical    
Priority: P3 CC: abel.hegedus, balazs.grill
Version: oldinquery   
Target Milestone: M1   
Hardware: PC   
OS: Windows 7   
Whiteboard:
Bug Depends on:    
Bug Blocks: 398720    
Attachments:
Description Flags
mylyn/context/zip
none
Fixed URI calculation when EClass is identified by xmi:id zoltan.ujhelyi: iplog+

Description Balazs Grill CLA 2013-02-04 04:04:31 EST
When both the model and query projects are located in the workspace, queries are built against the ecore models loaded by the eiqgen file. The generated globalEiqModel.xmi will contain URIs to EClasses contained by the referenced ecore models.

However, these URIs are not the same as it would be in runtime, which causes an error when I try to execute the queries at runtime, becuase it cannot load the EClasses.

Sample code for the situation:
https://github.com/balazsgrill/modembed/tree/feature-query/core/hu.modembed.query

Sample EClass URI at development time:
http://modembed.hu/core/assembler/code#//core/assembler/code/AssemblerObject

Sample EClass URI at runtime:
http://modembed.hu/core#//assembler/code/AssemblerObject

Exception trace:
org.eclipse.incquery.runtime.exception.IncQueryException: The following error occurred during the preparation of an EMF-IncQuery pattern matcher: Error during constructing Rete pattern matcher; please review Error Log and consult developers
	at org.eclipse.incquery.runtime.api.impl.BaseGeneratedMatcher.accessMatcher(BaseGeneratedMatcher.java:44)
	at org.eclipse.incquery.runtime.api.impl.BaseGeneratedMatcher.<init>(BaseGeneratedMatcher.java:35)
	at hu.modembed.query.types.TypesMatcher.<init>(TypesMatcher.java:63)
	at hu.modembed.query.types.TypesMatcherFactory.instantiate(TypesMatcherFactory.java:34)
	at hu.modembed.query.types.TypesMatcherFactory.instantiate(TypesMatcherFactory.java:1)
	at org.eclipse.incquery.runtime.api.impl.BaseMatcherFactory.getMatcher(BaseMatcherFactory.java:42)
	at org.eclipse.incquery.tooling.ui.queryexplorer.content.matcher.ObservablePatternMatcherRoot.addMatchersForPatterns(ObservablePatternMatcherRoot.java:202)
	at org.eclipse.incquery.tooling.ui.queryexplorer.content.matcher.ObservablePatternMatcherRoot.registerPattern(ObservablePatternMatcherRoot.java:175)
	at org.eclipse.incquery.tooling.ui.queryexplorer.util.DatabindingUtil.createPatternMatcherRoot(DatabindingUtil.java:447)
	at org.eclipse.incquery.tooling.ui.queryexplorer.content.matcher.MatcherTreeViewerRoot.addPatternMatcherRoot(MatcherTreeViewerRoot.java:40)
	at org.eclipse.incquery.tooling.ui.queryexplorer.handlers.util.EMFModelConnector.loadModel(EMFModelConnector.java:42)
	at org.eclipse.incquery.tooling.ui.queryexplorer.handlers.LoadModelHandler.execute(LoadModelHandler.java:41)
	at org.eclipse.ui.internal.handlers.HandlerProxy.execute(HandlerProxy.java:290)
	at org.eclipse.ui.internal.handlers.E4HandlerProxy.execute(E4HandlerProxy.java:76)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
	at java.lang.reflect.Method.invoke(Unknown Source)
	at org.eclipse.e4.core.internal.di.MethodRequestor.execute(MethodRequestor.java:56)
	at org.eclipse.e4.core.internal.di.InjectorImpl.invokeUsingClass(InjectorImpl.java:229)
	at org.eclipse.e4.core.internal.di.InjectorImpl.invoke(InjectorImpl.java:210)
	at org.eclipse.e4.core.contexts.ContextInjectionFactory.invoke(ContextInjectionFactory.java:131)
	at org.eclipse.e4.core.commands.internal.HandlerServiceImpl.executeHandler(HandlerServiceImpl.java:171)
	at org.eclipse.e4.ui.workbench.renderers.swt.HandledContributionItem.executeItem(HandledContributionItem.java:814)
	at org.eclipse.e4.ui.workbench.renderers.swt.HandledContributionItem.handleWidgetSelection(HandledContributionItem.java:707)
	at org.eclipse.e4.ui.workbench.renderers.swt.HandledContributionItem.access$7(HandledContributionItem.java:691)
	at org.eclipse.e4.ui.workbench.renderers.swt.HandledContributionItem$4.handleEvent(HandledContributionItem.java:630)
	at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1053)
	at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:4169)
	at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3758)
	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$9.run(PartRenderingEngine.java:1029)
	at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.run(PartRenderingEngine.java:923)
	at org.eclipse.e4.ui.internal.workbench.E4Workbench.createAndRunUI(E4Workbench.java:86)
	at org.eclipse.ui.internal.Workbench$5.run(Workbench.java:588)
	at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
	at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:543)
	at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149)
	at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:124)
	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:353)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:180)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
	at java.lang.reflect.Method.invoke(Unknown Source)
	at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:629)
	at org.eclipse.equinox.launcher.Main.basicRun(Main.java:584)
	at org.eclipse.equinox.launcher.Main.run(Main.java:1438)
	at org.eclipse.equinox.launcher.Main.main(Main.java:1414)
Caused by: org.eclipse.incquery.runtime.rete.construction.RetePatternBuildException: Error during constructing Rete pattern matcher; please review Error Log and consult developers
	at org.eclipse.incquery.runtime.internal.matcherbuilder.EPMBuilder.construct(EPMBuilder.java:59)
	at org.eclipse.incquery.runtime.internal.matcherbuilder.EPMBuilder.construct(EPMBuilder.java:1)
	at org.eclipse.incquery.runtime.rete.boundary.ReteBoundary.construct(ReteBoundary.java:523)
	at org.eclipse.incquery.runtime.rete.boundary.ReteBoundary.accessProduction(ReteBoundary.java:455)
	at org.eclipse.incquery.runtime.rete.matcher.ReteEngine$1.call(ReteEngine.java:179)
	at org.eclipse.incquery.runtime.rete.matcher.ReteEngine$1.call(ReteEngine.java:1)
	at org.eclipse.incquery.runtime.base.core.NavigationHelperImpl.coalesceTraversals(NavigationHelperImpl.java:656)
	at org.eclipse.incquery.runtime.internal.EMFPatternMatcherRuntimeContext.coalesceTraversals(EMFPatternMatcherRuntimeContext.java:193)
	at org.eclipse.incquery.runtime.rete.matcher.ReteEngine.accessMatcher(ReteEngine.java:175)
	at org.eclipse.incquery.runtime.api.impl.BaseGeneratedMatcher.accessMatcher(BaseGeneratedMatcher.java:42)
	... 52 more
Caused by: java.lang.NullPointerException
	at org.eclipse.incquery.runtime.base.core.NavigationHelperContentAdapter.getUniqueIdentifier(NavigationHelperContentAdapter.java:98)
	at org.eclipse.incquery.runtime.base.core.NavigationHelperContentAdapter.getInstanceSet(NavigationHelperContentAdapter.java:421)
	at org.eclipse.incquery.runtime.base.core.NavigationHelperImpl.getAllInstances(NavigationHelperImpl.java:321)
	at org.eclipse.incquery.runtime.internal.EMFPatternMatcherRuntimeContext.enumerateAllUnaryInstances(EMFPatternMatcherRuntimeContext.java:387)
	at org.eclipse.incquery.runtime.rete.boundary.EntityFeeder.feed(EntityFeeder.java:42)
	at org.eclipse.incquery.runtime.rete.boundary.ReteBoundary.accessUnaryRoot(ReteBoundary.java:200)
	at org.eclipse.incquery.runtime.rete.construction.ReteContainerBuildable.unaryTypeStub(ReteContainerBuildable.java:161)
	at org.eclipse.incquery.runtime.rete.construction.psystem.basicenumerables.TypeUnary.doCreateStub(TypeUnary.java:38)
	at org.eclipse.incquery.runtime.rete.construction.psystem.EnumerablePConstraint.getStub(EnumerablePConstraint.java:39)
	at org.eclipse.incquery.runtime.rete.construction.quasitree.QuasiTreeLayout$Scaffold.run(QuasiTreeLayout.java:91)
	at org.eclipse.incquery.runtime.rete.construction.quasitree.QuasiTreeLayout.layout(QuasiTreeLayout.java:49)
	at org.eclipse.incquery.runtime.internal.matcherbuilder.EPMBuildScaffold.construct(EPMBuildScaffold.java:58)
	at org.eclipse.incquery.runtime.internal.matcherbuilder.EPMBuilder.construct(EPMBuilder.java:57)
	... 61 more
Comment 1 Zoltan Ujhelyi CLA 2013-02-04 10:30:29 EST
This seems to be the same issue we have debugged with Abel two weeks ago. If there are multiple EPackage-s in an Ecore file, the correct calculation of the precise URI seems to be problematic (some segmens needs to be removed, but not all and not a constant amount).

I will look into the issue shortly in more details.
Comment 2 Zoltan Ujhelyi CLA 2013-02-10 17:37:53 EST
That was quite an issue. I had to reverse engineer the EMF type URI algorithm, and re-code it for our serializer extensions. It seems to be working, but some extensive testing is needed.

Balázs, could you check your case whether this issue fixed it?

Ábel, could you check whether I managed to fix your other test case as well?

In the meantime, I am marking this issue as resolved, but feel free to re-open it if I missed something.
Comment 3 Zoltan Ujhelyi CLA 2013-02-10 17:38:35 EST
Created attachment 226816 [details]
mylyn/context/zip
Comment 4 Abel Hegedus CLA 2013-02-11 09:57:40 EST
Unfortunately, the fix does not work in my case:

EPackage in use:
name: dungeon, nsURI: http://dungeon.jitd.descent/1.0, nsPrefix: dungeon

ECore:
descent
\-jitd
 \-dungeon
  \-Hero

Sample EClass URI at development time (before fix):
http://dungeon.jitd.descent/1.0#//jitd/dungeon/Hero

Sample EClass URI at development time (after fix):
http://dungeon.jitd.descent/1.0#//Hero

Sample EClass URI at runtime:
http://dungeon.jitd.descent/1.0#//dungeon/Hero

Example: https://miklosfoldenyi@bitbucket.org/miklosfoldenyi/descent.git
Comment 5 Abel Hegedus CLA 2013-02-11 09:59:25 EST
Sorry, parent package is:
name: jitd, nsUri: http://jitd.descent/1.0, prefix: jitd
Comment 6 Abel Hegedus CLA 2013-02-11 10:05:28 EST
*** Bug 398891 has been marked as a duplicate of this bug. ***
Comment 7 Balazs Grill CLA 2013-02-12 04:26:36 EST
It doesn't work for me either, additionally, the builder fails with an exception in the log (apparently, there is an EClass, which doesn't have a "/" in its URI fragment. I don't know yet which is it, I'm still debugging the problem):

java.lang.StringIndexOutOfBoundsException: String index out of range: -1
	at java.lang.String.substring(Unknown Source)
	at org.eclipse.incquery.tooling.core.generator.util.EMFPatternURIHandler.deresolve(EMFPatternURIHandler.java:63)
	at org.eclipse.emf.ecore.xmi.impl.XMLHelperImpl.deresolve(XMLHelperImpl.java:815)
	at org.eclipse.emf.ecore.xmi.impl.XMLHelperImpl.getHREF(XMLHelperImpl.java:801)
	at org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveHref(XMLSaveImpl.java:2294)
	at org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveHRefSingle(XMLSaveImpl.java:2378)
	at org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveFeatures(XMLSaveImpl.java:1561)
	at org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveFeatures(XMLSaveImpl.java:1218)
	at org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveElementID(XMLSaveImpl.java:2710)
	at org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveElement(XMLSaveImpl.java:1175)
	at org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveElement(XMLSaveImpl.java:1036)
	at org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveContainedSingle(XMLSaveImpl.java:2397)
	at org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveFeatures(XMLSaveImpl.java:1541)
	at org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveFeatures(XMLSaveImpl.java:1218)
	at org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveElementID(XMLSaveImpl.java:2710)
	at org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveElement(XMLSaveImpl.java:1175)
	at org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveElement(XMLSaveImpl.java:1036)
	at org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveContainedMany(XMLSaveImpl.java:2411)
	at org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveFeatures(XMLSaveImpl.java:1547)
	at org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveFeatures(XMLSaveImpl.java:1218)
	at org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveElementID(XMLSaveImpl.java:2710)
	at org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveElement(XMLSaveImpl.java:1175)
	at org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveElement(XMLSaveImpl.java:1036)
	at org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveContainedMany(XMLSaveImpl.java:2411)
	at org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveFeatures(XMLSaveImpl.java:1547)
	at org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveFeatures(XMLSaveImpl.java:1218)
	at org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveElementID(XMLSaveImpl.java:2710)
	at org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.writeTopObject(XMLSaveImpl.java:677)
	at org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.traverse(XMLSaveImpl.java:585)
	at org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.save(XMLSaveImpl.java:251)
	at org.eclipse.emf.ecore.xmi.impl.XMLResourceImpl.doSave(XMLResourceImpl.java:331)
	at org.eclipse.emf.ecore.resource.impl.ResourceImpl.save(ResourceImpl.java:1417)
	at org.eclipse.emf.ecore.resource.impl.ResourceImpl.save(ResourceImpl.java:986)
	at org.eclipse.incquery.tooling.core.generator.builder.xmi.XmiModelBuilder.build(XmiModelBuilder.java:195)
	at org.eclipse.incquery.tooling.core.generator.builder.xmi.XmiModelSupport.internalBuild(XmiModelSupport.java:94)
	at org.eclipse.incquery.tooling.core.generator.builder.xmi.XmiModelSupport.build(XmiModelSupport.java:71)
	at org.eclipse.incquery.tooling.core.generator.builder.EMFPatternLanguageBuilderParticipant.build(EMFPatternLanguageBuilderParticipant.java:137)
	at org.eclipse.xtext.builder.impl.RegistryBuilderParticipant.build(RegistryBuilderParticipant.java:60)
	at org.eclipse.xtext.builder.impl.XtextBuilder.doBuild(XtextBuilder.java:161)
	at org.eclipse.xtext.builder.impl.XtextBuilder.fullBuild(XtextBuilder.java:188)
	at org.eclipse.xtext.builder.impl.XtextBuilder.build(XtextBuilder.java:85)
	at org.eclipse.core.internal.events.BuildManager$2.run(BuildManager.java:728)
	at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
	at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:199)
	at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:239)
	at org.eclipse.core.internal.events.BuildManager$1.run(BuildManager.java:292)
	at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
	at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:295)
	at org.eclipse.core.internal.events.BuildManager.basicBuildLoop(BuildManager.java:351)
	at org.eclipse.core.internal.events.BuildManager.build(BuildManager.java:374)
	at org.eclipse.core.internal.events.AutoBuildJob.doBuild(AutoBuildJob.java:143)
Comment 8 Zoltan Ujhelyi CLA 2013-02-12 04:36:10 EST
Balázs, don't debug it for now. After a short forum thread with Ed Merks, I found out I got the uri calculation algorithm wrong. Working on an alternative.
Comment 9 Zoltan Ujhelyi CLA 2013-02-12 10:57:51 EST
Another implementation is committed, and it seems to work on both the modembed and the descent examples (we have validated it with Ábel). Balázs, can you please try again?

I have also asked in the EMF Forum whether our new solution is as supported by EMF, and will not close the issue before I got an answer.
Comment 10 Zoltan Ujhelyi CLA 2013-02-12 11:31:59 EST
The URI resolution issue should be fixed for now; Ed Merks confirmed that parent packages are to be handled the way they are in http://www.eclipse.org/forums/index.php/m/1008478/#msg_1008478.

Alltogether, I am now optimistically marking this issue as fixed - but feel free to re-open if there remain some issues.
Comment 11 Balazs Grill CLA 2013-02-13 02:26:49 EST
Unfortunately it still doesn't work for me, I'm not sure why. It cannot generate queries for Autosar 4 models, the builder still fails with the following exception:

java.lang.StringIndexOutOfBoundsException: String index out of range: -1
	at java.lang.String.substring(Unknown Source)
	at org.eclipse.incquery.tooling.core.generator.util.EMFPatternURIHandler.deresolve(EMFPatternURIHandler.java:63)
	at org.eclipse.emf.ecore.xmi.impl.XMLHelperImpl.deresolve(XMLHelperImpl.java:815)
	at org.eclipse.emf.ecore.xmi.impl.XMLHelperImpl.getHREF(XMLHelperImpl.java:801)
	at org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveHref(XMLSaveImpl.java:2294)
	at org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveHRefSingle(XMLSaveImpl.java:2378)
	at org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveFeatures(XMLSaveImpl.java:1561)
	at org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveFeatures(XMLSaveImpl.java:1218)
	at org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveElementID(XMLSaveImpl.java:2710)
	at org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveElement(XMLSaveImpl.java:1175)
	at org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveElement(XMLSaveImpl.java:1036)
	at org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveContainedSingle(XMLSaveImpl.java:2397)
	at org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveFeatures(XMLSaveImpl.java:1541)
	at org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveFeatures(XMLSaveImpl.java:1218)
	at org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveElementID(XMLSaveImpl.java:2710)
	at org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveElement(XMLSaveImpl.java:1175)
	at org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveElement(XMLSaveImpl.java:1036)
	at org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveContainedMany(XMLSaveImpl.java:2411)
	at org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveFeatures(XMLSaveImpl.java:1547)
	at org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveFeatures(XMLSaveImpl.java:1218)
	at org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveElementID(XMLSaveImpl.java:2710)
	at org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveElement(XMLSaveImpl.java:1175)
	at org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveElement(XMLSaveImpl.java:1036)
	at org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveContainedMany(XMLSaveImpl.java:2411)
	at org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveFeatures(XMLSaveImpl.java:1547)
	at org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveFeatures(XMLSaveImpl.java:1218)
	at org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveElementID(XMLSaveImpl.java:2710)
	at org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.writeTopObject(XMLSaveImpl.java:677)
	at org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.traverse(XMLSaveImpl.java:585)
	at org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.save(XMLSaveImpl.java:251)
	at org.eclipse.emf.ecore.xmi.impl.XMLResourceImpl.doSave(XMLResourceImpl.java:331)
	at org.eclipse.emf.ecore.resource.impl.ResourceImpl.save(ResourceImpl.java:1417)
	at org.eclipse.emf.ecore.resource.impl.ResourceImpl.save(ResourceImpl.java:986)
	at org.eclipse.incquery.tooling.core.generator.builder.xmi.XmiModelBuilder.build(XmiModelBuilder.java:195)
	at org.eclipse.incquery.tooling.core.generator.builder.xmi.XmiModelSupport.internalBuild(XmiModelSupport.java:94)
	at org.eclipse.incquery.tooling.core.generator.builder.xmi.XmiModelSupport.build(XmiModelSupport.java:71)
	at org.eclipse.incquery.tooling.core.generator.builder.EMFPatternLanguageBuilderParticipant.build(EMFPatternLanguageBuilderParticipant.java:137)
	at org.eclipse.xtext.builder.impl.RegistryBuilderParticipant.build(RegistryBuilderParticipant.java:60)
	at org.eclipse.xtext.builder.impl.XtextBuilder.doBuild(XtextBuilder.java:161)
	at org.eclipse.xtext.builder.impl.XtextBuilder.fullBuild(XtextBuilder.java:188)
	at org.eclipse.xtext.builder.impl.XtextBuilder.build(XtextBuilder.java:85)
	at org.eclipse.core.internal.events.BuildManager$2.run(BuildManager.java:728)
	at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
	at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:199)
	at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:239)
	at org.eclipse.core.internal.events.BuildManager$1.run(BuildManager.java:292)
	at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
	at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:295)
	at org.eclipse.core.internal.events.BuildManager.basicBuildLoop(BuildManager.java:351)
	at org.eclipse.core.internal.events.BuildManager.build(BuildManager.java:374)
	at org.eclipse.core.internal.events.AutoBuildJob.doBuild(AutoBuildJob.java:143)
	at org.eclipse.core.internal.events.AutoBuildJob.run(AutoBuildJob.java:241)
	at org.eclipse.core.internal.jobs.Worker.run(Worker.java:53)


For Autosar 3 models, the queries are generated, but cannot be executed. Running them from the query explorer causes the following exception:

org.eclipse.incquery.runtime.exception.IncQueryException: The following error occurred during the preparation of an EMF-IncQuery pattern matcher: Error during constructing Rete pattern matcher; please review Error Log and consult developers
	at org.eclipse.incquery.runtime.api.impl.BaseGeneratedMatcher.accessMatcher(BaseGeneratedMatcher.java:44)
	at org.eclipse.incquery.runtime.api.impl.BaseGeneratedMatcher.<init>(BaseGeneratedMatcher.java:35)
	at com.thyssenkrupp.presta.ar.browser.ar300.consistency.invalidconnector.InvalidConnectorMatcher.<init>(InvalidConnectorMatcher.java:123)
	at com.thyssenkrupp.presta.ar.browser.ar300.consistency.invalidconnector.InvalidConnectorMatcherFactory.instantiate(InvalidConnectorMatcherFactory.java:34)
	at com.thyssenkrupp.presta.ar.browser.ar300.consistency.invalidconnector.InvalidConnectorMatcherFactory.instantiate(InvalidConnectorMatcherFactory.java:1)
	at org.eclipse.incquery.runtime.api.impl.BaseMatcherFactory.getMatcher(BaseMatcherFactory.java:42)
	at org.eclipse.incquery.tooling.ui.queryexplorer.content.matcher.ObservablePatternMatcherRoot.addMatchersForPatterns(ObservablePatternMatcherRoot.java:202)
	at org.eclipse.incquery.tooling.ui.queryexplorer.content.matcher.ObservablePatternMatcherRoot.registerPattern(ObservablePatternMatcherRoot.java:175)
	at org.eclipse.incquery.tooling.ui.queryexplorer.util.DatabindingUtil.createPatternMatcherRoot(DatabindingUtil.java:441)
	at org.eclipse.incquery.tooling.ui.queryexplorer.content.matcher.MatcherTreeViewerRoot.addPatternMatcherRoot(MatcherTreeViewerRoot.java:40)
	at org.eclipse.incquery.tooling.ui.queryexplorer.adapters.EMFModelConnector.loadModel(EMFModelConnector.java:67)
	at org.eclipse.incquery.tooling.ui.queryexplorer.handlers.LoadResourceSetHandler.execute(LoadResourceSetHandler.java:35)
	at org.eclipse.ui.internal.handlers.HandlerProxy.execute(HandlerProxy.java:293)
	at org.eclipse.core.commands.Command.executeWithChecks(Command.java:476)
	at org.eclipse.core.commands.ParameterizedCommand.executeWithChecks(ParameterizedCommand.java:508)
	at org.eclipse.ui.internal.handlers.HandlerService.executeCommand(HandlerService.java:169)
	at org.eclipse.ui.internal.handlers.SlaveHandlerService.executeCommand(SlaveHandlerService.java:241)
	at org.eclipse.ui.internal.handlers.SlaveHandlerService.executeCommand(SlaveHandlerService.java:241)
	at org.eclipse.ui.menus.CommandContributionItem.handleWidgetSelection(CommandContributionItem.java:829)
	at org.eclipse.ui.menus.CommandContributionItem.access$19(CommandContributionItem.java:815)
	at org.eclipse.ui.menus.CommandContributionItem$5.handleEvent(CommandContributionItem.java:805)
	at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1053)
	at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:4169)
	at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3758)
	at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:2701)
	at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2665)
	at org.eclipse.ui.internal.Workbench.access$4(Workbench.java:2499)
	at org.eclipse.ui.internal.Workbench$7.run(Workbench.java:679)
	at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
	at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:668)
	at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149)
	at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:123)
	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:344)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:179)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
	at java.lang.reflect.Method.invoke(Unknown Source)
	at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:622)
	at org.eclipse.equinox.launcher.Main.basicRun(Main.java:577)
	at org.eclipse.equinox.launcher.Main.run(Main.java:1410)
	at org.eclipse.equinox.launcher.Main.main(Main.java:1386)
Caused by: org.eclipse.incquery.runtime.rete.construction.RetePatternBuildException: Error during constructing Rete pattern matcher; please review Error Log and consult developers
	at org.eclipse.incquery.runtime.internal.matcherbuilder.EPMBuilder.construct(EPMBuilder.java:59)
	at org.eclipse.incquery.runtime.internal.matcherbuilder.EPMBuilder.construct(EPMBuilder.java:1)
	at org.eclipse.incquery.runtime.rete.boundary.ReteBoundary.construct(ReteBoundary.java:523)
	at org.eclipse.incquery.runtime.rete.boundary.ReteBoundary.accessProduction(ReteBoundary.java:455)
	at org.eclipse.incquery.runtime.rete.construction.ReteContainerBuildable.patternCallStub(ReteContainerBuildable.java:125)
	at org.eclipse.incquery.runtime.rete.construction.psystem.basicdeferred.PatternCallBasedDeferred.getSideStub(PatternCallBasedDeferred.java:115)
	at org.eclipse.incquery.runtime.rete.construction.psystem.basicdeferred.NegativePatternCall.doCheckOn(NegativePatternCall.java:55)
	at org.eclipse.incquery.runtime.rete.construction.psystem.DeferredPConstraint.checkOn(DeferredPConstraint.java:38)
	at org.eclipse.incquery.runtime.rete.construction.quasitree.QuasiTreeLayout$Scaffold.admitStub(QuasiTreeLayout.java:141)
	at org.eclipse.incquery.runtime.rete.construction.quasitree.QuasiTreeLayout$Scaffold.admitStub(QuasiTreeLayout.java:141)
	at org.eclipse.incquery.runtime.rete.construction.quasitree.QuasiTreeLayout$Scaffold.admitStub(QuasiTreeLayout.java:141)
	at org.eclipse.incquery.runtime.rete.construction.quasitree.QuasiTreeLayout$Scaffold.run(QuasiTreeLayout.java:92)
	at org.eclipse.incquery.runtime.rete.construction.quasitree.QuasiTreeLayout.layout(QuasiTreeLayout.java:49)
	at org.eclipse.incquery.runtime.internal.matcherbuilder.EPMBuildScaffold.construct(EPMBuildScaffold.java:58)
	at org.eclipse.incquery.runtime.internal.matcherbuilder.EPMBuilder.construct(EPMBuilder.java:57)
	at org.eclipse.incquery.runtime.internal.matcherbuilder.EPMBuilder.construct(EPMBuilder.java:1)
	at org.eclipse.incquery.runtime.rete.boundary.ReteBoundary.construct(ReteBoundary.java:523)
	at org.eclipse.incquery.runtime.rete.boundary.ReteBoundary.accessProduction(ReteBoundary.java:455)
	at org.eclipse.incquery.runtime.rete.matcher.ReteEngine$1.call(ReteEngine.java:179)
	at org.eclipse.incquery.runtime.rete.matcher.ReteEngine$1.call(ReteEngine.java:1)
	at org.eclipse.incquery.runtime.base.core.NavigationHelperImpl.coalesceTraversals(NavigationHelperImpl.java:677)
	at org.eclipse.incquery.runtime.internal.EMFPatternMatcherRuntimeContext.coalesceTraversals(EMFPatternMatcherRuntimeContext.java:193)
	at org.eclipse.incquery.runtime.rete.matcher.ReteEngine.accessMatcher(ReteEngine.java:175)
	at org.eclipse.incquery.runtime.api.impl.BaseGeneratedMatcher.accessMatcher(BaseGeneratedMatcher.java:42)
	... 45 more
Caused by: java.lang.NullPointerException
	at org.eclipse.incquery.runtime.base.core.NavigationHelperContentAdapter.getUniqueIdentifier(NavigationHelperContentAdapter.java:99)
	at org.eclipse.incquery.runtime.base.core.NavigationHelperContentAdapter.getInstanceSet(NavigationHelperContentAdapter.java:405)
	at org.eclipse.incquery.runtime.base.core.NavigationHelperImpl.getAllInstances(NavigationHelperImpl.java:339)
	at org.eclipse.incquery.runtime.internal.EMFPatternMatcherRuntimeContext.enumerateAllUnaryInstances(EMFPatternMatcherRuntimeContext.java:387)
	at org.eclipse.incquery.runtime.rete.boundary.EntityFeeder.feed(EntityFeeder.java:42)
	at org.eclipse.incquery.runtime.rete.boundary.ReteBoundary.accessUnaryRoot(ReteBoundary.java:200)
	at org.eclipse.incquery.runtime.rete.construction.ReteContainerBuildable.unaryTypeStub(ReteContainerBuildable.java:161)
	at org.eclipse.incquery.runtime.rete.construction.psystem.basicenumerables.TypeUnary.doCreateStub(TypeUnary.java:38)
	at org.eclipse.incquery.runtime.rete.construction.psystem.EnumerablePConstraint.getStub(EnumerablePConstraint.java:39)
	at org.eclipse.incquery.runtime.rete.construction.quasitree.QuasiTreeLayout$Scaffold.run(QuasiTreeLayout.java:91)
	at org.eclipse.incquery.runtime.rete.construction.quasitree.QuasiTreeLayout.layout(QuasiTreeLayout.java:49)
	at org.eclipse.incquery.runtime.internal.matcherbuilder.EPMBuildScaffold.construct(EPMBuildScaffold.java:58)
	at org.eclipse.incquery.runtime.internal.matcherbuilder.EPMBuilder.construct(EPMBuilder.java:57)
	... 68 more


I suspect that these problems are caused by some strangeness in our ecore files. We've generated them from UML models thus they contain some unconventional way of describing some of the elements. I will try to debug to the root cause of these exceptions.
Comment 12 Balazs Grill CLA 2013-02-13 03:35:18 EST
The builder fails if there is no "/" in the fragment of the EClass's URI. This can happen if the ecore file has ID set for the elements, like this:

<eClassifiers xsi:type="ecore:EClass" xmi:id="_mmtG__1917564164" name="EcucContainerValue"
            eSuperTypes="#_mmtG_270654108 #//presta/AR402/AutoSARArchitect/IVariationPointContainer">...

(some elements doesn't have id, as the one referenced by 'eSuperTypes'.)

in this case, the URI looks like the following:

platform:/resource/com.thyssenkrupp.presta.ar.model.ver402/model/AUTOSAR_4-0-2.ecore#_mmtG__1917564164

It seems that in this case the runtime URI could only be built by querying the ecore model and not just by transforming the URI.
Comment 13 Istvan Rath CLA 2013-02-13 08:24:13 EST
As it is unclear at the moment how to reproduce this issue in our environment, I'm postponing this issue to the next milestone (we'll continue to work on this, but we're pushing out M1 now).
Comment 14 Abel Hegedus CLA 2013-02-15 04:40:52 EST
These enormous exception traces are completely unreadable and there is only one significant line:

Caused by: java.lang.NullPointerException at org.eclipse.incquery.runtime.base.core.NavigationHelperContentAdapter.getUniqueIdentifier(NavigationHelperContentAdapter.java:99)

Obviously, the NPE conveys no information on what happened:
1. the passed EClassifier is an unresolvable proxy (since the URI was not generated properly)
2. EClassifier.getPackage returns null on the passed classifier
3. EPackage.getNsUri throws NPE

So I added a precondition to the method that will throw IllegalArgumentException when the passed classifier is a proxy and print out the unresolved URI as well.
Comment 15 Abel Hegedus CLA 2013-02-15 06:11:30 EST
Balázs, can you please check a few things:

1. Will the URI use the id in runtime as well, or would we need to transfrom it?

platform:/resource/com.thyssenkrupp.presta.ar.model.ver402/model/AUTOSAR_4-0-2.ecore#_mmtG__1917564164 is turned to which of the following?
 a) someUri#//packages/_mmtG__1917564164
 b) someUri#//packages/EcucContainerValue

2. What URIs are put into the package maps in EMFPatternURIHandler constructor?

Both the value of EcoreUtil.getURI(package) and calculateModifiedUri(package) would be nice. This should help in deciding what to put in the different partial fragments when the index is -1 (no / in fragment).

Thanks in advance!
Comment 16 Balazs Grill CLA 2013-02-15 07:20:46 EST
(In reply to comment #15)
1: ID will not be available through the reflective ecore model, therefore it shouldn't be used. Generally, the EClass URI should be in the following form:

"nsURI#//EClassName"

EMF can load a runtime ecore package by its namespace URI. Then this ecore package contains the referenced class directly.

2: Unfortunately i won't have time today to look up this info for you. I will try to do it this weekend.

B;
Comment 17 Abel Hegedus CLA 2013-02-15 11:03:18 EST
I have submitted an alternative implementation for handling ID-based URIs.

Balázs, please see if it helps in your case.
Comment 18 Balazs Grill CLA 2013-02-19 07:16:42 EST
(In reply to comment #17)

It's almost working.

it produces the following uri:
http:///M2/AR30/SWComponentTemplate/Composition.ecore#/CompositionType
instead of this:
http:///M2/AR30/SWComponentTemplate/Composition.ecore#//CompositionType

the platform cannot resolve the first URI causing an exception when trying to execute the queries.
Comment 19 Balazs Grill CLA 2013-02-19 09:14:21 EST
(In reply to comment #18)

It seems that this problem is solved by the patch I've posted for #398720.
Comment 20 Balazs Grill CLA 2013-02-19 09:49:04 EST
There are still some URIs which are generated incorrectly (I'm not yet sure why..)

Caused by: java.lang.IllegalArgumentException: Classifier org.eclipse.emf.ecore.impl.EClassImpl@9bdf6f9 (eProxyURI: http:///M2/AR30/SWComponentTemplate/Composition.ecore#//M2.AR30.SWComponentTemplate.Composition._instanceRef/AssemblyConnectorPrototype_provider) is an unresolved proxy
	at com.google.common.base.Preconditions.checkArgument(Preconditions.java:88)
	at org.eclipse.incquery.runtime.base.core.NavigationHelperContentAdapter.getUniqueIdentifier(NavigationHelperContentAdapter.java:100)
	at org.eclipse.incquery.runtime.base.core.NavigationHelperContentAdapter.getInstanceSet(NavigationHelperContentAdapter.java:408)
	at org.eclipse.incquery.runtime.base.core.NavigationHelperImpl.getAllInstances(NavigationHelperImpl.java:339)
	at org.eclipse.incquery.runtime.internal.EMFPatternMatcherRuntimeContext.enumerateAllUnaryInstances(EMFPatternMatcherRuntimeContext.java:387)
	at org.eclipse.incquery.runtime.rete.boundary.EntityFeeder.feed(EntityFeeder.java:42)
	at org.eclipse.incquery.runtime.rete.boundary.ReteBoundary.accessUnaryRoot(ReteBoundary.java:200)
	at org.eclipse.incquery.runtime.rete.construction.ReteContainerBuildable.unaryTypeStub(ReteContainerBuildable.java:161)
	at org.eclipse.incquery.runtime.rete.construction.psystem.basicenumerables.TypeUnary.doCreateStub(TypeUnary.java:38)
	at org.eclipse.incquery.runtime.rete.construction.psystem.EnumerablePConstraint.getStub(EnumerablePConstraint.java:39)
	at org.eclipse.incquery.runtime.rete.construction.quasitree.QuasiTreeLayout$Scaffold.run(QuasiTreeLayout.java:86)
	at org.eclipse.incquery.runtime.rete.construction.quasitree.QuasiTreeLayout.layout(QuasiTreeLayout.java:44)
	at org.eclipse.incquery.runtime.internal.matcherbuilder.EPMBuildScaffold.construct(EPMBuildScaffold.java:58)
	at org.eclipse.incquery.runtime.internal.matcherbuilder.EPMBuilder.construct(EPMBuilder.java:57)
	... 67 more
Comment 21 Zoltan Ujhelyi CLA 2013-02-19 12:21:06 EST
Can you elaborate what is the expected output and what was the input. Sadly, it is really hard to solve this issue without knowing what have gone wrong...

Or can you provide some small example that reproduces this issue?
Comment 22 Balazs Grill CLA 2013-02-20 02:43:46 EST
(In reply to comment #21)

The problem originates in calculateModifiedUri(EPackage). It returns a fragmented uri for packages that have a non-empty parent package. Why is that? I think every package should be identified by its nsURI.
Comment 23 Zoltan Ujhelyi CLA 2013-02-20 03:39:28 EST
Nope, the parent package stuff is needed. See the previously linked EMF forum thread for details: http://www.eclipse.org/forums/index.php/m/1008478/#msg_1008478

Basically, not nsUris, but parent nsUris are used to identify the package in case of nested packages.

I don't know, why is EMF implemented that way, but that works for both the Descent model introduced by Ábel's student and the ModEMBED model you presented.

The question here is why is it different in your other metamodel. Can you use a method like the following to get the expected type url from the corresponding instance model class?

private void printData(EObject content) {
    System.out.println(String.format("%s", EcoreUtil.getURI(content.eClass())));
}
Comment 24 Balazs Grill CLA 2013-02-20 04:46:12 EST
(In reply to comment #23)

I was wrong, your interpretation of the EClass URI is correct. I queried the runtime URIs of all EClasses from the registered EPackages, and compared them to the generated URIs. I've found out that the calculateModifiedUri should put the name of the EPackage in the fragment sections instead of the nsPrefix:

        while (nonEmptySuperPackage(p) != null) {
            fragments.add(p.getName());
            p = nonEmptySuperPackage(p);
            uriString = p.getNsURI();

        }

This way, most of the queries started working. Now I get some EClass URIs contain another package uri, not the one which contains that particular EClass, like this:

the globalEiqModel contains this: 
http:///AUTOSARRoot/M2/AUTOSARTemplates/ECUCParameterDefTemplate.ecore#//EcucContainerValue
instead of this:
http:///AUTOSARRoot/M2/AUTOSARTemplates/ECUCDescriptionTemplate.ecore#//EcucContainerValue

currently I'm trying to debug this..
Comment 25 Balazs Grill CLA 2013-02-20 05:25:15 EST
Created attachment 227324 [details]
Fixed URI calculation when EClass is identified by xmi:id

After applying these changes, the builder generates the URIs correctly, and all of our queries works.
Comment 26 Balazs Grill CLA 2013-02-20 05:31:35 EST
1] Did you agree to contribute the code to the Incquery project,
a) to be licensed as open source under the EPL agreement?;

Yes.

2] Did you [yourself] write the code you contributed to the Incquery project?

Yes.

3] Does anyone else have rights to the code you contributed? [For example, did
you have an agreement with an employer giving the employer rights to all code
you wrote during that time?]

No, I've written the code in my free time.
Comment 27 Zoltan Ujhelyi CLA 2013-02-20 05:38:21 EST
It seems, we have managed to fix this issue. Let's hope, everything's fine for now.
Comment 28 Istvan Rath CLA 2013-02-26 09:25:27 EST
Closing.