author | aivanov |
Mon, 20 Oct 2014 12:36:16 +0400 | |
changeset 27279 | a5914bdb193c |
child 39056 | d99e63b6d962 |
permissions | -rw-r--r-- |
27279
a5914bdb193c
8059590: ArrayIndexOutOfBoundsException occurs when Container with overridden getComponents() is deserialized
aivanov
parents:
diff
changeset
|
1 |
/* |
a5914bdb193c
8059590: ArrayIndexOutOfBoundsException occurs when Container with overridden getComponents() is deserialized
aivanov
parents:
diff
changeset
|
2 |
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. |
a5914bdb193c
8059590: ArrayIndexOutOfBoundsException occurs when Container with overridden getComponents() is deserialized
aivanov
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
a5914bdb193c
8059590: ArrayIndexOutOfBoundsException occurs when Container with overridden getComponents() is deserialized
aivanov
parents:
diff
changeset
|
4 |
* |
a5914bdb193c
8059590: ArrayIndexOutOfBoundsException occurs when Container with overridden getComponents() is deserialized
aivanov
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
a5914bdb193c
8059590: ArrayIndexOutOfBoundsException occurs when Container with overridden getComponents() is deserialized
aivanov
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
a5914bdb193c
8059590: ArrayIndexOutOfBoundsException occurs when Container with overridden getComponents() is deserialized
aivanov
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
a5914bdb193c
8059590: ArrayIndexOutOfBoundsException occurs when Container with overridden getComponents() is deserialized
aivanov
parents:
diff
changeset
|
8 |
* |
a5914bdb193c
8059590: ArrayIndexOutOfBoundsException occurs when Container with overridden getComponents() is deserialized
aivanov
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
a5914bdb193c
8059590: ArrayIndexOutOfBoundsException occurs when Container with overridden getComponents() is deserialized
aivanov
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
a5914bdb193c
8059590: ArrayIndexOutOfBoundsException occurs when Container with overridden getComponents() is deserialized
aivanov
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
a5914bdb193c
8059590: ArrayIndexOutOfBoundsException occurs when Container with overridden getComponents() is deserialized
aivanov
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
a5914bdb193c
8059590: ArrayIndexOutOfBoundsException occurs when Container with overridden getComponents() is deserialized
aivanov
parents:
diff
changeset
|
13 |
* accompanied this code). |
a5914bdb193c
8059590: ArrayIndexOutOfBoundsException occurs when Container with overridden getComponents() is deserialized
aivanov
parents:
diff
changeset
|
14 |
* |
a5914bdb193c
8059590: ArrayIndexOutOfBoundsException occurs when Container with overridden getComponents() is deserialized
aivanov
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
a5914bdb193c
8059590: ArrayIndexOutOfBoundsException occurs when Container with overridden getComponents() is deserialized
aivanov
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
a5914bdb193c
8059590: ArrayIndexOutOfBoundsException occurs when Container with overridden getComponents() is deserialized
aivanov
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
a5914bdb193c
8059590: ArrayIndexOutOfBoundsException occurs when Container with overridden getComponents() is deserialized
aivanov
parents:
diff
changeset
|
18 |
* |
a5914bdb193c
8059590: ArrayIndexOutOfBoundsException occurs when Container with overridden getComponents() is deserialized
aivanov
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
a5914bdb193c
8059590: ArrayIndexOutOfBoundsException occurs when Container with overridden getComponents() is deserialized
aivanov
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
a5914bdb193c
8059590: ArrayIndexOutOfBoundsException occurs when Container with overridden getComponents() is deserialized
aivanov
parents:
diff
changeset
|
21 |
* questions. |
a5914bdb193c
8059590: ArrayIndexOutOfBoundsException occurs when Container with overridden getComponents() is deserialized
aivanov
parents:
diff
changeset
|
22 |
*/ |
a5914bdb193c
8059590: ArrayIndexOutOfBoundsException occurs when Container with overridden getComponents() is deserialized
aivanov
parents:
diff
changeset
|
23 |
|
a5914bdb193c
8059590: ArrayIndexOutOfBoundsException occurs when Container with overridden getComponents() is deserialized
aivanov
parents:
diff
changeset
|
24 |
import java.awt.Button; |
a5914bdb193c
8059590: ArrayIndexOutOfBoundsException occurs when Container with overridden getComponents() is deserialized
aivanov
parents:
diff
changeset
|
25 |
import java.awt.Component; |
a5914bdb193c
8059590: ArrayIndexOutOfBoundsException occurs when Container with overridden getComponents() is deserialized
aivanov
parents:
diff
changeset
|
26 |
import java.awt.Container; |
a5914bdb193c
8059590: ArrayIndexOutOfBoundsException occurs when Container with overridden getComponents() is deserialized
aivanov
parents:
diff
changeset
|
27 |
import java.io.ByteArrayInputStream; |
a5914bdb193c
8059590: ArrayIndexOutOfBoundsException occurs when Container with overridden getComponents() is deserialized
aivanov
parents:
diff
changeset
|
28 |
import java.io.ByteArrayOutputStream; |
a5914bdb193c
8059590: ArrayIndexOutOfBoundsException occurs when Container with overridden getComponents() is deserialized
aivanov
parents:
diff
changeset
|
29 |
import java.io.ObjectInputStream; |
a5914bdb193c
8059590: ArrayIndexOutOfBoundsException occurs when Container with overridden getComponents() is deserialized
aivanov
parents:
diff
changeset
|
30 |
import java.io.ObjectOutputStream; |
a5914bdb193c
8059590: ArrayIndexOutOfBoundsException occurs when Container with overridden getComponents() is deserialized
aivanov
parents:
diff
changeset
|
31 |
|
a5914bdb193c
8059590: ArrayIndexOutOfBoundsException occurs when Container with overridden getComponents() is deserialized
aivanov
parents:
diff
changeset
|
32 |
/** |
a5914bdb193c
8059590: ArrayIndexOutOfBoundsException occurs when Container with overridden getComponents() is deserialized
aivanov
parents:
diff
changeset
|
33 |
* @test |
a5914bdb193c
8059590: ArrayIndexOutOfBoundsException occurs when Container with overridden getComponents() is deserialized
aivanov
parents:
diff
changeset
|
34 |
* @bug 8059590 |
a5914bdb193c
8059590: ArrayIndexOutOfBoundsException occurs when Container with overridden getComponents() is deserialized
aivanov
parents:
diff
changeset
|
35 |
* @summary ArrayIndexOutOfBoundsException occurs when Container with overridden getComponents() is deserialized. |
a5914bdb193c
8059590: ArrayIndexOutOfBoundsException occurs when Container with overridden getComponents() is deserialized
aivanov
parents:
diff
changeset
|
36 |
* @author Alexey Ivanov |
a5914bdb193c
8059590: ArrayIndexOutOfBoundsException occurs when Container with overridden getComponents() is deserialized
aivanov
parents:
diff
changeset
|
37 |
* @run main ContainerAIOOBE |
a5914bdb193c
8059590: ArrayIndexOutOfBoundsException occurs when Container with overridden getComponents() is deserialized
aivanov
parents:
diff
changeset
|
38 |
*/ |
a5914bdb193c
8059590: ArrayIndexOutOfBoundsException occurs when Container with overridden getComponents() is deserialized
aivanov
parents:
diff
changeset
|
39 |
public class ContainerAIOOBE { |
a5914bdb193c
8059590: ArrayIndexOutOfBoundsException occurs when Container with overridden getComponents() is deserialized
aivanov
parents:
diff
changeset
|
40 |
|
a5914bdb193c
8059590: ArrayIndexOutOfBoundsException occurs when Container with overridden getComponents() is deserialized
aivanov
parents:
diff
changeset
|
41 |
public static void main(final String[] args) throws Exception { |
a5914bdb193c
8059590: ArrayIndexOutOfBoundsException occurs when Container with overridden getComponents() is deserialized
aivanov
parents:
diff
changeset
|
42 |
ZContainer z = new ZContainer(); |
a5914bdb193c
8059590: ArrayIndexOutOfBoundsException occurs when Container with overridden getComponents() is deserialized
aivanov
parents:
diff
changeset
|
43 |
z.add(new Button()); |
a5914bdb193c
8059590: ArrayIndexOutOfBoundsException occurs when Container with overridden getComponents() is deserialized
aivanov
parents:
diff
changeset
|
44 |
|
a5914bdb193c
8059590: ArrayIndexOutOfBoundsException occurs when Container with overridden getComponents() is deserialized
aivanov
parents:
diff
changeset
|
45 |
ByteArrayOutputStream baos = new ByteArrayOutputStream(); |
a5914bdb193c
8059590: ArrayIndexOutOfBoundsException occurs when Container with overridden getComponents() is deserialized
aivanov
parents:
diff
changeset
|
46 |
ObjectOutputStream oos = new ObjectOutputStream(baos); |
a5914bdb193c
8059590: ArrayIndexOutOfBoundsException occurs when Container with overridden getComponents() is deserialized
aivanov
parents:
diff
changeset
|
47 |
oos.writeObject(z); |
a5914bdb193c
8059590: ArrayIndexOutOfBoundsException occurs when Container with overridden getComponents() is deserialized
aivanov
parents:
diff
changeset
|
48 |
oos.flush(); |
a5914bdb193c
8059590: ArrayIndexOutOfBoundsException occurs when Container with overridden getComponents() is deserialized
aivanov
parents:
diff
changeset
|
49 |
oos.close(); |
a5914bdb193c
8059590: ArrayIndexOutOfBoundsException occurs when Container with overridden getComponents() is deserialized
aivanov
parents:
diff
changeset
|
50 |
|
a5914bdb193c
8059590: ArrayIndexOutOfBoundsException occurs when Container with overridden getComponents() is deserialized
aivanov
parents:
diff
changeset
|
51 |
byte[] array = baos.toByteArray(); |
a5914bdb193c
8059590: ArrayIndexOutOfBoundsException occurs when Container with overridden getComponents() is deserialized
aivanov
parents:
diff
changeset
|
52 |
ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(array)); |
a5914bdb193c
8059590: ArrayIndexOutOfBoundsException occurs when Container with overridden getComponents() is deserialized
aivanov
parents:
diff
changeset
|
53 |
|
a5914bdb193c
8059590: ArrayIndexOutOfBoundsException occurs when Container with overridden getComponents() is deserialized
aivanov
parents:
diff
changeset
|
54 |
// Reading the object must not throw ArrayIndexOutOfBoundsException |
a5914bdb193c
8059590: ArrayIndexOutOfBoundsException occurs when Container with overridden getComponents() is deserialized
aivanov
parents:
diff
changeset
|
55 |
ZContainer zz = (ZContainer) ois.readObject(); |
a5914bdb193c
8059590: ArrayIndexOutOfBoundsException occurs when Container with overridden getComponents() is deserialized
aivanov
parents:
diff
changeset
|
56 |
|
a5914bdb193c
8059590: ArrayIndexOutOfBoundsException occurs when Container with overridden getComponents() is deserialized
aivanov
parents:
diff
changeset
|
57 |
if (zz.getComponentCount() != 1) { |
a5914bdb193c
8059590: ArrayIndexOutOfBoundsException occurs when Container with overridden getComponents() is deserialized
aivanov
parents:
diff
changeset
|
58 |
throw new Exception("deserialized object must have 1 component"); |
a5914bdb193c
8059590: ArrayIndexOutOfBoundsException occurs when Container with overridden getComponents() is deserialized
aivanov
parents:
diff
changeset
|
59 |
} |
a5914bdb193c
8059590: ArrayIndexOutOfBoundsException occurs when Container with overridden getComponents() is deserialized
aivanov
parents:
diff
changeset
|
60 |
if (!(zz.getComponent(0) instanceof Button)) { |
a5914bdb193c
8059590: ArrayIndexOutOfBoundsException occurs when Container with overridden getComponents() is deserialized
aivanov
parents:
diff
changeset
|
61 |
throw new Exception("deserialized object must contain Button component"); |
a5914bdb193c
8059590: ArrayIndexOutOfBoundsException occurs when Container with overridden getComponents() is deserialized
aivanov
parents:
diff
changeset
|
62 |
} |
a5914bdb193c
8059590: ArrayIndexOutOfBoundsException occurs when Container with overridden getComponents() is deserialized
aivanov
parents:
diff
changeset
|
63 |
if (zz.getComponents().length != 0) { |
a5914bdb193c
8059590: ArrayIndexOutOfBoundsException occurs when Container with overridden getComponents() is deserialized
aivanov
parents:
diff
changeset
|
64 |
throw new Exception("deserialized object returns non-empty array"); |
a5914bdb193c
8059590: ArrayIndexOutOfBoundsException occurs when Container with overridden getComponents() is deserialized
aivanov
parents:
diff
changeset
|
65 |
} |
a5914bdb193c
8059590: ArrayIndexOutOfBoundsException occurs when Container with overridden getComponents() is deserialized
aivanov
parents:
diff
changeset
|
66 |
System.out.println("Test passed"); |
a5914bdb193c
8059590: ArrayIndexOutOfBoundsException occurs when Container with overridden getComponents() is deserialized
aivanov
parents:
diff
changeset
|
67 |
} |
a5914bdb193c
8059590: ArrayIndexOutOfBoundsException occurs when Container with overridden getComponents() is deserialized
aivanov
parents:
diff
changeset
|
68 |
|
a5914bdb193c
8059590: ArrayIndexOutOfBoundsException occurs when Container with overridden getComponents() is deserialized
aivanov
parents:
diff
changeset
|
69 |
static class ZContainer extends Container { |
a5914bdb193c
8059590: ArrayIndexOutOfBoundsException occurs when Container with overridden getComponents() is deserialized
aivanov
parents:
diff
changeset
|
70 |
public Component[] getComponents() { |
a5914bdb193c
8059590: ArrayIndexOutOfBoundsException occurs when Container with overridden getComponents() is deserialized
aivanov
parents:
diff
changeset
|
71 |
return new Component[0]; |
a5914bdb193c
8059590: ArrayIndexOutOfBoundsException occurs when Container with overridden getComponents() is deserialized
aivanov
parents:
diff
changeset
|
72 |
} |
a5914bdb193c
8059590: ArrayIndexOutOfBoundsException occurs when Container with overridden getComponents() is deserialized
aivanov
parents:
diff
changeset
|
73 |
} |
a5914bdb193c
8059590: ArrayIndexOutOfBoundsException occurs when Container with overridden getComponents() is deserialized
aivanov
parents:
diff
changeset
|
74 |
} |