Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/javax/management/MBeanInfo/SerializationTest1.java
38841 views
/*1* Copyright (c) 2005, 2012, 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*/2223/*24* @test25* @bug 678329026* @summary Test correct reading of an empty Descriptor.27* @author Jaroslav Bachorik28* @run clean SerializationTest129* @run build SerializationTest130* @run main SerializationTest131*/3233import java.io.*;34import javax.management.*;3536public class SerializationTest1 {37public static void main(String[] args) throws Exception {38MBeanInfo mi1 = new MBeanInfo("",39"",40new MBeanAttributeInfo[]{},41new MBeanConstructorInfo[]{},42new MBeanOperationInfo[]{},43new MBeanNotificationInfo[]{},44ImmutableDescriptor.EMPTY_DESCRIPTOR);4546test(mi1);4748MBeanFeatureInfo mfi2 = new MBeanFeatureInfo("",49"",50ImmutableDescriptor.EMPTY_DESCRIPTOR);5152test(mfi2);53}5455public static void test(Object obj) throws Exception {56ByteArrayOutputStream baos = new ByteArrayOutputStream();57ObjectOutputStream oos = new ObjectOutputStream(baos);58oos.writeObject(obj);5960final boolean[] failed = new boolean[]{false};61ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());62final ObjectInputStream ois = new ObjectInputStream(bais) {63protected Class<?> resolveClass(ObjectStreamClass desc) throws IOException, ClassNotFoundException {64System.out.println("*** " + desc.getName());65if (desc.getName().equals("[Ljava.lang.Object;")) { // javax.management.Descriptor fields66Thread.dumpStack();67for(StackTraceElement e : Thread.currentThread().getStackTrace()) { // checking for the deserialization location68if (e.getMethodName().equals("skipCustomData")) { // indicates the presence of unread values from the custom object serialization69failed[0] = true;70}71}72}73return super.resolveClass(desc); //To change body of generated methods, choose Tools | Templates.74}75};76Object newObj = ois.readObject();7778if (failed[0]) {79throw new RuntimeException("Zero-length descriptor not read back");80}81}82}838485