20 * or visit www.oracle.com if you need additional information or have any |
20 * or visit www.oracle.com if you need additional information or have any |
21 * questions. |
21 * questions. |
22 */ |
22 */ |
23 |
23 |
24 /* @test |
24 /* @test |
25 * @bug 4413817 |
25 * @bug 4413817 8004928 |
26 * @summary Verify that ObjectInputStream.resolveProxyClass can properly |
26 * @summary Verify that ObjectInputStream.resolveProxyClass can properly |
27 * resolve a dynamic proxy class which implements a non-public |
27 * resolve a dynamic proxy class which implements a non-public |
28 * interface not defined in the latest user defined class loader. |
28 * interface not defined in the latest user defined class loader. |
29 */ |
29 */ |
30 |
30 |
31 import java.io.*; |
31 import java.io.*; |
32 import java.lang.reflect.*; |
32 import java.lang.reflect.InvocationHandler; |
|
33 import java.lang.reflect.Method; |
|
34 import java.lang.reflect.Modifier; |
|
35 import java.lang.reflect.Proxy; |
33 |
36 |
34 public class NonPublicInterface { |
37 public class NonPublicInterface { |
35 |
38 |
36 static class Handler implements InvocationHandler, Serializable { |
39 static class Handler implements InvocationHandler, Serializable { |
37 public Object invoke(Object obj, Method meth, Object[] args) { |
40 public Object invoke(Object obj, Method meth, Object[] args) { |
38 return null; |
41 return null; |
39 } |
42 } |
40 } |
43 } |
41 |
44 |
|
45 public static final String nonPublicIntrfaceName = "java.util.zip.ZipConstants"; |
|
46 |
42 public static void main(String[] args) throws Exception { |
47 public static void main(String[] args) throws Exception { |
43 Class nonPublic = null; |
48 Class<?> nonPublic = Class.forName(nonPublicIntrfaceName); |
44 String[] nonPublicInterfaces = new String[] { |
49 if (Modifier.isPublic(nonPublic.getModifiers())) { |
45 "java.awt.Conditional", |
50 throw new Error("Interface " + nonPublicIntrfaceName + |
46 "java.util.zip.ZipConstants", |
51 " is public and need to be changed!"); |
47 "javax.swing.GraphicsWrapper", |
|
48 "javax.swing.JPopupMenu$Popup", |
|
49 "javax.swing.JTable$Resizable2", |
|
50 "javax.swing.JTable$Resizable3", |
|
51 "javax.swing.ToolTipManager$Popup", |
|
52 "sun.audio.Format", |
|
53 "sun.audio.HaePlayable", |
|
54 "sun.tools.agent.StepConstants", |
|
55 }; |
|
56 for (int i = 0; i < nonPublicInterfaces.length; i++) { |
|
57 try { |
|
58 nonPublic = Class.forName(nonPublicInterfaces[i]); |
|
59 break; |
|
60 } catch (ClassNotFoundException ex) { |
|
61 } |
|
62 } |
|
63 if (nonPublic == null) { |
|
64 throw new Error("couldn't find system non-public interface"); |
|
65 } |
52 } |
66 |
53 |
67 ByteArrayOutputStream bout = new ByteArrayOutputStream(); |
54 ByteArrayOutputStream bout = new ByteArrayOutputStream(); |
68 ObjectOutputStream oout = new ObjectOutputStream(bout); |
55 ObjectOutputStream oout = new ObjectOutputStream(bout); |
69 oout.writeObject(Proxy.newProxyInstance(nonPublic.getClassLoader(), |
56 oout.writeObject(Proxy.newProxyInstance(nonPublic.getClassLoader(), |
70 new Class[]{ nonPublic }, new Handler())); |
57 new Class<?>[]{ nonPublic }, new Handler())); |
71 oout.close(); |
58 oout.close(); |
72 ObjectInputStream oin = new ObjectInputStream( |
59 ObjectInputStream oin = new ObjectInputStream( |
73 new ByteArrayInputStream(bout.toByteArray())); |
60 new ByteArrayInputStream(bout.toByteArray())); |
74 oin.readObject(); |
61 oin.readObject(); |
75 } |
62 } |