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

AnnotatedType implementations of hashCode() lead to StackOverflowError

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P2
    • Resolution: Fixed
    • Affects Version/s: 12, 13
    • Fix Version/s: 13
    • Component/s: core-libs
    • Labels:
      None
    • Subcomponent:
    • Introduced In Version:
      12
    • Resolved In Build:
      b23
    • Verification:
      Verified

      Backports

        Description

        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.

          Attachments

            Issue Links

              Activity

                People

                Assignee:
                darcy Joe Darcy
                Reporter:
                cwimmer Christian Wimmer
                Votes:
                0 Vote for this issue
                Watchers:
                5 Start watching this issue

                  Dates

                  Created:
                  Updated:
                  Resolved: