jdk/test/javax/management/MBeanInfo/SerializationTest1.java
author stefank
Fri, 17 Apr 2015 17:10:38 +0000
changeset 30266 ef82cd1f2db3
parent 23010 6dadb192ad81
child 30376 2ccf2cf7ea48
permissions -rw-r--r--
Merge
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
14916
5e9eb5d9de14 8005309: Missed tests for 6783290,6937053,7009998
dsamersoff
parents:
diff changeset
     1
/*
23010
6dadb192ad81 8029235: Update copyright year to match last edit in jdk8 jdk repository for 2013
lana
parents: 14916
diff changeset
     2
 * Copyright (c) 2005, 2012, Oracle and/or its affiliates. All rights reserved.
14916
5e9eb5d9de14 8005309: Missed tests for 6783290,6937053,7009998
dsamersoff
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5e9eb5d9de14 8005309: Missed tests for 6783290,6937053,7009998
dsamersoff
parents:
diff changeset
     4
 *
5e9eb5d9de14 8005309: Missed tests for 6783290,6937053,7009998
dsamersoff
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
5e9eb5d9de14 8005309: Missed tests for 6783290,6937053,7009998
dsamersoff
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5e9eb5d9de14 8005309: Missed tests for 6783290,6937053,7009998
dsamersoff
parents:
diff changeset
     7
 * published by the Free Software Foundation.
5e9eb5d9de14 8005309: Missed tests for 6783290,6937053,7009998
dsamersoff
parents:
diff changeset
     8
 *
5e9eb5d9de14 8005309: Missed tests for 6783290,6937053,7009998
dsamersoff
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
5e9eb5d9de14 8005309: Missed tests for 6783290,6937053,7009998
dsamersoff
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
5e9eb5d9de14 8005309: Missed tests for 6783290,6937053,7009998
dsamersoff
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
5e9eb5d9de14 8005309: Missed tests for 6783290,6937053,7009998
dsamersoff
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
5e9eb5d9de14 8005309: Missed tests for 6783290,6937053,7009998
dsamersoff
parents:
diff changeset
    13
 * accompanied this code).
5e9eb5d9de14 8005309: Missed tests for 6783290,6937053,7009998
dsamersoff
parents:
diff changeset
    14
 *
5e9eb5d9de14 8005309: Missed tests for 6783290,6937053,7009998
dsamersoff
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
5e9eb5d9de14 8005309: Missed tests for 6783290,6937053,7009998
dsamersoff
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
5e9eb5d9de14 8005309: Missed tests for 6783290,6937053,7009998
dsamersoff
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
5e9eb5d9de14 8005309: Missed tests for 6783290,6937053,7009998
dsamersoff
parents:
diff changeset
    18
 *
5e9eb5d9de14 8005309: Missed tests for 6783290,6937053,7009998
dsamersoff
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
5e9eb5d9de14 8005309: Missed tests for 6783290,6937053,7009998
dsamersoff
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
5e9eb5d9de14 8005309: Missed tests for 6783290,6937053,7009998
dsamersoff
parents:
diff changeset
    21
 * questions.
5e9eb5d9de14 8005309: Missed tests for 6783290,6937053,7009998
dsamersoff
parents:
diff changeset
    22
 */
5e9eb5d9de14 8005309: Missed tests for 6783290,6937053,7009998
dsamersoff
parents:
diff changeset
    23
5e9eb5d9de14 8005309: Missed tests for 6783290,6937053,7009998
dsamersoff
parents:
diff changeset
    24
/*
5e9eb5d9de14 8005309: Missed tests for 6783290,6937053,7009998
dsamersoff
parents:
diff changeset
    25
 * @test
5e9eb5d9de14 8005309: Missed tests for 6783290,6937053,7009998
dsamersoff
parents:
diff changeset
    26
 * @bug 6783290
5e9eb5d9de14 8005309: Missed tests for 6783290,6937053,7009998
dsamersoff
parents:
diff changeset
    27
 * @summary Test correct reading of an empty Descriptor.
5e9eb5d9de14 8005309: Missed tests for 6783290,6937053,7009998
dsamersoff
parents:
diff changeset
    28
 * @author Jaroslav Bachorik
5e9eb5d9de14 8005309: Missed tests for 6783290,6937053,7009998
dsamersoff
parents:
diff changeset
    29
 * @run clean SerializationTest1
5e9eb5d9de14 8005309: Missed tests for 6783290,6937053,7009998
dsamersoff
parents:
diff changeset
    30
 * @run build SerializationTest1
5e9eb5d9de14 8005309: Missed tests for 6783290,6937053,7009998
dsamersoff
parents:
diff changeset
    31
 * @run main SerializationTest1
5e9eb5d9de14 8005309: Missed tests for 6783290,6937053,7009998
dsamersoff
parents:
diff changeset
    32
 */
