Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » [Xtext] NPE in ResourceDescriptionsProvider.createResourceDescriptions() after update to 2.9 / 2.10(Upgrading from global scope implementation of Xtext 2.8 to Xtext 2.9)
icon5.gif  [Xtext] NPE in ResourceDescriptionsProvider.createResourceDescriptions() after update to 2.9 / 2.10 [message #1736133] Mon, 27 June 2016 00:22 Go to next message
Torsten Juergeleit is currently offline Torsten JuergeleitFriend
Messages: 18
Registered: July 2009
Junior Member
I'm trying to update a standalone generator (using ImportURIScopingFragment and SimpleNamesFragment) from Xtext version 2.8.4 to 2.9.2 or 2.10.0.

Without any modifications other than changing the Xtext version in Maven POM and target definition I'm ending up with NPEs while loading / validating models with imports, e.g.
org.eclipse.emf.common.util.WrappedException: java.lang.NullPointerException
	at org.eclipse.xtext.resource.impl.ResourceDescriptionsProvider.createResourceDescriptions(ResourceDescriptionsProvider.java:159)
	at org.eclipse.xtext.resource.impl.ResourceDescriptionsProvider.getResourceDescriptions(ResourceDescriptionsProvider.java:113)
	at org.eclipse.xtext.scoping.impl.AbstractGlobalScopeProvider.getResourceDescriptions(AbstractGlobalScopeProvider.java:37)
	at org.eclipse.xtext.scoping.impl.ImportUriGlobalScopeProvider.getResourceDescriptions(ImportUriGlobalScopeProvider.java:66)
	at org.eclipse.xtext.scoping.impl.ImportUriGlobalScopeProvider.getScope(ImportUriGlobalScopeProvider.java:75)
	at org.eclipse.xtext.scoping.impl.AbstractGlobalScopeProvider.getScope(AbstractGlobalScopeProvider.java:50)
	at org.eclipse.xtext.scoping.impl.AbstractGlobalScopeDelegatingScopeProvider.getGlobalScope(AbstractGlobalScopeDelegatingScopeProvider.java:46)
	at org.eclipse.xtext.scoping.impl.AbstractGlobalScopeDelegatingScopeProvider.getGlobalScope(AbstractGlobalScopeDelegatingScopeProvider.java:42)
	at org.eclipse.xtext.scoping.impl.SimpleLocalScopeProvider.getScope(SimpleLocalScopeProvider.java:62)
	at org.eclipse.xtext.scoping.impl.AbstractDeclarativeScopeProvider.delegateGetScope(AbstractDeclarativeScopeProvider.java:72)
	at org.eclipse.xtext.scoping.impl.AbstractDeclarativeScopeProvider.getScope(AbstractDeclarativeScopeProvider.java:104)
	at org.eclipse.xtext.linking.impl.DefaultLinkingService.getScope(DefaultLinkingService.java:59)
	at org.eclipse.xtext.linking.impl.DefaultLinkingService.getLinkedObjects(DefaultLinkingService.java:119)
	at org.eclipse.xtext.linking.lazy.LazyLinkingResource.getEObject(LazyLinkingResource.java:247)
	at org.eclipse.xtext.linking.lazy.LazyLinkingResource.getEObject(LazyLinkingResource.java:222)
	at org.eclipse.xtext.linking.lazy.LazyLinkingResource.doResolveLazyCrossReference(LazyLinkingResource.java:189)
	at org.eclipse.xtext.linking.lazy.LazyLinkingResource.resolveLazyCrossReference(LazyLinkingResource.java:148)
	at org.eclipse.xtext.linking.lazy.LazyLinkingResource.resolveLazyCrossReferences(LazyLinkingResource.java:134)
	at org.eclipse.xtext.EcoreUtil2.resolveLazyCrossReferences(EcoreUtil2.java:498)
	at org.eclipse.xtext.validation.ResourceValidatorImpl.resolveProxies(ResourceValidatorImpl.java:161)
	at org.eclipse.xtext.validation.ResourceValidatorImpl.validate(ResourceValidatorImpl.java:74)
	at org.sculptor.generator.workflow.SculptorGeneratorWorkflow$2.apply(SculptorGeneratorWorkflow.java:229)
	at org.sculptor.generator.workflow.SculptorGeneratorWorkflow$2.apply(SculptorGeneratorWorkflow.java:219)
	at org.eclipse.xtext.xbase.lib.IteratorExtensions.forall(IteratorExtensions.java:278)
	at org.eclipse.xtext.xbase.lib.IterableExtensions.forall(IterableExtensions.java:237)
	at org.sculptor.generator.workflow.SculptorGeneratorWorkflow.validateResources(SculptorGeneratorWorkflow.java:281)
	at org.sculptor.generator.workflow.SculptorGeneratorWorkflow.run(SculptorGeneratorWorkflow.java:108)
	at org.sculptor.generator.SculptorGeneratorRunner.run(SculptorGeneratorRunner.java:50)


Here it seems that in ResourceDescriptionsProvider
result = ChunkedResourceDescriptions.findInEmfObject(resourceSet);
if (result == null) {
  result = createResourceDescriptions();
}

no result was return from findInEmfObject() and no IResourceDescriptions instance was injected in
@Inject(optional = true)
private Provider<IResourceDescriptions> resourceDescriptions;


Now I'm wondering which changes are necessary to update from the global scope implementation of Xtext 2.8 to the one of version 2.9.

/Torsten

[Updated on: Mon, 27 June 2016 00:27]

Report message to a moderator

Re: [Xtext] NPE in ResourceDescriptionsProvider.createResourceDescriptions() after update to 2.9 / 2 [message #1736134 is a reply to message #1736133] Mon, 27 June 2016 04:02 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14735
Registered: July 2009
Senior Member
Hi Torsten,

how to reproduce this?
what did you exactly do when updating?

the ImportURIScopingFragment did and still does add bindings for

public Class<? extends org.eclipse.xtext.scoping.IGlobalScopeProvider> bindIGlobalScopeProvider() {
		return org.eclipse.xtext.scoping.impl.ImportUriGlobalScopeProvider.class;
	}
....
	// contributed by org.eclipse.xtext.generator.builder.BuilderIntegrationFragment
	public void configureIResourceDescriptions(com.google.inject.Binder binder) {
		binder.bind(org.eclipse.xtext.resource.IResourceDescriptions.class).to(org.eclipse.xtext.resource.impl.ResourceSetBasedResourceDescriptions.class);
	}


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Day Job: https://www.everest-systems.com
Re: [Xtext] NPE in ResourceDescriptionsProvider.createResourceDescriptions() after update to 2.9 / 2 [message #1736151 is a reply to message #1736134] Mon, 27 June 2016 07:36 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14735
Registered: July 2009
Senior Member
the problem i have is https://github.com/eclipse/xtext-core/issues/17

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Day Job: https://www.everest-systems.com
Re: [Xtext] NPE in ResourceDescriptionsProvider.createResourceDescriptions() after update to 2.9 / 2 [message #1736213 is a reply to message #1736151] Mon, 27 June 2016 14:06 Go to previous messageGo to next message
Torsten Juergeleit is currently offline Torsten JuergeleitFriend
Messages: 18
Registered: July 2009
Junior Member
Christian Dietrich wrote on Mon, 27 June 2016 07:36
the problem i have is https://github.com/eclipse/xtext-core/issues/17


Thanks for digging into this.
Yes, this serializer issue is the next on my list of issues with Xtext 2.9. As a temporarily work around I'm using XtextTestBase.testFileNoSerializer() instead of XtextTestBase.testFile() in the tests.

Btw. do you know a public p2 repository containing the xtext.unittesting bundle? Unluckily the old p2 repository on google code isn't available anymore.

/Torsten
Re: [Xtext] NPE in ResourceDescriptionsProvider.createResourceDescriptions() after update to 2.9 / 2 [message #1736217 is a reply to message #1736134] Mon, 27 June 2016 14:21 Go to previous messageGo to next message
Torsten Juergeleit is currently offline Torsten JuergeleitFriend
Messages: 18
Registered: July 2009
Junior Member
Christian Dietrich wrote on Mon, 27 June 2016 04:02

how to reproduce this?


This issue is reproducible with the unit / integration tests (after replacing the calls to XtextTestBase.testFile() with XtextTestBase.testFileNoSerializer() - due to https://github.com/eclipse/xtext-core/issues/17), e.g. SculptorGeneratorWorkflowTest.assertRunWorkflow().

Christian Dietrich wrote on Mon, 27 June 2016 04:02

what did you exactly do when updating?


I only updated the Xtext version number in the parent pom and the target definition. The MWE2 workflow is unchanged (no migration to the new Xtext generator architecture yet).

Christian Dietrich wrote on Mon, 27 June 2016 04:02

the ImportURIScopingFragment did and still does add bindings for


Yes, these bindings are available in the generated language runtime.

But there's no provider for the optional binding of "private Provider<IResourceDescriptions> resourceDescriptions;" (defined in ResourceDescriptionsProvider). So at runtime this field is not initialized and ResourceDescriptionsProvider.createResourceDescriptions() throws an NPE.

/Torsten
Re: [Xtext] NPE in ResourceDescriptionsProvider.createResourceDescriptions() after update to 2.9 / 2 [message #1736222 is a reply to message #1736217] Mon, 27 June 2016 15:01 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14735
Registered: July 2009
Senior Member
the problem is here

Injector bootstrapInjector = Guice.createInjector(new ConfigurationProviderModule());
try {
return bootstrapInjector.createChildInjector(
new ChainOverrideAwareModule(bootstrapInjector, DslTransformation.class, Transformation.class,
Class.forName("org.sculptor.generator.template.RootTmpl")), new SculptordslRuntimeModule());

that basically ignores SculptordslRuntimeModule IResourceDescriptions binding (and many others)


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Day Job: https://www.everest-systems.com
Re: [Xtext] NPE in ResourceDescriptionsProvider.createResourceDescriptions() after update to 2.9 / 2 [message #1736239 is a reply to message #1736222] Mon, 27 June 2016 18:11 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14735
Registered: July 2009
Senior Member
the following looks better

Injector bootstrapInjector = Guice.createInjector(new ConfigurationProviderModule(), new SculptordslRuntimeModule());
try {
return bootstrapInjector.createChildInjector(
new ChainOverrideAwareModule(bootstrapInjector, DslTransformation.class, Transformation.class,
Class.forName("org.sculptor.generator.template.RootTmpl"))


);


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Day Job: https://www.everest-systems.com
Re: [Xtext] NPE in ResourceDescriptionsProvider.createResourceDescriptions() after update to 2.9 / 2 [message #1736256 is a reply to message #1736222] Mon, 27 June 2016 22:46 Go to previous messageGo to next message
Torsten Juergeleit is currently offline Torsten JuergeleitFriend
Messages: 18
Registered: July 2009
Junior Member
Christian Dietrich wrote on Mon, 27 June 2016 15:01
the problem is here

Injector bootstrapInjector = Guice.createInjector(new ConfigurationProviderModule());
try {
return bootstrapInjector.createChildInjector(
new ChainOverrideAwareModule(bootstrapInjector, DslTransformation.class, Transformation.class,
Class.forName("org.sculptor.generator.template.RootTmpl")), new SculptordslRuntimeModule());

that basically ignores SculptordslRuntimeModule IResourceDescriptions binding (and many others)


Christian, you nailed it! Excellent finding.

Sculptors configuration subsystem in the parent injector is implemented with Xtend. So in the parent injector Xtexts runtime is initialized via Xtends runtime library. When the Sculptors language runtime is initialized in the child injector it's bound to the already initialized Xtext runtime from the parent injector. This explains why Sculptors bindings are not recognized.

This whole xtend-based-parent-with-sculptor-child-injector approach has been working with Xtext up to version 2.8. Starting with Xtext 2.9 using Xtend in the parent injector is no option anymore Sad

/Torsten
Re: [Xtext] NPE in ResourceDescriptionsProvider.createResourceDescriptions() after update to 2.9 / 2 [message #1736258 is a reply to message #1736239] Mon, 27 June 2016 23:13 Go to previous messageGo to next message
Torsten Juergeleit is currently offline Torsten JuergeleitFriend
Messages: 18
Registered: July 2009
Junior Member
Christian Dietrich wrote on Mon, 27 June 2016 18:11
the following looks better

Injector bootstrapInjector = Guice.createInjector(new ConfigurationProviderModule(), new SculptordslRuntimeModule());
try {
return bootstrapInjector.createChildInjector(
new ChainOverrideAwareModule(bootstrapInjector, DslTransformation.class, Transformation.class,
Class.forName("org.sculptor.generator.template.RootTmpl"))
);


Yes, moving Sculptors language runtime (including the Xtext runtime) to the parent injector solves the issues with the missing IResourceDescriptors binding.

But another issue is popping up now:

com.google.inject.ConfigurationException: Guice configuration errors:

1) Unable to create binding for org.sculptor.generator.transform.DslTransformation. It was already configured on one or more child injectors or private modules
    bound at org.sculptor.generator.chain.ChainOverrideAwareModule.buildChainForClass(ChainOverrideAwareModule.java:156)
  If it was in a PrivateModule, did you forget to expose the binding?
  while locating org.sculptor.generator.transform.DslTransformation

1 error


This is because SculptorGeneratorWorkflow uses "@Inject var Injector injector" which binds the wrong injector (the parent one instead the child one #973 @Inject Injector does not work with child injectors).

So it seems that I've to let go using Xtend in parent injector Crying or Very Sad

/Torsten
Re: [Xtext] NPE in ResourceDescriptionsProvider.createResourceDescriptions() after update to 2.9 / 2 [message #1736260 is a reply to message #1736258] Tue, 28 June 2016 03:24 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14735
Registered: July 2009
Senior Member
I am not sure what your child injector intends but why not Module.overrides(...)

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Day Job: https://www.everest-systems.com
Re: [Xtext] NPE in ResourceDescriptionsProvider.createResourceDescriptions() after update to 2.9 / 2 [message #1736298 is a reply to message #1736260] Tue, 28 June 2016 10:15 Go to previous message
Torsten Juergeleit is currently offline Torsten JuergeleitFriend
Messages: 18
Registered: July 2009
Junior Member
Christian Dietrich wrote on Tue, 28 June 2016 03:24
I am not sure what your child injector intends but why not Module.overrides(...)


The parent injector provides the configuration subsystem needed for newing a module which is used to initialize the child injector.

Ok, I dropped the idea of reusing an already initialized configuration in a child injector and refactored the injector setup as follows:

public class SculptorGeneratorSetup extends SculptordslStandaloneSetup {

	@Override
	public Injector createInjector() {
		ConfigurationProvider configurationProvider = Guice.createInjector(new ConfigurationProviderModule()).getInstance(ConfigurationProvider.class);
		try {
			return Guice.createInjector(new ConfigurationProviderModule(), new SculptordslRuntimeModule(),
					new ChainOverrideAwareModule(configurationProvider, DslTransformation.class, Transformation.class,
							Class.forName("org.sculptor.generator.template.RootTmpl")));
		} catch (ClassNotFoundException e) {
			throw new RuntimeException("Emergency - 'RootTmpl' not available on classpath");
		}
	}

}


Now the configuration subsystem is instantiated twice. But without using a child injector the binding of Xtext 2.9+ works Shocked

Next I reintroduced the child injector as follows:

public class SculptorGeneratorSetup extends SculptordslStandaloneSetup {

	@Override
	public Injector createInjector() {
		ConfigurationProvider configurationProvider = Guice.createInjector(new ConfigurationProviderModule()).getInstance(ConfigurationProvider.class);
		try {
			return Guice.createInjector().createChildInjector(new ConfigurationProviderModule(), new SculptordslRuntimeModule(),
					new ChainOverrideAwareModule(configurationProvider, DslTransformation.class, Transformation.class,
							Class.forName("org.sculptor.generator.template.RootTmpl")));
		} catch (ClassNotFoundException e) {
			throw new RuntimeException("Emergency - 'RootTmpl' not available on classpath");
		}
	}

}


Now the NPE due to unbound IResourceDescriptions is back again Confused

So it seems that the inner workings of Xtext 2.9+ have been changed with regards to Guice interceptor handling. Maybe Xtext is internally using interceptor injection now.

I'll check this with Xtext 2.8.

/Torsten
Previous Topic:Backslash in string
Next Topic:When to use XExpression, XblockExpression and just plain parser rule
Goto Forum:
  


Current Time: Fri Dec 06 04:50:18 GMT 2024

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

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

Back to the top