Integrated: 8337142: StackOverflowError in Types.containsTypeRecursive with deeply nested type hierarchy
Vicente Romero
vromero at openjdk.org
Tue Nov 4 16:50:34 UTC 2025
On Sun, 2 Nov 2025 02:12:40 GMT, Vicente Romero <vromero at openjdk.org> wrote:
> javac can crash with SOE for some deeply nested type hierarchies. See the related JBS issue for the code example. Here we have another example of infinite recursion in the compiler. This is what is happening:
>
> - method Types."isSubtype"::containsTypeRecursive uses a cache, which is a Set, the elements in that cache are of type Types.TypePair. Method TypePair::equals invoke Types::isSameType
> - Types::isSameType for this test case ends up invoking Types."isSubtype"::containsTypeRecursive, closing the infinite loop
>
> The proposed solution is to define current anonymous class isSameTypeVisitor as a named class and derive from it a visitor that will be the one used by Types.TypePair and thus invoked by TypePair::equals every time instances of TypePair are added or removed from a Map, Set, etc.
>
> This new visitor will compare types looking for exactness which is something desirable in a map key.
>
> TIA
This pull request has now been integrated.
Changeset: 4c6af03f
Author: Vicente Romero <vromero at openjdk.org>
URL: https://git.openjdk.org/jdk/commit/4c6af03f81e068a98b8f4628b96682a54f3946da
Stats: 102 lines in 2 files changed: 96 ins; 0 del; 6 mod
8337142: StackOverflowError in Types.containsTypeRecursive with deeply nested type hierarchy
Reviewed-by: mcimadamore
-------------
PR: https://git.openjdk.org/jdk/pull/28101
More information about the compiler-dev
mailing list