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

(coll) toString() on self-referential Checked collections causes stack overflow

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Won't Fix
    • Icon: P4 P4
    • None
    • 7
    • core-libs

      Description:
         As per bug 4421469, toString() method was throwing StackOverFlowError with self-referential collections and was fixed. Now trying out a similar scenario with Collections.checkedMap and Collections.checkedList also ends up with StackOverFlowError. This should be fixed to maintain the consistency .Please find the testcase below:

      <code>

      import java.util.Collections;
      import java.util.HashMap;
      import java.util.Hashtable;
      import java.util.LinkedList;
      import java.util.List;
      import java.util.Map;


      public class SelfReferencetoString {
          
          public static void main( String[] args ) {
              
              try{
                  // Map<String,Map> map1 = new HashMap<String,Map>(); // Uncomment this and comment the next line-This will work,Already fixed
                  Map<String,Map> map1 = Collections.checkedMap(new Hashtable<String,Map>(),String.class,Map.class);
                  map1.put("first",map1);
                  System.out.println("My Hashtable "+map1);
                  System.out.println("TestCase1 Passed!");
              } catch(StackOverflowError ste){
                  // ste.printStackTrace();
                  System.out.println("TestCase1 Failed with StackOverflowError!!!!");
              }
              
              
              try{
                  // List<List> listOfLists = new LinkedList<List>();// Uncomment this and comment the next line-This will work,Already fixed
                  List<List> listOfLists = Collections.checkedList(new LinkedList<List>(),List.class);
                  listOfLists.add(listOfLists);
                  System.out.println("My LinkedList "+ listOfLists);
                  System.out.println("TestCase2 Passed!");
              } catch(StackOverflowError ste){
                  // ste.printStackTrace();
                  System.out.println("TestCase2 Failed with StackOverflowError!!!!");
              }
              
          }
      }


      </code>
      <output>
      TestCase1 Failed with StackOverflowError!!!!
      TestCase2 Failed with StackOverflowError!!!!

      </output>

      Tried in :
      <version>
      bash-3.00$ java -version
      java version "1.7.0-ea"
      Java(TM) SE Runtime Environment (build 1.7.0-ea-b14)
      Java HotSpot(TM) Client VM (build 1.7.0-ea-b14, mixed mode)

      bash-3.00$ uname -a
      SunOS hrajan 5.10 Generic sun4u sparc SUNW,Sun-Blade-100
      </version>

            Unassigned Unassigned
            duke J. Duke
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: