Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Null pointer when serializing cross references
Null pointer when serializing cross references [message #868097] Tue, 01 May 2012 16:41 Go to next message
Andrew Gacek is currently offline Andrew GacekFriend
Messages: 32
Registered: October 2011
Member
I have a simple expression language with cross references. When I try to serialize it, I get a null pointer exception (see bottom). It appears to be something related to scoping, but I don't know what. My language does not yet have any interesting scope: everything is global at the file level. Here is what I have in my mwe2 config:

// scoping and exporting API
fragment = scoping.ImportURIScopingFragment {}
fragment = exporting.SimpleNamesFragment {}

fragment = builder.BuilderIntegrationFragment {}


Is there something I'm doing wrong which is triggering this error?

Thanks,
Andrew

java.lang.NullPointerException
	at org.eclipse.xtext.scoping.impl.SimpleLocalScopeProvider$2.iterator(SimpleLocalScopeProvider.java:71)
	at com.google.common.collect.Iterables$8.iterator(Iterables.java:687)
	at com.google.common.collect.Iterables$6.iterator(Iterables.java:582)
	at org.eclipse.xtext.scoping.impl.MultimapBasedSelectable.setExportedObjects(MultimapBasedSelectable.java:97)
	at org.eclipse.xtext.scoping.impl.MultimapBasedSelectable.<init>(MultimapBasedSelectable.java:36)
	at org.eclipse.xtext.scoping.impl.SimpleLocalScopeProvider.getAllDescriptions(SimpleLocalScopeProvider.java:75)
	at org.eclipse.xtext.scoping.impl.SimpleLocalScopeProvider$1.get(SimpleLocalScopeProvider.java:57)
	at org.eclipse.xtext.scoping.impl.SimpleLocalScopeProvider$1.get(SimpleLocalScopeProvider.java:1)
	at org.eclipse.xtext.util.OnChangeEvictingCache.get(OnChangeEvictingCache.java:67)
	at org.eclipse.xtext.scoping.impl.SimpleLocalScopeProvider.getScope(SimpleLocalScopeProvider.java:54)
	at org.eclipse.xtext.scoping.impl.AbstractDeclarativeScopeProvider.delegateGetScope(AbstractDeclarativeScopeProvider.java:72)
	at org.eclipse.xtext.scoping.impl.AbstractDeclarativeScopeProvider.getScope(AbstractDeclarativeScopeProvider.java:102)
	at org.eclipse.xtext.serializer.tokens.CrossReferenceSerializer.serializeCrossRef(CrossReferenceSerializer.java:100)
	at org.eclipse.xtext.serializer.acceptor.SequenceFeeder.getToken(SequenceFeeder.java:448)
	at org.eclipse.xtext.serializer.acceptor.SequenceFeeder.accept(SequenceFeeder.java:214)
	at org.xtext.example.mydsl.serializer.AbstractMyDslSemanticSequencer.sequence_Atom(AbstractMyDslSemanticSequencer.java:131)
	at org.xtext.example.mydsl.serializer.AbstractMyDslSemanticSequencer.createSequence(AbstractMyDslSemanticSequencer.java:76)
	at org.eclipse.xtext.serializer.acceptor.SequenceFeeder.acceptAction(SequenceFeeder.java:292)
	at org.eclipse.xtext.serializer.acceptor.SequenceFeeder.accept(SequenceFeeder.java:90)
	at org.xtext.example.mydsl.serializer.AbstractMyDslSemanticSequencer.sequence_Expr(AbstractMyDslSemanticSequencer.java:200)
	at org.xtext.example.mydsl.serializer.AbstractMyDslSemanticSequencer.createSequence(AbstractMyDslSemanticSequencer.java:60)
	at org.eclipse.xtext.serializer.acceptor.SequenceFeeder.acceptEObjectRuleCall(SequenceFeeder.java:299)
	at org.eclipse.xtext.serializer.acceptor.SequenceFeeder.acceptRuleCall(SequenceFeeder.java:325)
	at org.eclipse.xtext.serializer.acceptor.SequenceFeeder.accept(SequenceFeeder.java:215)
	at org.xtext.example.mydsl.serializer.AbstractMyDslSemanticSequencer.sequence_Equation(AbstractMyDslSemanticSequencer.java:182)
	at org.xtext.example.mydsl.serializer.AbstractMyDslSemanticSequencer.createSequence(AbstractMyDslSemanticSequencer.java:66)
	at org.eclipse.xtext.serializer.acceptor.SequenceFeeder.acceptEObjectRuleCall(SequenceFeeder.java:299)
	at org.eclipse.xtext.serializer.acceptor.SequenceFeeder.acceptRuleCall(SequenceFeeder.java:325)
	at org.eclipse.xtext.serializer.acceptor.SequenceFeeder.accept(SequenceFeeder.java:239)
	at org.eclipse.xtext.serializer.sequencer.BacktrackingSemanticSequencer.accept(BacktrackingSemanticSequencer.java:380)
	at org.eclipse.xtext.serializer.sequencer.BacktrackingSemanticSequencer.createSequence(BacktrackingSemanticSequencer.java:423)
	at org.xtext.example.mydsl.serializer.AbstractMyDslSemanticSequencer.sequence_Model(AbstractMyDslSemanticSequencer.java:230)
	at org.xtext.example.mydsl.serializer.AbstractMyDslSemanticSequencer.createSequence(AbstractMyDslSemanticSequencer.java:92)
	at org.eclipse.xtext.serializer.impl.Serializer.serialize(Serializer.java:84)
	at org.eclipse.xtext.serializer.impl.Serializer.serialize(Serializer.java:103)
	at org.eclipse.xtext.serializer.impl.Serializer.serialize(Serializer.java:117)
	at org.eclipse.xtext.serializer.impl.Serializer.serialize(Serializer.java:50)
	at org.xtext.example.mydsl.plugin.actions.SampleAction$1.exec(SampleAction.java:79)
	at org.xtext.example.mydsl.plugin.actions.SampleAction$1.exec(SampleAction.java:1)
	at org.eclipse.xtext.util.concurrent.AbstractReadWriteAcces.readOnly(AbstractReadWriteAcces.java:32)
	at org.eclipse.xtext.ui.editor.model.XtextDocument.readOnly(XtextDocument.java:78)
	at org.xtext.example.mydsl.plugin.actions.SampleAction.run(SampleAction.java:65)
	at org.eclipse.ui.internal.PluginAction.runWithEvent(PluginAction.java:251)
	at org.eclipse.ui.internal.WWinPluginAction.runWithEvent(WWinPluginAction.java:229)
	at org.eclipse.jface.action.ActionContributionItem.handleWidgetSelection(ActionContributionItem.java:584)
	at org.eclipse.jface.action.ActionContributionItem.access$2(ActionContributionItem.java:501)
	at org.eclipse.jface.action.ActionContributionItem$5.handleEvent(ActionContributionItem.java:411)
	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:4066)
	at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3657)
	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.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)
