Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/io/Serializable/cloneArray/CloneArray.java
38828 views
/*1* Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/222324/* @test25* @bug 699009426* @summary Verify ObjectInputStream.cloneArray works on many kinds of arrays27* @author Stuart Marks, Joseph D. Darcy28*/2930import java.io.ByteArrayInputStream;31import java.io.ByteArrayOutputStream;32import java.io.IOException;33import java.io.ObjectInputStream;34import java.io.ObjectOutputStream;35import java.io.ObjectStreamException;36import java.io.Serializable;3738public class CloneArray {39static Object replacement;4041static class Resolver implements Serializable {42private Object readResolve() throws ObjectStreamException {43return replacement;44}45}4647private static void test(Object rep)48throws IOException, ClassNotFoundException {4950try(ByteArrayOutputStream baos = new ByteArrayOutputStream()) {51try(ObjectOutputStream oos = new ObjectOutputStream(baos)) {52oos.writeObject(new Resolver());53oos.writeObject(new Resolver());54}5556Object o1;57Object o2;58try(ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());59ObjectInputStream ois = new ObjectInputStream(bais)) {60replacement = rep;61o1 = ois.readUnshared();62o2 = ois.readUnshared();63}6465if (o1 == o2)66throw new AssertionError("o1 and o2 must not be identical");67}68}6970public static void main(String[] args)71throws IOException, ClassNotFoundException {72Object[] replacements = {73new byte[] {1},74new char[] {'2'},75new short[] {3},76new int[] {4},77new long[] {5},78new float[] {6.0f},79new double[] {7.0},80new boolean[] {true},81new Object[] {"A string."}82};8384for(Object replacement : replacements) {85test(replacement);86}87}88}899091