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

Bug 370158

Summary: JvmReference causes NullPointerException
Product: [Modeling] TMF Reporter: Hendrik Renken <funsheep>
Component: XtextAssignee: Project Inbox <tmf.xtext-inbox>
Status: CLOSED FIXED QA Contact:
Severity: critical    
Priority: P3 CC: moritz.eysholdt, sebastian.zarnekow, sven.efftinge
Version: 2.3.0Flags: sven.efftinge: juno+
Target Milestone: RC2   
Hardware: Macintosh   
OS: Mac OS X - Carbon (unsup.)   
Whiteboard:
Attachments:
Description Flags
Testcase that crashes the Mwe2-Workflow with a NPE
none
The Mwe2-Workflow none

Description Hendrik Renken CLA 2012-01-30 15:01:52 EST
Build Identifier: Version: 3.7.1 Build id: M20110909-1335

Im using the attached grammar. The grammar causes the exception:

java.lang.NullPointerException
	at org.eclipse.xtext.generator.grammarAccess.GrammarAccessFragment.replaceResourceURIsWithNsURIs(GrammarAccessFragment.java:118)
	at org.eclipse.xtext.generator.grammarAccess.GrammarAccessFragment.addAllGrammarsToResource(GrammarAccessFragment.java:109)
	at org.eclipse.xtext.generator.grammarAccess.GrammarAccessFragment.addAllGrammarsToResource(GrammarAccessFragment.java:111)
	at org.eclipse.xtext.generator.grammarAccess.GrammarAccessFragment.generate(GrammarAccessFragment.java:76)
	at org.eclipse.xtext.generator.CompositeGeneratorFragment.generate(CompositeGeneratorFragment.java:81)
	at org.eclipse.xtext.generator.LanguageConfig.generate(LanguageConfig.java:108)
	at org.eclipse.xtext.generator.Generator.generate(Generator.java:352)
	at org.eclipse.xtext.generator.Generator.invokeInternal(Generator.java:126)
	at org.eclipse.emf.mwe.core.lib.AbstractWorkflowComponent.invoke(AbstractWorkflowComponent.java:126)
	at org.eclipse.emf.mwe.core.lib.Mwe2Bridge.invoke(Mwe2Bridge.java:34)
	at org.eclipse.emf.mwe.core.lib.AbstractWorkflowComponent.invoke(AbstractWorkflowComponent.java:201)
	at org.eclipse.emf.mwe2.runtime.workflow.AbstractCompositeWorkflowComponent.invoke(AbstractCompositeWorkflowComponent.java:35)
	at org.eclipse.emf.mwe2.runtime.workflow.Workflow.run(Workflow.java:19)
	at org.eclipse.emf.mwe2.launch.runtime.Mwe2Runner.run(Mwe2Runner.java:97)
	at org.eclipse.emf.mwe2.launch.runtime.Mwe2Runner.run(Mwe2Runner.java:73)
	at org.eclipse.emf.mwe2.launch.runtime.Mwe2Runner.run(Mwe2Runner.java:64)
	at org.eclipse.emf.mwe2.launch.runtime.Mwe2Runner.run(Mwe2Runner.java:55)
	at org.eclipse.emf.mwe2.launch.runtime.Mwe2Launcher.run(Mwe2Launcher.java:74)
	at org.eclipse.emf.mwe2.launch.runtime.Mwe2Launcher.main(Mwe2Launcher.java:35)

Reproducible: Always

Steps to Reproduce:
1. Try to compile the attached grammar klass.xtext
Comment 1 Hendrik Renken CLA 2012-01-30 15:03:46 EST
Created attachment 210278 [details]
Testcase that crashes the Mwe2-Workflow with a NPE

The testcase. Just try to compile it with the Mwe2-Workflow.
Comment 2 Hendrik Renken CLA 2012-01-30 15:04:32 EST
Created attachment 210279 [details]
The Mwe2-Workflow

The workflow file. Execute this to cause the NPE.
Comment 3 Moritz Eysholdt CLA 2012-05-29 04:45:57 EDT
workaround: register the Xbase package ;)

This snippet is copied from your workflow:
---
bean = StandaloneSetup {
        scanClassPath = true
        platformUri = "${runtimeProject}/.."
        // The following two lines can be removed, if Xbase is not used.
//        registerGeneratedEPackage = "org.eclipse.xtext.xbase.XbasePackage"
        registerGenModelFile = "platform:/resource/org.eclipse.xtext.xbase/model/Xbase.genmodel"
    }
---


The NPE is not being thrown if registerGeneratedEPackage is enabled.
Comment 4 Moritz Eysholdt CLA 2012-05-29 05:09:17 EDT
Further analysis shows that a metamodel-import inside the super-grammar (which is Xbase) is null.

This error, however, is nerver reported as such since LanguageConfig.setUri(String) only validates the grammar that is being loaded, but not its "used" grammars (aka supergrammars).

Suggested fix: validate supergrammars in LanguageConfig.setUri(String).
Comment 5 Moritz Eysholdt CLA 2012-05-29 05:55:03 EDT
fixed in 
http://git.eclipse.org/c/tmf/org.eclipse.xtext.git/commit/?id=d289400be065f02f7afe5acf5867a17d28888bd1

The imports of all grammars (the one that is loaded and all imported grammars) will now be validated when the grammar is being loaded.

The fix will be available with the RC2 release.
Comment 6 Eclipse Webmaster CLA 2017-10-31 11:05:05 EDT
Requested via bug 522520.

-M.
Comment 7 Eclipse Webmaster CLA 2017-10-31 11:16:27 EDT
Requested via bug 522520.

-M.