1 /* |
1 /* |
2 * Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 2000, 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. |
34 interface Foo { int foo(); } |
34 interface Foo { int foo(); } |
35 interface Bar { float bar(); } |
35 interface Bar { float bar(); } |
36 |
36 |
37 // dummy invocation handler |
37 // dummy invocation handler |
38 class Handler implements InvocationHandler, Serializable { |
38 class Handler implements InvocationHandler, Serializable { |
|
39 private static final long serialVersionUID = 1L; |
39 |
40 |
40 static Method fooMethod, barMethod; |
41 static Method fooMethod, barMethod; |
41 static { |
42 static { |
42 try { |
43 try { |
43 fooMethod = Foo.class.getDeclaredMethod("foo", new Class[0]); |
44 fooMethod = Foo.class.getDeclaredMethod("foo", new Class<?>[0]); |
44 barMethod = Bar.class.getDeclaredMethod("bar", new Class[0]); |
45 barMethod = Bar.class.getDeclaredMethod("bar", new Class<?>[0]); |
45 } catch (NoSuchMethodException ex) { |
46 } catch (NoSuchMethodException ex) { |
46 throw new Error(); |
47 throw new Error(); |
47 } |
48 } |
48 } |
49 } |
49 |
50 |
57 |
58 |
58 public Object invoke(Object proxy, Method method, Object[] args) |
59 public Object invoke(Object proxy, Method method, Object[] args) |
59 throws Throwable |
60 throws Throwable |
60 { |
61 { |
61 if (method.equals(fooMethod)) { |
62 if (method.equals(fooMethod)) { |
62 return new Integer(foo); |
63 return foo; |
63 } else if (method.equals(barMethod)) { |
64 } else if (method.equals(barMethod)) { |
64 return new Float(bar); |
65 return bar; |
65 } else { |
66 } else { |
66 throw new UnsupportedOperationException(); |
67 throw new UnsupportedOperationException(); |
67 } |
68 } |
68 } |
69 } |
69 } |
70 } |
71 // ObjectInputStream incapable of resolving proxy classes |
72 // ObjectInputStream incapable of resolving proxy classes |
72 class ProxyBlindInputStream extends ObjectInputStream { |
73 class ProxyBlindInputStream extends ObjectInputStream { |
73 |
74 |
74 ProxyBlindInputStream(InputStream in) throws IOException { super(in); } |
75 ProxyBlindInputStream(InputStream in) throws IOException { super(in); } |
75 |
76 |
76 protected Class resolveProxyClass(String[] interfaces) |
77 protected Class<?> resolveProxyClass(String[] interfaces) |
77 throws IOException, ClassNotFoundException |
78 throws IOException, ClassNotFoundException |
78 { |
79 { |
79 throw new ClassNotFoundException(); |
80 throw new ClassNotFoundException(); |
80 } |
81 } |
81 } |
82 } |
82 |
83 |
83 public class Basic { |
84 public class Basic { |
84 public static void main(String[] args) throws Exception { |
85 public static void main(String[] args) throws Exception { |
85 ClassLoader loader = Basic.class.getClassLoader(); |
86 ClassLoader loader = Basic.class.getClassLoader(); |
86 Class[] interfaces = new Class[] { Foo.class, Bar.class }; |
87 Class<?>[] interfaces = { Foo.class, Bar.class }; |
87 Random rand = new Random(); |
88 Random rand = new Random(); |
88 int foo = rand.nextInt(); |
89 int foo = rand.nextInt(); |
89 float bar = rand.nextFloat(); |
90 float bar = rand.nextFloat(); |
90 ObjectOutputStream oout; |
91 ObjectOutputStream oout; |
91 ObjectInputStream oin; |
92 ObjectInputStream oin; |