author | rriggs |
Fri, 11 Oct 2019 13:11:56 -0400 | |
changeset 58565 | baa5969ecf34 |
parent 47216 | 71c04702a3d5 |
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) 2007, 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 6541870 |
|
26 |
* @summary this test checks that ObjectInputStream throws an IOException |
|
27 |
* instead of a NullPointerException when deserializing an ArrayList |
|
28 |
* of Externalizables if there is an IOException while deserializing |
|
29 |
* one of these Externalizables. |
|
30 |
* |
|
31 |
* @author Andrey Ozerov |
|
32 |
*/ |
|
33 |
||
34 |
import java.io.ByteArrayInputStream; |
|
35 |
import java.io.ByteArrayOutputStream; |
|
36 |
import java.io.IOException; |
|
37 |
import java.io.ObjectInput; |
|
38 |
import java.io.ObjectInputStream; |
|
39 |
import java.io.ObjectOutput; |
|
40 |
import java.io.ObjectOutputStream; |
|
41 |
import java.util.ArrayList; |
|
42 |
||
43 |
public class NPEProvoker implements java.io.Externalizable { |
|
58565
baa5969ecf34
8231427: Warning cleanup in tests of java.io.Serializable
rriggs
parents:
47216
diff
changeset
|
44 |
private static final long serialVersionUID = 1L; |
baa5969ecf34
8231427: Warning cleanup in tests of java.io.Serializable
rriggs
parents:
47216
diff
changeset
|
45 |
|
2 | 46 |
private String test = "test"; |
47 |
||
48 |
public void readExternal(ObjectInput in) throws IOException, |
|
49 |
ClassNotFoundException |
|
50 |
{ |
|
51 |
throw new IOException(); //io exception for whatever reason |
|
52 |
} |
|
53 |
||
54 |
public void writeExternal(ObjectOutput out) throws IOException { |
|
55 |
out.writeObject(test); |
|
56 |
} |
|
57 |
||
58 |
public static void main(String[] args) { |
|
59 |
System.err.println("\n Regression test for bug 6541870\n"); |
|
60 |
try { |
|
7803
56bc97d69d93
6880112: Project Coin: Port JDK core library code to use diamond operator
smarks
parents:
5506
diff
changeset
|
61 |
ArrayList<NPEProvoker> list = new ArrayList<>(); |
2 | 62 |
list.add(new NPEProvoker()); |
63 |
ByteArrayOutputStream baos = new ByteArrayOutputStream(); |
|
64 |
ObjectOutputStream oos = new ObjectOutputStream(baos); |
|
65 |
oos.writeObject(list); |
|
66 |
||
67 |
ObjectInputStream ois = |
|
68 |
new ObjectInputStream(new ByteArrayInputStream( |
|
69 |
baos.toByteArray())); |
|
70 |
ois.readObject(); |
|
71 |
throw new Error(); |
|
72 |
} catch (IOException e) { |
|
73 |
System.err.println("\nTEST PASSED"); |
|
74 |
} catch (ClassNotFoundException e) { |
|
75 |
throw new Error(); |
|
76 |
} catch (NullPointerException e) { |
|
77 |
throw new Error(); |
|
78 |
} |
|
79 |
} |
|
80 |
} |