Code review request for 6990094 "ObjectInputStream cloneArray doesn't handle short[]"

Joe Darcy joe.darcy at oracle.com
Fri Dec 3 16:06:11 UTC 2010


Hello.

Please review this simple fix for

    6990094 "ObjectInputStream cloneArray doesn't handle short[]"
    http://cr.openjdk.java.net/~darcy/6990094.0/

The complete patch is

--- old/src/share/classes/java/io/ObjectInputStream.java    2010-12-03 
00:31:24.000000000 -0800
+++ new/src/share/classes/java/io/ObjectInputStream.java    2010-12-03 
00:31:24.000000000 -0800
@@ -3498,8 +3498,8 @@
             return ((int[]) array).clone();
         } else if (array instanceof long[]) {
             return ((long[]) array).clone();
-        } else if (array instanceof double[]) {
-            return ((double[]) array).clone();
+        } else if (array instanceof short[]) {
+            return ((short[]) array).clone();
         } else {
             throw new AssertionError();
         }

You'll notice there is no regression test for this change.  One 
justification is that the fix is in the "obviously no bugs" category. 
[1] There is an if-else instanceof chain over Object arrays and arrays 
of each primitive type; there are two checks for double and none for 
short so changing the one of the double checks to short is "obviously 
correct."  Also, I've taken a stab a writing an explicit regression test 
for this condition, but the problem only manifests in cases beyond my 
direct serialization experience where a class has overridden the 
readUnshared method.

-Joe

[1] "There are two ways of constructing a software design. One way is to 
make it so simple that there are obviously no deficiencies. And the 
other way is to make it so complicated that there are no obvious 
deficiencies." C.A.R. Hoare]



More information about the core-libs-dev mailing list