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

ArrayIndexOutOfBoundsException while cloning a custom HashMap Implementation

    XMLWordPrintable

    Details

      Description

      FULL PRODUCT VERSION :
      1.7.0_71

      ADDITIONAL OS VERSION INFORMATION :
      Windows
      Linux

      A DESCRIPTION OF THE PROBLEM :
      Getting error while using below code.

      import java.util.HashMap;
      import java.util.Map;
      import java.util.Set;

      public class Testmap {

          
          public Testmap() {
              
          }
          
          protected void testMap() {
              MyMap myMap = new MyMap();
              myMap.put("A", "VVVV");
              System.out.println(myMap.clone());
              System.out.println(myMap.get("A"));
          }
          
          
          public class MyMap extends HashMap {
              
              Map map = new HashMap();
              
              public MyMap() {
                  
              }
              
              @Override
              public Object put(Object key, Object value) {
                  return map.put(key, value);
              }
              
              @Override
              public Object get(Object key) {
                  return map.get(key);
              }
              
              @Override
              public Object clone() {
                  return super.clone();
              }

              @Override
              public Set entrySet() {
                  return map.entrySet();
              }
              
          }
          /**
           * @param args
           */
          public static void main(String[] args) {
              Testmap test = new Testmap();
              test.testMap();
          }

      }


      Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 69
          at java.util.HashMap.putForCreate(HashMap.java:541)
          at java.util.HashMap.putAllForCreate(HashMap.java:555)
          at java.util.HashMap.clone(HashMap.java:796)
          at Testmap$MyMap.clone(Testmap.java:52)
          at Testmap.testMap(Testmap.java:27)
          at Testmap.main(Testmap.java:66)


      REGRESSION. Last worked in version 7u45

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      //Execute below code

      import java.util.HashMap;
      import java.util.Map;
      import java.util.Set;

      public class Testmap {

          
          public Testmap() {
              
          }
          
          protected void testMap() {
              MyMap myMap = new MyMap();
              myMap.put("A", "VVVV");
              System.out.println(myMap.clone());
              System.out.println(myMap.get("A"));
          }
          
          
          public class MyMap extends HashMap {
              
              Map map = new HashMap();
              
              public MyMap() {
                  
              }
              
              @Override
              public Object put(Object key, Object value) {
                  return map.put(key, value);
              }
              
              @Override
              public Object get(Object key) {
                  return map.get(key);
              }
              
              @Override
              public Object clone() {
                  return super.clone();
              }

              @Override
              public Set entrySet() {
                  return map.entrySet();
              }
              
          }
          /**
           * @param args
           */
          public static void main(String[] args) {
              Testmap test = new Testmap();
              test.testMap();
          }

      }


      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      It was working properly in earlier java7 versions.
      ACTUAL -
      Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 69
          at java.util.HashMap.putForCreate(HashMap.java:541)
          at java.util.HashMap.putAllForCreate(HashMap.java:555)
          at java.util.HashMap.clone(HashMap.java:796)
          at Testmap$MyMap.clone(Testmap.java:52)
          at Testmap.testMap(Testmap.java:27)
          at Testmap.main(Testmap.java:66)


      REPRODUCIBILITY :
      This bug can be reproduced always.

      SUPPORT :
      YES

        Attachments

          Activity

            People

            • Assignee:
              igerasim Ivan Gerasimov
              Reporter:
              webbuggrp Webbug Group
            • Votes:
              0 Vote for this issue
              Watchers:
              6 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: