Community
Participate
Working Groups
Xtext Complete SDK 2.8.0.v201503090534 Hi, since I changed my .xtext file slightly (introduced a new Element) one of my unit tests is failing with a null point exception: java.lang.NullPointerException at org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.getEObject(ResourceSetImpl.java:220) at org.eclipse.xtext.junit4.validation.ValidationTestHelper$5.apply(ValidationTestHelper.java:389) at org.eclipse.xtext.junit4.validation.ValidationTestHelper$5.apply(ValidationTestHelper.java:1) at com.google.common.collect.Iterators$7.computeNext(Iterators.java:647) at com.google.common.collect.AbstractIterator.tryToComputeNext(AbstractIterator.java:143) at com.google.common.collect.AbstractIterator.hasNext(AbstractIterator.java:138) at com.google.common.collect.Iterables.isEmpty(Iterables.java:988) at org.eclipse.xtext.junit4.validation.ValidationTestHelper.assertIssue(ValidationTestHelper.java:284) at org.eclipse.xtext.junit4.validation.ValidationTestHelper.assertIssue(ValidationTestHelper.java:109) at org.eclipse.xtext.junit4.validation.ValidationTestHelper.assertIssue(ValidationTestHelper.java:101) at org.eclipse.xtext.junit4.validation.ValidationTestHelper.assertError(ValidationTestHelper.java:93) at com.mycompany.lab.mde.tests.ParserTest.RealVariable_MustNotHaveValueMappingTest(ParserTest.java:46) 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.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47) at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44) at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17) at org.eclipse.xtext.junit4.XtextRunner$1.evaluate(XtextRunner.java:49) at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50) at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238) at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63) at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236) at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53) at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229) at org.junit.runners.ParentRunner.run(ParentRunner.java:309) at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50) at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192) The reason for this is, that the Issues getUriToProblem() returns null. That again happens because setUriToProblem is fed with a null returned by castedDiagnostic.getUriToProblem() [code]issue.setUriToProblem(castedDiagnostic.getUriToProblem());[/code] The reason that this methid returns a null is because [code]node.getSemanticElement()[/code] called within the getUriToProblem function returns a nulll. This in turn is because the parent attribute of the correspronding AbstractNode object is null: [code]@Override public EObject getSemanticElement() { if (parent == null) return null; return parent.getSemanticElement(); }[/code] This AbstractNode is the root element of my application. Does this help? What I dont understand is why it worked before. This is what I changed: Before: [code]grammar com.mycompany.lab.Mde with org.eclipse.xtext.common.Terminals generate mde "http://www.mycopmany.com/lab/Mde" MdeApplication: 'MDE Application' name=MultiLangString version = FLOAT ...[/code] After: [code]grammar com.mycompany.lab.Mde with org.eclipse.xtext.common.Terminals generate mde "http://www.mycopmany.com/lab/Mde" Root: MdeApplication|Dictionary; Dictionary: {Dictionary} 'MDE' 'Dictionary' entries+=Entry*; Entry: name=STRING '/' en=STRING; MdeApplication: 'MDE' 'Application' name=MultiLangString version = FLOAT ...[/code] [/code][/quote]
Sorry for coming back so late. I tried to reproduce the issue but it seems that some context is missing. The error occurs when you try to assert some error. The context of the error is not clear here. What does "No value mapping" mean in the context of your extracted grammar? One thing I noticed in your grammar is that you have an alternative in the root definition: Root: MdeApplication|Dictionary; This is quite unusual. The root usually always is an element with assignments, and elements assigned could be an alternative: Root: elements += Element; Element: MdeApplication|Dictionary; Does that work for you? If not, please elaborate more on how the error can be reproduced.