Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8224012

AnnotatedType implementations of hashCode() lead to StackOverflowError

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P2 P2
    • 13
    • 12, 13
    • 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.

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

                Created:
                Updated:
                Resolved: