3220N/A/*
3220N/A * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
3220N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
3220N/A *
3220N/A * This code is free software; you can redistribute it and/or modify it
3220N/A * under the terms of the GNU General Public License version 2 only, as
3220N/A * published by the Free Software Foundation.
3220N/A *
3220N/A * This code is distributed in the hope that it will be useful, but WITHOUT
3220N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
3220N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
3220N/A * version 2 for more details (a copy is included in the LICENSE file that
3220N/A * accompanied this code).
3220N/A *
3220N/A * You should have received a copy of the GNU General Public License version
3220N/A * 2 along with this work; if not, write to the Free Software Foundation,
3220N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
3220N/A *
3220N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
3220N/A * or visit www.oracle.com if you need additional information or have any
3220N/A * questions.
3220N/A */
3220N/A
3220N/A
3220N/A/* @test
3220N/A * @bug 6990094
3220N/A * @summary Verify ObjectInputStream.cloneArray works on many kinds of arrays
3220N/A * @author Stuart Marks, Joseph D. Darcy
3220N/A */
3220N/A
3220N/Aimport java.io.ByteArrayInputStream;
3220N/Aimport java.io.ByteArrayOutputStream;
3220N/Aimport java.io.IOException;
3220N/Aimport java.io.ObjectInputStream;
3220N/Aimport java.io.ObjectOutputStream;
3220N/Aimport java.io.ObjectStreamException;
3220N/Aimport java.io.Serializable;
3220N/A
3220N/Apublic class CloneArray {
3220N/A static Object replacement;
3220N/A
3220N/A static class Resolver implements Serializable {
3220N/A private Object readResolve() throws ObjectStreamException {
3220N/A return replacement;
3220N/A }
3220N/A }
3220N/A
3220N/A private static void test(Object rep)
3220N/A throws IOException, ClassNotFoundException {
3220N/A
3220N/A try(ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
3220N/A try(ObjectOutputStream oos = new ObjectOutputStream(baos)) {
3220N/A oos.writeObject(new Resolver());
3220N/A oos.writeObject(new Resolver());
3220N/A }
3220N/A
3220N/A Object o1;
3220N/A Object o2;
3220N/A try(ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
3220N/A ObjectInputStream ois = new ObjectInputStream(bais)) {
3220N/A replacement = rep;
3220N/A o1 = ois.readUnshared();
3220N/A o2 = ois.readUnshared();
3220N/A }
3220N/A
3220N/A if (o1 == o2)
3220N/A throw new AssertionError("o1 and o2 must not be identical");
3220N/A }
3220N/A }
3220N/A
3220N/A public static void main(String[] args)
3220N/A throws IOException, ClassNotFoundException {
3220N/A Object[] replacements = {
3220N/A new byte[] {1},
3220N/A new char[] {'2'},
3220N/A new short[] {3},
3220N/A new int[] {4},
3220N/A new long[] {5},
3220N/A new float[] {6.0f},
3220N/A new double[] {7.0},
3220N/A new boolean[] {true},
3220N/A new Object[] {"A string."}
3220N/A };
3220N/A
3220N/A for(Object replacement : replacements) {
3220N/A test(replacement);
3220N/A }
3220N/A }
3220N/A}