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

hashCode() on list containing itself causes stackoverflow

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P4 P4
    • 8
    • 6
    • core-libs
    • b112
    • x86
    • windows_7
    • Verified

      FULL PRODUCT VERSION :


      A DESCRIPTION OF THE PROBLEM :
      If list contains itself then hashCode() loops forever (undetected recursion).
      Items may be added/removed but operations requiring hashCode() (e.g. adding list to Map as key) results in stack overflow.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      List list=new ArrayList();
      list.add(list);
      list.hashCode();

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      some int value
      ACTUAL -
      exception

      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      Exception in thread "main" java.lang.StackOverflowError
      at java.util.AbstractList$Itr.<init>(AbstractList.java:318)
              ...

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      public class TestListStackOverflow {

      public static void main(String[] args) {

      List list=new ArrayList();
      list.add(list);
      list.hashCode();

      }

      }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      change specification or introduce loopback detection in hasCode evaluation.

            mduigou Mike Duigou
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: