author | ohair |
Wed, 06 Apr 2011 22:06:11 -0700 | |
changeset 9035 | 1255eb81cc2f |
parent 7803 | 56bc97d69d93 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
9035
1255eb81cc2f
7033660: Update copyright year to 2011 on any files changed in 2011
ohair
parents:
7803
diff
changeset
|
2 |
* Copyright (c) 2007, 2010, 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 { |
|
44 |
private String test = "test"; |
|
45 |
||
46 |
public void readExternal(ObjectInput in) throws IOException, |
|
47 |
ClassNotFoundException |
|
48 |
{ |
|
49 |
throw new IOException(); //io exception for whatever reason |
|
50 |
} |
|
51 |
||
52 |
public void writeExternal(ObjectOutput out) throws IOException { |
|
53 |
out.writeObject(test); |
|
54 |
} |
|
55 |
||
56 |
public static void main(String[] args) { |
|
57 |
System.err.println("\n Regression test for bug 6541870\n"); |
|
58 |
try { |
|
7803
56bc97d69d93
6880112: Project Coin: Port JDK core library code to use diamond operator
smarks
parents:
5506
diff
changeset
|
59 |
ArrayList<NPEProvoker> list = new ArrayList<>(); |
2 | 60 |
list.add(new NPEProvoker()); |
61 |
ByteArrayOutputStream baos = new ByteArrayOutputStream(); |
|
62 |
ObjectOutputStream oos = new ObjectOutputStream(baos); |
|
63 |
oos.writeObject(list); |
|
64 |
||
65 |
ObjectInputStream ois = |
|
66 |
new ObjectInputStream(new ByteArrayInputStream( |
|
67 |
baos.toByteArray())); |
|
68 |
ois.readObject(); |
|
69 |
throw new Error(); |
|
70 |
} catch (IOException e) { |
|
71 |
System.err.println("\nTEST PASSED"); |
|
72 |
} catch (ClassNotFoundException e) { |
|
73 |
throw new Error(); |
|
74 |
} catch (NullPointerException e) { |
|
75 |
throw new Error(); |
|
76 |
} |
|
77 |
} |
|
78 |
} |