Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 361649 - CCE accessing overridden grammar with new serializer
Summary: CCE accessing overridden grammar with new serializer
Status: CLOSED FIXED
Alias: None
Product: TMF
Classification: Modeling
Component: Xtext (show other bugs)
Version: 2.0.1   Edit
Hardware: PC Windows Vista
: P3 critical (vote)
Target Milestone: RC1   Edit
Assignee: Project Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-10-21 09:28 EDT by Ed Willink CLA
Modified: 2017-10-31 11:16 EDT (History)
2 users (show)

See Also:
sebastian.zarnekow: juno+


Attachments
Editor start up failure (242.41 KB, text/plain)
2012-05-19 17:16 EDT, Ed Willink CLA
no flags Details
JUnit plugin failure trace (344.52 KB, text/plain)
2012-05-19 17:17 EDT, Ed Willink CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Ed Willink CLA 2011-10-21 09:28:47 EDT
With the new serializer I'm getting

java.lang.ClassCastException: org.eclipse.xtext.impl.AlternativesImpl cannot be cast to org.eclipse.xtext.RuleCall
	at org.eclipse.ocl.examples.xtext.essentialocl.services.EssentialOCLGrammarAccess$NavigatingArgExpCSElements.<init>(EssentialOCLGrammarAccess.java:1981)
	at org.eclipse.ocl.examples.xtext.essentialocl.services.EssentialOCLGrammarAccess.getNavigatingArgExpCSAccess(EssentialOCLGrammarAccess.java:2921)
	at org.eclipse.ocl.examples.xtext.essentialocl.services.EssentialOCLGrammarAccess.getNavigatingArgExpCSRule(EssentialOCLGrammarAccess.java:2925)
	at org.eclipse.ocl.examples.xtext.essentialocl.serializer.AbstractEssentialOCLSemanticSequencer.createSequence(AbstractEssentialOCLSemanticSequencer.java:257)
	at org.eclipse.ocl.examples.xtext.completeocl.serializer.AbstractCompleteOCLSemanticSequencer.sequence_NavigatingExpCS(AbstractCompleteOCLSemanticSequencer.java:1020)
	at org.eclipse.ocl.examples.xtext.completeocl.serializer.AbstractCompleteOCLSemanticSequencer.createSequence(AbstractCompleteOCLSemanticSequencer.java:411)
	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)