5e9eb5d9de14 8005309: Missed tests for 6783290,6937053,7009998
dsamersoff
parents:
diff changeset
    33
5e9eb5d9de14 8005309: Missed tests for 6783290,6937053,7009998
dsamersoff
parents:
diff changeset
    34
import java.io.*;
5e9eb5d9de14 8005309: Missed tests for 6783290,6937053,7009998
dsamersoff
parents:
diff changeset
    35
import javax.management.*;
5e9eb5d9de14 8005309: Missed tests for 6783290,6937053,7009998
dsamersoff
parents:
diff changeset
    36
5e9eb5d9de14 8005309: Missed tests for 6783290,6937053,7009998
dsamersoff
parents:
diff changeset
    37
public class SerializationTest1 {
5e9eb5d9de14 8005309: Missed tests for 6783290,6937053,7009998
dsamersoff
parents:
diff changeset
    38
    public static void main(String[] args) throws Exception {
5e9eb5d9de14 8005309: Missed tests for 6783290,6937053,7009998
dsamersoff
parents:
diff changeset
    39
        MBeanInfo mi1 = new MBeanInfo("",
5e9eb5d9de14 8005309: Missed tests for 6783290,6937053,7009998
dsamersoff
parents:
diff changeset
    40
                                      "",
5e9eb5d9de14 8005309: Missed tests for 6783290,6937053,7009998
dsamersoff
parents:
diff changeset
    41
                                      new MBeanAttributeInfo[]{},
5e9eb5d9de14 8005309: Missed tests for 6783290,6937053,7009998
dsamersoff
parents:
diff changeset
    42
                                      new MBeanConstructorInfo[]{},
5e9eb5d9de14 8005309: Missed tests for 6783290,6937053,7009998
dsamersoff
parents:
diff changeset
    43
                                      new MBeanOperationInfo[]{},
5e9eb5d9de14 8005309: Missed tests for 6783290,6937053,7009998
dsamersoff
parents:
diff changeset
    44
                                      new MBeanNotificationInfo[]{},
5e9eb5d9de14 8005309: Missed tests for 6783290,6937053,7009998
dsamersoff
parents:
diff changeset
    45
                                      ImmutableDescriptor.EMPTY_DESCRIPTOR);
5e9eb5d9de14 8005309: Missed tests for 6783290,6937053,7009998
dsamersoff
parents:
diff changeset
    46
5e9eb5d9de14 8005309: Missed tests for 6783290,6937053,7009998
dsamersoff
parents:
diff changeset
    47
        test(mi1);
5e9eb5d9de14 8005309: Missed tests for 6783290,6937053,7009998
dsamersoff
parents:
diff changeset
    48
5e9eb5d9de14 8005309: Missed tests for 6783290,6937053,7009998
dsamersoff
parents:
diff changeset
    49
        MBeanFeatureInfo mfi2 = new MBeanFeatureInfo("",
5e9eb5d9de14 8005309: Missed tests for 6783290,6937053,7009998
dsamersoff
parents:
diff changeset
    50
                                                     "",
5e9eb5d9de14 8005309: Missed tests for 6783290,6937053,7009998
dsamersoff
parents:
diff changeset
    51
                                                     ImmutableDescriptor.EMPTY_DESCRIPTOR);
5e9eb5d9de14 8005309: Missed tests for 6783290,6937053,7009998
dsamersoff
parents:
diff changeset
    52
5e9eb5d9de14 8005309: Missed tests for 6783290,6937053,7009998
dsamersoff
parents:
diff changeset
    53
        test(mfi2);
5e9eb5d9de14 8005309: Missed tests for 6783290,6937053,7009998
dsamersoff
parents:
diff changeset
    54
    }
5e9eb5d9de14 8005309: Missed tests for 6783290,6937053,7009998
dsamersoff
parents:
diff changeset
    55
5e9eb5d9de14 8005309: Missed tests for 6783290,6937053,7009998
dsamersoff
parents:
diff changeset
    56
    public static void test(Object obj) throws Exception {
5e9eb5d9de14 8005309: Missed tests for 6783290,6937053,7009998
dsamersoff
parents:
diff changeset
    57
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
5e9eb5d9de14 8005309: Missed tests for 6783290,6937053,7009998
dsamersoff
parents:
diff changeset
    58
        ObjectOutputStream oos = new ObjectOutputStream(baos);
5e9eb5d9de14 8005309: Missed tests for 6783290,6937053,7009998
dsamersoff
parents:
diff changeset
    59
        oos.writeObject(obj);
5e9eb5d9de14 8005309: Missed tests for 6783290,6937053,7009998
dsamersoff
parents:
diff changeset
    60
5e9eb5d9de14 8005309: Missed tests for 6783290,6937053,7009998
dsamersoff
parents:
diff changeset
    61
        final boolean[] failed = new boolean[]{false};
5e9eb5d9de14 8005309: Missed tests for 6783290,6937053,7009998
dsamersoff
parents:
diff changeset
    62
        ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
5e9eb5d9de14 8005309: Missed tests for 6783290,6937053,7009998
dsamersoff
parents:
diff changeset
    63
        final ObjectInputStream ois = new ObjectInputStream(bais) {
5e9eb5d9de14 8005309: Missed tests for 6783290,6937053,7009998
dsamersoff
parents:
diff changeset
    64
            protected Class<?> resolveClass(ObjectStreamClass desc) throws IOException, ClassNotFoundException {
5e9eb5d9de14 8005309: Missed tests for 6783290,6937053,7009998
dsamersoff
parents:
diff changeset
    65
                System.out.println("*** " + desc.getName());
5e9eb5d9de14 8005309: Missed tests for 6783290,6937053,7009998
dsamersoff
parents:
diff changeset
    66
                if (desc.getName().equals("[Ljava.lang.Object;")) { // javax.management.Descriptor fields
5e9eb5d9de14 8005309: Missed tests for 6783290,6937053,7009998
dsamersoff
parents:
diff changeset
    67
                    Thread.dumpStack();
5e9eb5d9de14 8005309: Missed tests for 6783290,6937053,7009998
dsamersoff
parents:
diff changeset
    68
                    for(StackTraceElement e : Thread.currentThread().getStackTrace()) { // checking for the deserialization location
5e9eb5d9de14 8005309: Missed tests for 6783290,6937053,7009998
dsamersoff
parents:
diff changeset
    69
                        if (e.getMethodName().equals("skipCustomData")) { // indicates the presence of unread values from the custom object serialization
5e9eb5d9de14 8005309: Missed tests for 6783290,6937053,7009998
dsamersoff
parents:
diff changeset
    70
                            failed[0] = true;
5e9eb5d9de14 8005309: Missed tests for 6783290,6937053,7009998
dsamersoff
parents:
diff changeset
    71
                        }
5e9eb5d9de14 8005309: Missed tests for 6783290,6937053,7009998
dsamersoff
parents:
diff changeset
    72
                    }
5e9eb5d9de14 8005309: Missed tests for 6783290,6937053,7009998
dsamersoff
parents:
diff changeset
    73
                }
5e9eb5d9de14 8005309: Missed tests for 6783290,6937053,7009998
dsamersoff
parents:
diff changeset
    74
                return super.resolveClass(desc); //To change body of generated methods, choose Tools | Templates.
5e9eb5d9de14 8005309: Missed tests for 6783290,6937053,7009998
dsamersoff
parents:
diff changeset
    75
            }
5e9eb5d9de14 8005309: Missed tests for 6783290,6937053,7009998
dsamersoff
parents:
diff changeset
    76
        };
5e9eb5d9de14 8005309: Missed tests for 6783290,6937053,7009998
dsamersoff
parents:
diff changeset
    77
        Object newObj = ois.readObject();
5e9eb5d9de14 8005309: Missed tests for 6783290,6937053,7009998
dsamersoff
parents:
diff changeset
    78
5e9eb5d9de14 8005309: Missed tests for 6783290,6937053,7009998
dsamersoff
parents:
diff changeset
    79
        if (failed[0]) {
5e9eb5d9de14 8005309: Missed tests for 6783290,6937053,7009998
dsamersoff
parents:
diff changeset
    80
            throw new RuntimeException("Zero-length descriptor not read back");
5e9eb5d9de14 8005309: Missed tests for 6783290,6937053,7009998
dsamersoff
parents:
diff changeset
    81
        }
5e9eb5d9de14 8005309: Missed tests for 6783290,6937053,7009998
dsamersoff
parents:
diff changeset
    82
    }
5e9eb5d9de14 8005309: Missed tests for 6783290,6937053,7009998
dsamersoff
parents:
diff changeset
    83
}