test/jdk/java/io/Serializable/defaultReadObjectCNFException/DefaultReadObjectCNFException.java
equal
deleted
inserted
replaced
1 /* |
1 /* |
2 * Copyright (c) 2002, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 2002, 2019, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
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 |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. |
7 * published by the Free Software Foundation. |
29 */ |
29 */ |
30 |
30 |
31 import java.io.*; |
31 import java.io.*; |
32 |
32 |
33 class Foo implements Serializable { |
33 class Foo implements Serializable { |
|
34 private static final long serialVersionUID = 1L; |
|
35 |
|
36 @SuppressWarnings("serial") /* Incorrect use is being tested */ |
34 Object obj = new Bar(); |
37 Object obj = new Bar(); |
35 |
38 |
36 private void readObject(ObjectInputStream in) |
39 private void readObject(ObjectInputStream in) |
37 throws IOException, ClassNotFoundException |
40 throws IOException, ClassNotFoundException |
38 { |
41 { |
42 "ClassNotFoundException masked by defaultReadObject()"); |
45 "ClassNotFoundException masked by defaultReadObject()"); |
43 } |
46 } |
44 } |
47 } |
45 } |
48 } |
46 |
49 |
47 class Bar implements Serializable {} |
50 class Bar implements Serializable { |
|
51 private static final long serialVersionUID = 1L; |
|
52 } |
48 |
53 |
49 class TestObjectInputStream extends ObjectInputStream { |
54 class TestObjectInputStream extends ObjectInputStream { |
50 TestObjectInputStream(InputStream in) throws IOException { super(in); } |
55 TestObjectInputStream(InputStream in) throws IOException { super(in); } |
51 |
56 |
52 protected Class resolveClass(ObjectStreamClass desc) |
57 protected Class<?> resolveClass(ObjectStreamClass desc) |
53 throws IOException, ClassNotFoundException |
58 throws IOException, ClassNotFoundException |
54 { |
59 { |
55 if (desc.getName().equals(Bar.class.getName())) { |
60 if (desc.getName().equals(Bar.class.getName())) { |
56 throw new ClassNotFoundException(); |
61 throw new ClassNotFoundException(); |
57 } |
62 } |