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