Redundant downcast in openjdk-7u40/jdk/src/share/classes/java/util/Arrays.java
Martin Buchholz
martinrb at google.com
Wed Nov 13 17:47:57 UTC 2013
While your suggestion looks like a code improvement, no one wants to fix
jdk7u40 sources. No one seems to have problems building jdk7u40 itself.
Which compiler is it that is complaining? There is a current effort to
remove warnings from openjdk8 build.
On Mon, Nov 11, 2013 at 7:13 AM, Alex Yursha <alexyursha at gmail.com> wrote:
> 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 core-libs-dev
mailing list