author | phh |
Sat, 30 Nov 2019 14:33:05 -0800 | |
changeset 59330 | 5b96c12f909d |
parent 58565 | baa5969ecf34 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
58565
baa5969ecf34
8231427: Warning cleanup in tests of java.io.Serializable
rriggs
parents:
47216
diff
changeset
|
2 |
* Copyright (c) 1999, 2019, Oracle and/or its affiliates. All rights reserved. |
2 | 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 |
* |
|
5506 | 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. |
|
2 | 22 |
*/ |
23 |
||
24 |
/* @test |
|
25 |
* @bug 4191941 |
|
26 |
* @summary Ensure that original ClassNotFoundException thrown inside of |
|
27 |
* ObjectInputStream.resolveClass() is preserved (and thrown). |
|
28 |
*/ |
|
29 |
||
30 |
import java.io.*; |
|
31 |
||
32 |
class BrokenObjectInputStream extends ObjectInputStream { |
|
33 |
||
34 |
static final String message = "bodega"; |
|
35 |
||
36 |
BrokenObjectInputStream(InputStream in) throws IOException { |
|
37 |
super(in); |
|
38 |
} |
|
39 |
||
58565
baa5969ecf34
8231427: Warning cleanup in tests of java.io.Serializable
rriggs
parents:
47216
diff
changeset
|
40 |
protected Class<?> resolveClass(ObjectStreamClass desc) |
baa5969ecf34
8231427: Warning cleanup in tests of java.io.Serializable
rriggs
parents:
47216
diff
changeset
|
41 |
throws ClassNotFoundException |
2 | 42 |
{ |
43 |
throw new ClassNotFoundException(message); |
|
44 |
} |
|
45 |
} |
|
46 |
||
47 |
public class ResolveClassException { |
|
48 |
public static void main(String[] args) throws Exception { |
|
49 |
ByteArrayOutputStream bout; |
|
50 |
ObjectOutputStream oout; |
|
51 |
ByteArrayInputStream bin; |
|
52 |
BrokenObjectInputStream oin; |
|
53 |
Object obj; |
|
54 |
||
55 |
// write and read an object |
|
58565
baa5969ecf34
8231427: Warning cleanup in tests of java.io.Serializable
rriggs
parents:
47216
diff
changeset
|
56 |
obj = 5; |
2 | 57 |
bout = new ByteArrayOutputStream(); |
58 |
oout = new ObjectOutputStream(bout); |
|
59 |
oout.writeObject(obj); |
|
60 |
bin = new ByteArrayInputStream(bout.toByteArray()); |
|
61 |
oin = new BrokenObjectInputStream(bin); |
|
62 |
try { |
|
63 |
oin.readObject(); |
|
64 |
} catch (ClassNotFoundException e) { |
|
65 |
if (! BrokenObjectInputStream.message.equals(e.getMessage())) |
|
66 |
throw new Error("Original exception not preserved"); |
|
67 |
} |
|
68 |
||
69 |
// write and read an array of objects |
|
58565
baa5969ecf34
8231427: Warning cleanup in tests of java.io.Serializable
rriggs
parents:
47216
diff
changeset
|
70 |
obj = new Integer[] { 5 }; |
2 | 71 |
bout = new ByteArrayOutputStream(); |
72 |
oout = new ObjectOutputStream(bout); |
|
73 |
oout.writeObject(obj); |
|
74 |
bin = new ByteArrayInputStream(bout.toByteArray()); |
|
75 |
oin = new BrokenObjectInputStream(bin); |
|
76 |
try { |
|
77 |
oin.readObject(); |
|
78 |
} catch (ClassNotFoundException e) { |
|
79 |
if (! BrokenObjectInputStream.message.equals(e.getMessage())) |
|
80 |
throw new Error("Original exception not preserved"); |
|
81 |
} |
|
82 |
} |
|
83 |
} |