8197893: Mistaken type check in CheckedEntrySet.toArray
authormartin
Wed, 14 Feb 2018 16:37:20 -0800
changeset 48899 e9676e9ca3d6
parent 48898 fdd4a131d766
child 48900 276b0604eab3
8197893: Mistaken type check in CheckedEntrySet.toArray Reviewed-by: psandoz
src/java.base/share/classes/java/util/Collections.java
--- a/src/java.base/share/classes/java/util/Collections.java	Wed Feb 14 14:13:42 2018 -0800
+++ b/src/java.base/share/classes/java/util/Collections.java	Wed Feb 14 16:37:20 2018 -0800
@@ -3771,9 +3771,9 @@
                  * Ensure that we don't get an ArrayStoreException even if
                  * s.toArray returns an array of something other than Object
                  */
-                Object[] dest = (CheckedEntry.class.isInstance(
-                    source.getClass().getComponentType()) ? source :
-                                 new Object[source.length]);
+                Object[] dest = (source.getClass() == Object[].class)
+                    ? source
+                    : new Object[source.length];
 
                 for (int i = 0; i < source.length; i++)
                     dest[i] = checkedEntry((Map.Entry<K,V>)source[i],