27
27
28
28
import com .sun .javafx .SecurityUtil ;
29
29
import java .security .AllPermission ;
30
- import java .security .AccessController ;
31
30
import java .security .PermissionCollection ;
32
31
import java .security .SecureClassLoader ;
33
32
import java .security .CodeSource ;
34
33
import java .io .InputStream ;
35
34
import java .io .IOException ;
36
35
import java .lang .reflect .Method ;
37
36
import java .lang .reflect .InvocationTargetException ;
38
- import java .lang .reflect .Modifier ;
39
- import java .util .Arrays ;
40
- import java .util .HashMap ;
41
- import java .util .Map ;
42
37
43
38
44
39
class Trampoline {
@@ -53,13 +48,11 @@ class Trampoline {
53
48
}
54
49
}
55
50
56
- @ SuppressWarnings ("removal" )
57
51
private static void ensureInvocableMethod (Method m )
58
52
throws InvocationTargetException
59
53
{
60
54
Class <?> clazz = m .getDeclaringClass ();
61
- if (clazz .equals (AccessController .class ) ||
62
- clazz .equals (Method .class ) ||
55
+ if (clazz .equals (Method .class ) ||
63
56
clazz .getName ().startsWith ("java.lang.invoke." ))
64
57
throw new InvocationTargetException (
65
58
new UnsupportedOperationException ("invocation not supported" ));
@@ -102,163 +95,6 @@ public static Method[] getMethods(Class<?> cls) {
102
95
return cls .getMethods ();
103
96
}
104
97
105
- /*
106
- * Discover the public methods on public classes
107
- * and interfaces accessible to any caller by calling
108
- * Class.getMethods() and walking towards Object until
109
- * we're done.
110
- */
111
- /*public*/
112
- @ SuppressWarnings ("removal" )
113
- static Method [] getPublicMethods (Class <?> cls ) {
114
- // compatibility for update release
115
- if (System .getSecurityManager () == null ) {
116
- return cls .getMethods ();
117
- }
118
- Map <Signature , Method > sigs = new HashMap <>();
119
- while (cls != null ) {
120
- boolean done = getInternalPublicMethods (cls , sigs );
121
- if (done ) {
122
- break ;
123
- }
124
- getInterfaceMethods (cls , sigs );
125
- cls = cls .getSuperclass ();
126
- }
127
- return sigs .values ().toArray (new Method [sigs .size ()]);
128
- }
129
-
130
- /*
131
- * Process the immediate interfaces of this class or interface.
132
- */
133
- private static void getInterfaceMethods (Class <?> cls ,
134
- Map <Signature , Method > sigs ) {
135
- Class <?>[] intfs = cls .getInterfaces ();
136
- for (int i =0 ; i < intfs .length ; i ++) {
137
- Class <?> intf = intfs [i ];
138
- boolean done = getInternalPublicMethods (intf , sigs );
139
- if (!done ) {
140
- getInterfaceMethods (intf , sigs );
141
- }
142
- }
143
- }
144
-
145
- /*
146
- *
147
- * Process the methods in this class or interface
148
- */
149
- private static boolean getInternalPublicMethods (Class <?> cls ,
150
- Map <Signature , Method > sigs ) {
151
- Method [] methods = null ;
152
- try {
153
- /*
154
- * This class or interface is non-public so we
155
- * can't use any of it's methods. Go back and
156
- * try again with a superclass or superinterface.
157
- */
158
- if (!Modifier .isPublic (cls .getModifiers ())) {
159
- return false ;
160
- }
161
- if (!ReflectUtil .isPackageAccessible (cls )) {
162
- return false ;
163
- }
164
-
165
- methods = cls .getMethods ();
166
- } catch (SecurityException se ) {
167
- return false ;
168
- }
169
-
170
- /*
171
- * Check for inherited methods with non-public
172
- * declaring classes. They might override and hide
173
- * methods from their superclasses or
174
- * superinterfaces.
175
- */
176
- boolean done = true ;
177
- for (int i =0 ; i < methods .length ; i ++) {
178
- Class <?> dc = methods [i ].getDeclaringClass ();
179
- if (!Modifier .isPublic (dc .getModifiers ())) {
180
- done = false ;
181
- break ;
182
- }
183
- }
184
-
185
- if (done ) {
186
- /*
187
- * We're done. Spray all the methods into
188
- * the list and then we're out of here.
189
- */
190
- for (int i =0 ; i < methods .length ; i ++) {
191
- addMethod (sigs , methods [i ]);
192
- }
193
- } else {
194
- /*
195
- * Simulate cls.getDeclaredMethods() by
196
- * stripping away inherited methods.
197
- */
198
- for (int i =0 ; i < methods .length ; i ++) {
199
- Class <?> dc = methods [i ].getDeclaringClass ();
200
- if (cls .equals (dc )) {
201
- addMethod (sigs , methods [i ]);
202
- }
203
- }
204
- }
205
- return done ;
206
- }
207
-
208
- private static void addMethod (Map <Signature , Method > sigs , Method method ) {
209
- Signature signature = new Signature (method );
210
- if (!sigs .containsKey (signature )) {
211
- sigs .put (signature , method );
212
- } else if (!method .getDeclaringClass ().isInterface ()){
213
- /*
214
- * Superclasses beat interfaces.
215
- */
216
- Method old = sigs .get (signature );
217
- if (old .getDeclaringClass ().isInterface ()) {
218
- sigs .put (signature , method );
219
- }
220
- }
221
- }
222
-
223
- /**
224
- * A class that represents the unique elements of a method that will be a
225
- * key in the method cache.
226
- */
227
- private static class Signature {
228
- private final String methodName ;
229
- private final Class <?>[] argClasses ;
230
- private final int hashCode ;
231
-
232
- Signature (Method m ) {
233
- this .methodName = m .getName ();
234
- this .argClasses = m .getParameterTypes ();
235
- this .hashCode = methodName .hashCode () + Arrays .hashCode (argClasses );
236
- }
237
-
238
- @ Override public int hashCode () {
239
- return hashCode ;
240
- }
241
-
242
- @ Override public boolean equals (Object o2 ) {
243
- if (this == o2 ) {
244
- return true ;
245
- }
246
- Signature that = (Signature )o2 ;
247
- if (!(methodName .equals (that .methodName ))) {
248
- return false ;
249
- }
250
- if (argClasses .length != that .argClasses .length ) {
251
- return false ;
252
- }
253
- for (int i = 0 ; i < argClasses .length ; i ++) {
254
- if (!(argClasses [i ] == that .argClasses [i ])) {
255
- return false ;
256
- }
257
- }
258
- return true ;
259
- }
260
- }
261
-
262
98
263
99
/*
264
100
* Get the (unnamed) module of the trampoline class
0 commit comments