RFR: 8320220: Compilation of cyclic hierarchy causes infinite recursion
Archie Cobbs
acobbs at openjdk.org
Thu Feb 20 23:50:04 UTC 2025
This input currently causes an infinite loop:
interface A extends B, C {}
interface B extends A {}
interface C extends A {}
However, less complicated cycles are handled properly.
When a cycle is found, we currently:
(a) Emit a warning; and
(b) Set the symbol's type to the error type.
These two steps are done in `Check.noteCyclic()`.
Step (b) is what normally prevents the infinite loop from happening later in the compilation. But we only do this for the first class in the loop, presumably because it would be too verbose to do (a) for every class in the loop. But that means we're also only doing (b) for the first class in the loop.
In more complicated scenarios like the bug example, that means some classes in the cycle can escape without (b) being applied. But this is incorrect (or, at least, weirdly indeterminate) because a loop is a loop no matter which class you start with.
So the solution is to continue to do (a) only to the first class in the cycle but do (b) for every class in the cycle.
-------------
Commit messages:
- Fix infinite loop in cyclic inheritance scenario.
Changes: https://git.openjdk.org/jdk/pull/23704/files
Webrev: https://webrevs.openjdk.org/?repo=jdk&pr=23704&range=00
Issue: https://bugs.openjdk.org/browse/JDK-8320220
Stats: 24 lines in 3 files changed: 19 ins; 0 del; 5 mod
Patch: https://git.openjdk.org/jdk/pull/23704.diff
Fetch: git fetch https://git.openjdk.org/jdk.git pull/23704/head:pull/23704
PR: https://git.openjdk.org/jdk/pull/23704
More information about the compiler-dev
mailing list