-
Bug
-
Resolution: Won't Fix
-
P4
-
None
-
None
-
generic
-
generic
A DESCRIPTION OF THE PROBLEM :
By current specification:
"if any of the following is true, an ArrayStoreException is thrown and the destination is not modified:
1. The src argument refers to an object that is not an array.
2. The dest argument refers to an object that is not an array.
3. The src argument and dest argument refer to arrays whose component types are different primitive types.
4. The src argument refers to an array with a primitive component type and the dest argument refers to an array with a reference component type.
5. The src argument refers to an array with a reference component type and the dest argument refers to an array with a primitive component type.
Otherwise:
6. If any actual component of the source array from position srcPos through srcPos+length-1 cannot be converted to the component type of the destination array by assignment conversion, an ArrayStoreException is thrown. In this case, let k be the smallest nonnegative integer less than length such that src[srcPos+k] cannot be converted to the component type of the destination array; when the exception is thrown, source array components from positions srcPos through srcPos+k-1 will already have been copied to destination array positions destPos through destPos+k-1 and no other positions of the destination array will have been modified. (Because of the restrictions already itemized, this paragraph effectively applies only to the situation where both arrays have component types that are reference types.)"
For my purpose, only points 4, 5, 6 are needed.
By points 4 and 5, any copy between an array with primitive component type and an array with the relative boxing component type (e.g. int[] and Integer[]) is prohibited, while we know that this type of copy is of course safe, since it relies on the autoboxing/unboxing mechanism.
Furthermore, it's easy to prove that the point 6 makes the points 4 and 5 redundant:
Suppose that src is an array with primitive component type P, and dest is an array with reference component type R that is not the P's boxing type or one of its supertype (i.e. P is not assignable to R), and suppose that check for condition of point 4 is not done.
Of course, src[srcPos] cannot be converted to R by assignment conversion. Then, the point 6 guarantees that, when the exception is thrown, dest is not modified.
Viceversa, suppose that dest is an array with primitive component type P, and src is an array with reference component type R that is not the P's boxing type (i.e. R is not assignable to P, since boxing types are final), and suppose that check for condition of point 5 is not done.
Of course, src[srcPos] cannot be converted to R by assignment conversion. Then, the point 6 guarantees that, when the exception is thrown, dest is not modified.
This means that the points 4 and 5 can be removed from specification and implementation without loss of semantic correctness, additionally allowing the autoboxing/unboxing copy, not permitted so far.
By current specification:
"if any of the following is true, an ArrayStoreException is thrown and the destination is not modified:
1. The src argument refers to an object that is not an array.
2. The dest argument refers to an object that is not an array.
3. The src argument and dest argument refer to arrays whose component types are different primitive types.
4. The src argument refers to an array with a primitive component type and the dest argument refers to an array with a reference component type.
5. The src argument refers to an array with a reference component type and the dest argument refers to an array with a primitive component type.
Otherwise:
6. If any actual component of the source array from position srcPos through srcPos+length-1 cannot be converted to the component type of the destination array by assignment conversion, an ArrayStoreException is thrown. In this case, let k be the smallest nonnegative integer less than length such that src[srcPos+k] cannot be converted to the component type of the destination array; when the exception is thrown, source array components from positions srcPos through srcPos+k-1 will already have been copied to destination array positions destPos through destPos+k-1 and no other positions of the destination array will have been modified. (Because of the restrictions already itemized, this paragraph effectively applies only to the situation where both arrays have component types that are reference types.)"
For my purpose, only points 4, 5, 6 are needed.
By points 4 and 5, any copy between an array with primitive component type and an array with the relative boxing component type (e.g. int[] and Integer[]) is prohibited, while we know that this type of copy is of course safe, since it relies on the autoboxing/unboxing mechanism.
Furthermore, it's easy to prove that the point 6 makes the points 4 and 5 redundant:
Suppose that src is an array with primitive component type P, and dest is an array with reference component type R that is not the P's boxing type or one of its supertype (i.e. P is not assignable to R), and suppose that check for condition of point 4 is not done.
Of course, src[srcPos] cannot be converted to R by assignment conversion. Then, the point 6 guarantees that, when the exception is thrown, dest is not modified.
Viceversa, suppose that dest is an array with primitive component type P, and src is an array with reference component type R that is not the P's boxing type (i.e. R is not assignable to P, since boxing types are final), and suppose that check for condition of point 5 is not done.
Of course, src[srcPos] cannot be converted to R by assignment conversion. Then, the point 6 guarantees that, when the exception is thrown, dest is not modified.
This means that the points 4 and 5 can be removed from specification and implementation without loss of semantic correctness, additionally allowing the autoboxing/unboxing copy, not permitted so far.