AnnotatedType implementations of hashCode() lead to StackOverflowError

XMLWordPrintable

    • Type: Bug
    • Resolution: Fixed
    • Priority: P2
    • 13
    • Affects Version/s: 12, 13
    • Component/s: core-libs
    • None
    • 12
    • b23
    • Verified

        JDK-8058202 introduced hashCode() and equals() methods for the inner class implementations of AnnotatedType.

        The implementations of hashCode() accumulate the hash codes of its elements. But the data structures are cyclic, which makes this simple traversal an endless recursion.

        The problem can be easily reproduced, for example with

            public static void main(String[] args) {
                Object[] intf = Enum.class.getAnnotatedInterfaces();
                Objects.hash(intf);
            }

        The repeated stack trace elements in the StackOverflowError are
        at java.base/sun.reflect.annotation.AnnotatedTypeFactory$AnnotatedParameterizedTypeImpl.hashCode(AnnotatedTypeFactory.java:506)
        at java.base/java.util.Arrays.hashCode(Arrays.java:4706)
        at java.base/java.util.Objects.hash(Objects.java:147)
        at java.base/sun.reflect.annotation.AnnotatedTypeFactory$AnnotatedTypeVariableImpl.hashCode(AnnotatedTypeFactory.java:417)
        at java.base/java.util.Arrays.hashCode(Arrays.java:4706)
        at java.base/java.util.Objects.hash(Objects.java:147)
        at java.base/sun.reflect.annotation.AnnotatedTypeFactory$AnnotatedParameterizedTypeImpl.hashCode(AnnotatedTypeFactory.java:506)

        The implementations of equals() follow the same pattern as the implementations of hashCode() and therefore probably have the same problem.

              Assignee:
              Joe Darcy
              Reporter:
              Christian Wimmer (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

                Created:
                Updated:
                Resolved: