RFR: 8319987: compilation of sealed classes leads to infinite recursion

Archie Cobbs acobbs at openjdk.org
Wed Nov 15 15:29:34 UTC 2023


On Wed, 15 Nov 2023 04:22:15 GMT, Vicente Romero <vromero at openjdk.org> wrote:

> The compiler can throw a SOE when trying to compile an incorrect sealed classes hierarchy like:
> 
>     sealed interface Action permits Add {}
>     sealed interface MathOp permits Add {}
>     sealed static class Add implements MathOp permits Add {}
> 
> The error is thrown while trying to prove if two classes are disjoint or not. The proposed solution is to keep a set with the pairs of classes analyzed so far and stop as soon as a the current pair of classes is already in the set.
> 
> TIA

src/jdk.compiler/share/classes/com/sun/tools/javac/code/Types.java line 1684:

> 1682:                 } else {
> 1683:                     pairsSeen.add(newPair);
> 1684:                 }

Minor simplification possible here:

if (!pairsSeen.add(newPair))
    return;

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/16668#discussion_r1394366621


More information about the compiler-dev mailing list