JDK-8317377 : StackOverflowError on Nested Class Inheritance
  • Type: Bug
  • Component: tools
  • Sub-Component: javac
  • Affected Version: 16,17,20
  • Priority: P4
  • Status: Open
  • Resolution: Unresolved
  • OS: generic
  • CPU: generic
  • Submitted: 2023-09-27
  • Updated: 2023-10-13
Description
ADDITIONAL SYSTEM INFORMATION :
System: Platform-Independent
OS: Multiple
Java Runtime: Issue replicable from JDK 16 through to the latest preview version (JDK 22 at the time of reporting).

A DESCRIPTION OF THE PROBLEM :
A StackOverflowError occurs in the Java compiler when attempting to extend an inner (non-static nested) class through its nested static class with more than one level of nesting. The issue manifests as a recursive stack trace during the compilation process.

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1. Create a Java class with an inner class and multiple levels of nested static classes.
2. Attempt to extend the inner class from the deepest level of the nested static class.
3. Compile the code.

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The code should compile without issues.
ACTUAL -
Compilation fails with a StackOverflowError and the message "Compilation failed: internal java compiler error".

---------- BEGIN SOURCE ----------
package p3;

public class Test {
    public static void main(String[] args) {
    }
    class Inner {
        class N1 {
            static class N2 extends Inner {}
        }
    }
}

class Test2 {
}
---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
None found at this time.

FREQUENCY : always



Comments
The issue is reproducible with following observations: JDK 8: No error JDK 11: Test.java:6: error: modifier static not allowed here static class N2 extends Inner {} ^ JDK 14: Test.java:6: error: modifier static not allowed here static class N2 extends Inner {} ^ JDK 16 to 20: Stack overflow with the crash error log mentioned in hs_err data JDk 21, 22: Test.java:6: error: modifier static not allowed here static class N2 extends Inner {} ^
03-10-2023