Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 360834 - Infinite Loop on unordered groups if all elements are optional
Summary: Infinite Loop on unordered groups if all elements are optional
Status: CLOSED FIXED
Alias: None
Product: TMF
Classification: Modeling
Component: Xtext (show other bugs)
Version: 2.1.0   Edit
Hardware: PC Windows 7
: P3 normal (vote)
Target Milestone: SR2   Edit
Assignee: Project Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-10-13 10:11 EDT by Daniel Mising name CLA
Modified: 2017-09-19 17:08 EDT (History)
1 user (show)

See Also:
sebastian.zarnekow: indigo+


Attachments
A demo grammar causing the problem (704 bytes, text/plain)
2011-10-13 10:13 EDT, Daniel Mising name CLA
no flags Details
A second grammar without recursive rule calls. (732 bytes, text/plain)
2011-10-13 10:23 EDT, Daniel Mising name CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Daniel Mising name CLA 2011-10-13 10:11:31 EDT
Build Identifier: 20110615-0604

If you define an unordered group where all elements are optional (like class modifiers in Java) it leads into an infinite/endless loop if you hit code-completion.  

If you test the sample you will notice that the endless loop is caused by the ui.InternalMyDslParser.rule__ClassDeclaration__MembersAssignment_4 method. It starts searching for proposals within it's nested rule and this leads to an infinite recursion. 


Reproducible: Always

Steps to Reproduce:
1. Create a new empty xtext project
2. Copy the grammar from the attachment into the project and run the MWE2
3. Start Eclipse
4. Create a new empty DSL file 
5. Place the cursor on the first line and hit CTRL+Space
6. The proposal provider will end up in an endless loop.
Comment 1 Daniel Mising name CLA 2011-10-13 10:13:33 EDT
Created attachment 205128 [details]
A demo grammar causing the problem
Comment 2 Daniel Mising name CLA 2011-10-13 10:23:30 EDT
I added a second sample grammar which demonstrates the problem. This time there's no recursion in the grammar but the error is caused by the unordered group. The Parser tries to find all available proposals but gets stuck because all elements are optional. (That's how it seems to be)

The parser loops within rule__ClassDeclaration__Group__4__Impl because the input.LA(1) always returns EOF in this case the rule__ClassDeclaration__MembersAssignment_4 is called over and over. 
Somehow the empty group causes the parser to never change the alt3 value and there the problem starts. 

To test the second grammar: Simply add an empty file and hit ctrl+space
Comment 3 Daniel Mising name CLA 2011-10-13 10:23:52 EDT
Created attachment 205129 [details]
A second grammar without recursive rule calls.
Comment 4 Sebastian Zarnekow CLA 2011-10-13 11:06:23 EDT
Good catch.

Things like

Foo:
  {Foo} (a | b?);

can cause an infinite recursion.
Comment 5 Sebastian Zarnekow CLA 2011-10-13 16:40:59 EDT
Pushed to master.
Comment 6 Karsten Thoms CLA 2017-09-19 16:57:35 EDT
Closing all bugs that were set to RESOLVED before Neon.0
Comment 7 Karsten Thoms CLA 2017-09-19 17:08:51 EDT
Closing all bugs that were set to RESOLVED before Neon.0