Path: blob/master/test/jdk/javax/management/MBeanInfo/SerializationTest1.java
41149 views
/*1* Copyright (c) 2005, 2015, 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*29* @run clean SerializationTest130* @run build SerializationTest131* @run main SerializationTest132*/3334import java.io.*;35import javax.management.*;3637public class SerializationTest1 {38public static void main(String[] args) throws Exception {39MBeanInfo mi1 = new MBeanInfo("",40"",41new MBeanAttributeInfo[]{},42new MBeanConstructorInfo[]{},43new MBeanOperationInfo[]{},44new MBeanNotificationInfo[]{},45ImmutableDescriptor.EMPTY_DESCRIPTOR);4647test(mi1);4849MBeanFeatureInfo mfi2 = new MBeanFeatureInfo("",50"",51ImmutableDescriptor.EMPTY_DESCRIPTOR);5253test(mfi2);54}5556public static void test(Object obj) throws Exception {57ByteArrayOutputStream baos = new ByteArrayOutputStream();58ObjectOutputStream oos = new ObjectOutputStream(baos);59oos.writeObject(obj);6061final boolean[] failed = new boolean[]{false};62ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());63final ObjectInputStream ois = new ObjectInputStream(bais) {64protected Class<?> resolveClass(ObjectStreamClass desc) throws IOException, ClassNotFoundException {65System.out.println("*** " + desc.getName());66if (desc.getName().equals("[Ljava.lang.Object;")) { // javax.management.Descriptor fields67Thread.dumpStack();68for(StackTraceElement e : Thread.currentThread().getStackTrace()) { // checking for the deserialization location69if (e.getMethodName().equals("skipCustomData")) { // indicates the presence of unread values from the custom object serialization70failed[0] = true;71}72}73}74return super.resolveClass(desc); //To change body of generated methods, choose Tools | Templates.75}76};77Object newObj = ois.readObject();7879if (failed[0]) {80throw new RuntimeException("Zero-length descriptor not read back");81}82}83}848586