Re: Null pointer when serializing cross references [message #868175 is a reply to message #868097] Tue, 01 May 2012 17:30 Go to previous messageGo to next message
Andrew Gacek is currently offline Andrew GacekFriend
Messages: 32
Registered: October 2011
Member
From poking around in the debugger, it seems that the error is caused because .eResource() returns null for everything that the serializer is returning. Do I need to somehow assign a resource prior to serializing? Here is how I currently serialize:

Injector injector = Guice.createInjector(new MyDslRuntimeModule());
Serializer serializer = injector.getInstance(Serializer.class);
String text = serializer.serialize(model);
Re: Null pointer when serializing cross references [message #868214 is a reply to message #868175] Tue, 01 May 2012 17:57 Go to previous message
Andrew Gacek is currently offline Andrew GacekFriend
Messages: 32
Registered: October 2011
Member
I have resolved this issue by avoiding calling the serializer directly. Instead I have roughly

document.readOnly(new IUnitOfWork<Void, XtextResource>() {
	public java.lang.Void exec(XtextResource state) throws Exception {
		Model model = (Model) state.getContents().get(0);
		model = ECoreUtil.copy(model);

		// Do some transformations on model

		URI uri = getOutputURI(state.getURI());
		Resource res = state.getResourceSet().createResource(uri);
		res.getContents().add(model);
		res.save(null);

		return null;
	}
});


and

private URI getOutputURI(URI uri) {
	String filename = uri.lastSegment();
	uri = uri.trimSegments(1);
	int i = filename.lastIndexOf(".");
	uri = uri.appendSegment(filename.substring(0, i) + ".transformed" + filename.substring(i));
	return uri;
}


I'm still not sure if this is the proper way to do things, but at least it seems to work.

-Andrew
Previous Topic:How to unit test global scoping
Next Topic:EOF not matching RULE_EOL
Goto Forum:
  


Current Time: Mon Nov 30 18:18:00 GMT 2020

Powered by FUDForum. Page generated in 0.01394 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top