Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/awt/Container/ContainerAIOOBE/ContainerAIOOBE.java
38828 views
/*1* Copyright (c) 2014, 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*/2223import java.awt.Button;24import java.awt.Component;25import java.awt.Container;26import java.io.ByteArrayInputStream;27import java.io.ByteArrayOutputStream;28import java.io.ObjectInputStream;29import java.io.ObjectOutputStream;3031/**32* @test33* @bug 805959034* @summary ArrayIndexOutOfBoundsException occurs when Container with overridden getComponents() is deserialized.35* @author Alexey Ivanov36* @run main ContainerAIOOBE37*/38public class ContainerAIOOBE {3940public static void main(final String[] args) throws Exception {41ZContainer z = new ZContainer();42z.add(new Button());4344ByteArrayOutputStream baos = new ByteArrayOutputStream();45ObjectOutputStream oos = new ObjectOutputStream(baos);46oos.writeObject(z);47oos.flush();48oos.close();4950byte[] array = baos.toByteArray();51ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(array));5253// Reading the object must not throw ArrayIndexOutOfBoundsException54ZContainer zz = (ZContainer) ois.readObject();5556if (zz.getComponentCount() != 1) {57throw new Exception("deserialized object must have 1 component");58}59if (!(zz.getComponent(0) instanceof Button)) {60throw new Exception("deserialized object must contain Button component");61}62if (zz.getComponents().length != 0) {63throw new Exception("deserialized object returns non-empty array");64}65System.out.println("Test passed");66}6768static class ZContainer extends Container {69public Component[] getComponents() {70return new Component[0];71}72}73}747576