-
Notifications
You must be signed in to change notification settings - Fork 6.2k
8373570: Javac stack overflow on method-local class with nested record referring to enclosing type #28821
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
Closed
+82
−1
Closed
8373570: Javac stack overflow on method-local class with nested record referring to enclosing type #28821
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
test/langtools/tools/javac/SuperInit/NewLocalNotInInner.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| /* | ||
| * @test /nodynamiccopyright/ | ||
| * @bug 8373570 | ||
| * @summary Javac stack overflow on method-local class with nested record referring to enclosing type | ||
| * @compile/fail/ref=NewLocalNotInInner.out -XDrawDiagnostics NewLocalNotInInner.java | ||
| */ | ||
| class NewLocalNotInInner { | ||
| void m() { | ||
| class Local { | ||
| static class Foo { | ||
| void m() { | ||
| new Local(); // error | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| void m_anon() { | ||
| class Local { | ||
| static class Foo { | ||
| void m() { | ||
| new Local() { }; // error | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| void m_record() { | ||
| class Local { | ||
| record Foo() { | ||
| void m() { | ||
| new Local(); // error | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| void m_intf() { | ||
| class Local { | ||
| interface Foo { | ||
| default void m() { | ||
| new Local(); // error | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| void sup() { | ||
| class Local { | ||
| static class Foo { | ||
| void m() { | ||
| class Sub extends Local { }; // error | ||
| new Sub(); | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| static void staticLocal() { | ||
| class Local { } | ||
| new Local(); // ok | ||
| } | ||
|
|
||
| static void staticLocalFromAnon() { | ||
| class Local { } | ||
| new Object() { | ||
| Local local() { | ||
| return new Local(); // ok | ||
| } | ||
| }; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| NewLocalNotInInner.java:12:21: compiler.err.local.cant.be.inst.static: kindname.class, Local | ||
| NewLocalNotInInner.java:22:21: compiler.err.local.cant.be.inst.static: kindname.class, Local | ||
| NewLocalNotInInner.java:32:21: compiler.err.local.cant.be.inst.static: kindname.class, Local | ||
| NewLocalNotInInner.java:42:21: compiler.err.local.cant.be.inst.static: kindname.class, Local | ||
| NewLocalNotInInner.java:52:21: compiler.err.local.cant.be.inst.static: kindname.class, Local | ||
| 5 errors |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In other similar loops, we would check
isStaticas the first statement in the loop. However, here we can't do that -- if the local class is static, it will be defined in a static method -- this means the search will always end with a static context. But this is ok, and we don't want to raise an error!There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See tests
staticLocalandstaticLocalFromAnon(these were derived from some failing code in the Stream API).