Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

avoid java.lang.StackOverflowError #1105

Closed
WolfgangFahl opened this issue Feb 5, 2016 · 10 comments
Closed

avoid java.lang.StackOverflowError #1105

WolfgangFahl opened this issue Feb 5, 2016 · 10 comments

Comments

@WolfgangFahl
Copy link

WolfgangFahl commented Feb 5, 2016

see http://stackoverflow.com/questions/31193527/stackoverflowerror-in-antlr4

The LexerATNSimulator should IMHO give up after a certain number of recursions before the StackOverflowError happens and spit out some information what is going on to help debug the grammer that causes the problem.

java.lang.StackOverflowError
    at org.antlr.v4.runtime.atn.LexerATNSimulator.getEpsilonTarget(LexerATNSimulator.java:499)
    at org.antlr.v4.runtime.atn.LexerATNSimulator.closure(LexerATNSimulator.java:480)
    at org.antlr.v4.runtime.atn.LexerATNSimulator.closure(LexerATNSimulator.java:482)
    at org.antlr.v4.runtime.atn.LexerATNSimulator.closure(LexerATNSimulator.java:482)
...
@parrt
Copy link
Member

parrt commented Dec 10, 2016

@WolfgangFahl Did you get an error from antlr during code generation? It's an optional token or something.

@parrt
Copy link
Member

parrt commented Mar 14, 2017

@WolfgangFahl If this is an issue of actual stack size because of parsing, you can increase the stack size remarkably big in Java ;) Did you see an error message when you generated code? Can I close this?

@Ma124
Copy link

Ma124 commented Sep 8, 2017

@parrt I have the same problem. I increased the stack size but it didn't work.

@WolfgangFahl
Copy link
Author

Increasing the stacksize obviously won't help. No please don't close this. It would be helpful to get an avoidance/debug help implemented.

@parrt
Copy link
Member

parrt commented Sep 9, 2017

it's an infinite loop issue when someone puts a lexer rule that can match the empty string I believe. detecting infinite loops in that case might be undecidable. (halting problem)

@KvanTTT
Copy link
Member

KvanTTT commented Nov 9, 2021

Seems like it's related to #2860

Also, I don't think it's about a halting problem rather a bug in runtime. Because there is stack overflow even for such a simple sample (for input 'x'):

TOKEN1: '\'' FRAGMENT1 '\'';
fragment FRAGMENT1: ('x'|)+;

But everything works fine if an empty alternative is replaced with optional:

TOKEN2: '\'' FRAGMENT2 '\'';
fragment FRAGMENT2: 'x'*;

@WolfgangFahl
Copy link
Author

This is definitely not a halting problem since the stack is a limited resource and it should be avoided to overrun the limit. The limit is known and therefore simple counting can decide when the limit is reached (or almost reached).

KvanTTT added a commit to KvanTTT/antlr4 that referenced this issue Nov 12, 2021
@KvanTTT
Copy link
Member

KvanTTT commented Nov 12, 2021

It seems like I've fixed this case. Lexer should throw EPSILON_CLOSURE on such rules as well as parser does it. For instance, here is another fix for parser: #1477

KvanTTT added a commit to KvanTTT/antlr4 that referenced this issue Dec 23, 2021
KvanTTT added a commit to KvanTTT/antlr4 that referenced this issue Dec 27, 2021
@KvanTTT
Copy link
Member

KvanTTT commented Dec 28, 2021

@parrt it should be closed as well :)

@parrt parrt closed this as completed Dec 28, 2021
@parrt parrt added this to the 4.9.4 milestone Dec 28, 2021
@WolfgangFahl
Copy link
Author

@parrt @KvanTTT thanks

srowen pushed a commit to apache/spark that referenced this issue Sep 26, 2023
### What changes were proposed in this pull request?
This pr is aims upgrade `antlr4` from 4.9.3 to 4.13.1

### Why are the changes needed?
After 4.10, antlr4 is using Java 11 for the source code and the compiled .class files for the ANTLR tool. There are some bug fix and Improvements after 4.9.3:
- antlr/antlr4#3399
- antlr/antlr4#1105
- antlr/antlr4#2788
- antlr/antlr4#3957
- antlr/antlr4#4394

The full release notes as follows:

- https://github.com/antlr/antlr4/releases/tag/4.13.1
- https://github.com/antlr/antlr4/releases/tag/4.13.0
- https://github.com/antlr/antlr4/releases/tag/4.12.0
- https://github.com/antlr/antlr4/releases/tag/4.11.1
- https://github.com/antlr/antlr4/releases/tag/4.11.0
- https://github.com/antlr/antlr4/releases/tag/4.10.1
- https://github.com/antlr/antlr4/releases/tag/4.10

### Does this PR introduce _any_ user-facing change?
No

### How was this patch tested?
Pass GitHub Actions

### Was this patch authored or co-authored using generative AI tooling?
No

Closes #43075 from LuciferYang/antlr4-4131.

Authored-by: yangjie01 <yangjie01@baidu.com>
Signed-off-by: Sean Owen <srowen@gmail.com>
doruchiulan pushed a commit to BlueprintTechnologies/spark-lhm that referenced this issue Feb 2, 2024
### What changes were proposed in this pull request?
This pr is aims upgrade `antlr4` from 4.9.3 to 4.13.1

### Why are the changes needed?
After 4.10, antlr4 is using Java 11 for the source code and the compiled .class files for the ANTLR tool. There are some bug fix and Improvements after 4.9.3:
- antlr/antlr4#3399
- antlr/antlr4#1105
- antlr/antlr4#2788
- antlr/antlr4#3957
- antlr/antlr4#4394

The full release notes as follows:

- https://github.com/antlr/antlr4/releases/tag/4.13.1
- https://github.com/antlr/antlr4/releases/tag/4.13.0
- https://github.com/antlr/antlr4/releases/tag/4.12.0
- https://github.com/antlr/antlr4/releases/tag/4.11.1
- https://github.com/antlr/antlr4/releases/tag/4.11.0
- https://github.com/antlr/antlr4/releases/tag/4.10.1
- https://github.com/antlr/antlr4/releases/tag/4.10

### Does this PR introduce _any_ user-facing change?
No

### How was this patch tested?
Pass GitHub Actions

### Was this patch authored or co-authored using generative AI tooling?
No

Closes apache#43075 from LuciferYang/antlr4-4131.

Authored-by: yangjie01 <yangjie01@baidu.com>
Signed-off-by: Sean Owen <srowen@gmail.com>
(cherry picked from commit 13cd291)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants