Redundant downcast in openjdk-7u40/jdk/src/share/classes/java/util/Arrays.java

Alex Yursha alexyursha at gmail.com
Sun Nov 10 06:07:57 PST 2013


I found a minor issue on openjdk-7u40 sources. Is this the right place to
discuss such things and if not could you please give me a hint on where
this right place is? I am really lost trying to find the right place to
open the issue. The issue itself is laid below.

Redundant downcast to java.lang.Object is made in method copyOf(U[]
original, int newLength, Class<? extends T[]> newType) (line 2245):

2244 public static <T,U> T[] copyOf(U[] original, int newLength, Class<?
extends T[]> newType) {
2245         T[] copy = ((Object)newType == (Object)Object[].class)
2246            ? (T[]) new Object[newLength]
2247            : (T[]) Array.newInstance(newType.getComponentType(),
newLength);
2248        System.arraycopy(original, 0, copy, 0,
2249                         Math.min(original.length, newLength));
2250        return copy;
2251 }

Actually, we need only to downcast one of the operands in order to avoid
compiler complaints about incomparable types. The patch can look like this:

- 2245  T[] copy = ((Object)newType == (Object)Object[].class)
+2245  T[] copy = ((Object)newType == Object[].class)

Regards,
Alex Yursha



More information about the jdk7u-dev mailing list