The relevant bad cast occurs in code that has not changed wityh the recent N-build:

	public class NavigatingArgExpCSElements extends AbstractParserRuleElementFinder {
		private final ParserRule rule = (ParserRule) GrammarUtil.findRuleForName(getGrammar(), "NavigatingArgExpCS");
		private final RuleCall cExpCSParserRuleCall = (RuleCall)rule.eContents().get(1);

The rule has two contained features: type and alternatives, so get(1) returns an AlternativesImpl that gives the CCE.

This code was not executed when using the old serializer, since the old serializer did not use the EssentialOCLGrammarAccess for the CompleteOCL grammar.

The rule in the base EssentialOCL grammar is:

NavigatingArgExpCS returns ExpCS: // Intended to be overridden
	ExpCS
	//	'?'	-- defined by Complete OCL
;

The overridden rule in the CompleteOCL grammar is:

NavigatingArgExpCS returns essentialocl::ExpCS:
	({OclMessageArgCS} '?')
	| ExpCS
;

The problem seems to be in the use of superSequencer in the generated AbstractCompleteOCLSemanticSequencer:
	
	/**
	 * Constraint:
	 *     (
	 *         (
	 *             namedExp=NavigatingExpCS_NavigatingExpCS_1_0 
	 *             (
	 *                 argument+=NavigatingArgCS 
	 *                 argument+=NavigatingCommaArgCS* 
	 *                 (argument+=NavigatingSemiArgCS argument+=NavigatingCommaArgCS*)? 
	 *                 (argument+=NavigatingBarArgCS argument+=NavigatingCommaArgCS*)?
	 *             )?
	 *         ) | 
	 *         namedExp=NavigatingExpCS_NavigatingExpCS_1_0
	 *     )
	 *
	 * Features:
	 *    namedExp[0, 2]
	 *    argument[0, *]
	 *         EXCLUDE_IF_UNSET namedExp
	 *         EXCLUDE_IF_SET namedExp
	 */
	protected void sequence_NavigatingExpCS(EObject context, NavigatingExpCS semanticObject) {
		superSequencer.createSequence(context, semanticObject);
	}
Comment 1 Sebastian Zarnekow CLA 2011-10-26 12:35:21 EDT
Most likely related to bug 347171
Comment 2 Moritz Eysholdt CLA 2012-05-18 10:25:39 EDT
hi Ed,

the problem that most likely caused this issue has been fixed. Could you verify if the problem still exists for you with the latest version of Xtext (i.e. the nightly build)?

thx
Comment 3 Ed Willink CLA 2012-05-19 16:34:06 EDT
After regenerating, looks good.

[Difficult to get the N-build past P2; had to uninstall Xtext first.]
Comment 4 Ed Willink CLA 2012-05-19 17:16:49 EDT
Created attachment 215906 [details]
Editor start up failure

(In reply to comment #3)
> After regenerating, looks good.

No. CRITICAL. It's really bad, although the fix enables me to re-activate some JUnit tests and they all pass when running standalone, when running as plugin tests I now get 68 failures mostly of the form shown below. Attempting to open editors interactively is also disastrous; same error (attached).

internalFindGrammar is new code, so I suspect some magic class-loader/injection must be occuring.
Comment 5 Ed Willink CLA 2012-05-19 17:17:57 EDT
Created attachment 215907 [details]
JUnit plugin failure trace
Comment 6 Ed Willink CLA 2012-05-19 17:20:56 EDT
Examples from attachments for Bugzilla search hits

Caused by: org.eclipse.emf.common.util.WrappedException: org.eclipse.xtext.resource.ClasspathUriResolutionException: java.lang.IllegalStateException: Couldn't find resource on classpath. URI was 'classpath:/org/eclipse/ocl/examples/xtext/oclinecore/OCLinEcore.xmi'
	at org.eclipse.xtext.parser.BaseEPackageAccess.loadResource(BaseEPackageAccess.java:57)
	at org.eclipse.xtext.parser.BaseEPackageAccess.loadGrammarFile(BaseEPackageAccess.java:44)
	at org.eclipse.xtext.service.GrammarProvider.getGrammar(GrammarProvider.java:57)
	at org.eclipse.ocl.examples.xtext.essentialocl.services.EssentialOCLGrammarAccess.internalFindGrammar(EssentialOCLGrammarAccess.java:2539)
	at org.eclipse.ocl.examples.xtext.essentialocl.services.EssentialOCLGrammarAccess.<init>(EssentialOCLGrammarAccess.java:2535)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
	at java.lang.reflect.Constructor.newInstance(Constructor.java:501)
	at com.google.inject.internal.DefaultConstructionProxyFactory$1.newInstance(DefaultConstructionProxyFactory.java:85)
	at com.google.inject.internal.ConstructorInjector.construct(ConstructorInjector.java:85)
----
Caused by: org.eclipse.xtext.resource.ClasspathUriResolutionException: java.lang.IllegalStateException: Couldn't find resource on classpath. URI was 'classpath:/org/eclipse/ocl/examples/xtext/oclinecore/OCLinEcore.xmi'
	at org.eclipse.xtext.resource.ClassloaderClasspathUriResolver.resolve(ClassloaderClasspathUriResolver.java:48)
	at org.eclipse.xtext.resource.XtextResourceSet.resolveClasspathURI(XtextResourceSet.java:36)
	at org.eclipse.xtext.resource.XtextResourceSet.access$0(XtextResourceSet.java:35)
	at org.eclipse.xtext.resource.XtextResourceSet$1.normalize(XtextResourceSet.java:105)
----
Caused by: org.eclipse.emf.common.util.WrappedException: org.eclipse.xtext.resource.ClasspathUriResolutionException: java.lang.IllegalStateException: Couldn't find resource on classpath. URI was 'classpath:/org/eclipse/ocl/examples/xtext/oclinecore/OCLinEcore.xmi'
	at org.eclipse.xtext.parser.BaseEPackageAccess.loadResource(BaseEPackageAccess.java:57)
	at org.eclipse.xtext.parser.BaseEPackageAccess.loadGrammarFile(BaseEPackageAccess.java:44)
	at org.eclipse.xtext.service.GrammarProvider.getGrammar(GrammarProvider.java:57)
	at org.eclipse.ocl.examples.xtext.essentialocl.services.EssentialOCLGrammarAccess.internalFindGrammar(EssentialOCLGrammarAccess.java:2539)
	at org.eclipse.ocl.examples.xtext.essentialocl.services.EssentialOCLGrammarAccess.<init>(EssentialOCLGrammarAccess.java:2535)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
	at java.lang.reflect.Constructor.newInstance(Constructor.java:501)
	at com.google.inject.internal.DefaultConstructionProxyFactory$1.newInstance(DefaultConstructionProxyFactory.java:85)
Comment 7 Ed Willink CLA 2012-05-19 17:28:43 EDT
If I revert the generated editor, but continue to use the N-build the new problem goes away, so the bug is in the generated code.
Comment 8 Sebastian Zarnekow CLA 2012-05-19 17:46:29 EDT
Your runtime modules are missing a binding of the right classloader.

see also bug 379903

The latest nightly will add that binding after regenerating the language.
Comment 9 Ed Willink CLA 2012-05-20 02:02:01 EDT
Thanks. N201205191342 works for me.
Comment 10 Eclipse Webmaster CLA 2017-10-31 11:04:59 EDT
Requested via bug 522520.

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

-M.