blob: 033384cab8a7ceca939933c1fad539e5a6d2b782 [file] [log] [blame]
igerasimb8b04252015-09-08 22:31:26 +03001/*
2 * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
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/* @test
25 * @bug 8135043
26 * @summary ObjectStreamClass.getField(String) too restrictive
27 */
28
29import java.io.ByteArrayInputStream;
30import java.io.ByteArrayOutputStream;
31import java.io.IOException;
32import java.io.InputStream;
33import java.io.ObjectInputStream;
34import java.io.ObjectOutputStream;
35import java.io.ObjectStreamClass;
36import java.io.Serializable;
37
38public class TestObjectStreamClass {
39
40 public static void main(String[] args) throws Exception {
41 ByteArrayOutputStream byteOutput = new ByteArrayOutputStream();
42 ObjectOutputStream output = new ObjectOutputStream(byteOutput);
43 output.writeObject(new TestClass());
44
45 ByteArrayInputStream bais = new ByteArrayInputStream(byteOutput.toByteArray());
46 TestObjectInputStream input = new TestObjectInputStream(bais);
47 input.readObject();
48
49 ObjectStreamClass osc = input.getDescriptor();
50
51 // All OSC public API methods should complete without throwing.
52 osc.getName();
53 osc.forClass();
54 osc.getField("str");
55 osc.getFields();
56 osc.getSerialVersionUID();
57 osc.toString();
58 }
59
60 static class TestClass implements Serializable {
61 String str = "hello world";
62 }
63
64 static class TestObjectInputStream extends ObjectInputStream {
65 private ObjectStreamClass objectStreamClass;
66
67 public TestObjectInputStream(InputStream in) throws IOException {
68 super(in);
69 }
70
71 public ObjectStreamClass getDescriptor()
72 throws IOException, ClassNotFoundException
73 {
74 return objectStreamClass;
75 }
76
77 public ObjectStreamClass readClassDescriptor()
78 throws IOException, ClassNotFoundException
79 {
80 objectStreamClass = super.readClassDescriptor();
81 return objectStreamClass;
82 }
83 }
84}