author | chegar |
Thu, 17 Oct 2019 20:54:25 +0100 | |
branch | datagramsocketimpl-branch |
changeset 58679 | 9c3209ff7550 |
parent 58678 | 9cf78a70fa4f |
parent 58242 | 94bb65cb37d3 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
54952
a978d86ac389
8224175: Fix inconsistencies in @jls and @jvms tags
darcy
parents:
52427
diff
changeset
|
2 |
* Copyright (c) 1996, 2019, Oracle and/or its affiliates. All rights reserved. |
2 | 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 |
|
5506 | 7 |
* published by the Free Software Foundation. Oracle designates this |
2 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
2 | 10 |
* |
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
5506 | 21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
2 | 24 |
*/ |
25 |
||
26 |
package java.lang.reflect; |
|
27 |
||
31671
362e0c0acece
8076112: Add @HotSpotIntrinsicCandidate annotation to indicate methods for which Java Runtime has intrinsics
zmajo
parents:
29125
diff
changeset
|
28 |
import jdk.internal.HotSpotIntrinsicCandidate; |
52427
3c6aa484536c
8211122: Reduce the number of internal classes made accessible to jdk.unsupported
mchung
parents:
52380
diff
changeset
|
29 |
import jdk.internal.access.SharedSecrets; |
37363
329dba26ffd2
8137058: Clear out all non-Critical APIs from sun.reflect
chegar
parents:
36511
diff
changeset
|
30 |
import jdk.internal.reflect.CallerSensitive; |
329dba26ffd2
8137058: Clear out all non-Critical APIs from sun.reflect
chegar
parents:
36511
diff
changeset
|
31 |
import jdk.internal.reflect.MethodAccessor; |
329dba26ffd2
8137058: Clear out all non-Critical APIs from sun.reflect
chegar
parents:
36511
diff
changeset
|
32 |
import jdk.internal.reflect.Reflection; |
40175
8df87018d96a
8161379: Force inline methods calling Reflection.getCallerClass
redestad
parents:
38882
diff
changeset
|
33 |
import jdk.internal.vm.annotation.ForceInline; |
38882
efb06b82374b
5041778: (ann) AnnotationFormatError if "default" Class type not found
darcy
parents:
37363
diff
changeset
|
34 |
import sun.reflect.annotation.ExceptionProxy; |
efb06b82374b
5041778: (ann) AnnotationFormatError if "default" Class type not found
darcy
parents:
37363
diff
changeset
|
35 |
import sun.reflect.annotation.TypeNotPresentExceptionProxy; |
2 | 36 |
import sun.reflect.generics.repository.MethodRepository; |
37 |
import sun.reflect.generics.factory.CoreReflectionFactory; |
|
38 |
import sun.reflect.generics.factory.GenericsFactory; |
|
39 |
import sun.reflect.generics.scope.MethodScope; |
|
40 |
import sun.reflect.annotation.AnnotationType; |
|
41 |
import sun.reflect.annotation.AnnotationParser; |
|
42 |
import java.lang.annotation.Annotation; |
|
43 |
import java.lang.annotation.AnnotationFormatError; |
|
44 |
import java.nio.ByteBuffer; |
|
44359
c6761862ca0b
8174823: Module system implementation refresh (3/2017)
alanb
parents:
43712
diff
changeset
|
45 |
import java.util.StringJoiner; |
2 | 46 |
|
47 |
/** |
|
48 |
* A {@code Method} provides information about, and access to, a single method |
|
49 |
* on a class or interface. The reflected method may be a class method |
|
50 |
* or an instance method (including an abstract method). |
|
51 |
* |
|
52 |
* <p>A {@code Method} permits widening conversions to occur when matching the |
|
53 |
* actual parameters to invoke with the underlying method's formal |
|
54 |
* parameters, but it throws an {@code IllegalArgumentException} if a |
|
55 |
* narrowing conversion would occur. |
|
56 |
* |
|
57 |
* @see Member |
|
58 |
* @see java.lang.Class |
|
59 |
* @see java.lang.Class#getMethods() |
|
60 |
* @see java.lang.Class#getMethod(String, Class[]) |
|
61 |
* @see java.lang.Class#getDeclaredMethods() |
|
62 |
* @see java.lang.Class#getDeclaredMethod(String, Class[]) |
|
63 |
* |
|
64 |
* @author Kenneth Russell |
|
65 |
* @author Nakul Saraiya |
|
45434
4582657c7260
8181082: class-level since tag issues in java.base & java.datatransfer module
mli
parents:
45332
diff
changeset
|
66 |
* @since 1.1 |
2 | 67 |
*/ |
10127
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
9266
diff
changeset
|
68 |
public final class Method extends Executable { |
3959
05a07c0a273b
5062288: (reflect) Core reflection uses raw types when it could be using wildcards
darcy
parents:
3941
diff
changeset
|
69 |
private Class<?> clazz; |
2 | 70 |
private int slot; |
71 |
// This is guaranteed to be interned by the VM in the 1.4 |
|
72 |
// reflection implementation |
|
73 |
private String name; |
|
3959
05a07c0a273b
5062288: (reflect) Core reflection uses raw types when it could be using wildcards
darcy
parents:
3941
diff
changeset
|
74 |
private Class<?> returnType; |
05a07c0a273b
5062288: (reflect) Core reflection uses raw types when it could be using wildcards
darcy
parents:
3941
diff
changeset
|
75 |
private Class<?>[] parameterTypes; |
05a07c0a273b
5062288: (reflect) Core reflection uses raw types when it could be using wildcards
darcy
parents:
3941
diff
changeset
|
76 |
private Class<?>[] exceptionTypes; |
2 | 77 |
private int modifiers; |
78 |
// Generics and annotations support |
|
79 |
private transient String signature; |
|
80 |
// generic info repository; lazily initialized |
|
81 |
private transient MethodRepository genericInfo; |
|
82 |
private byte[] annotations; |
|
83 |
private byte[] parameterAnnotations; |
|
84 |
private byte[] annotationDefault; |
|
85 |
private volatile MethodAccessor methodAccessor; |
|
86 |
// For sharing of MethodAccessors. This branching structure is |
|
87 |
// currently only two levels deep (i.e., one root Method and |
|
88 |
// potentially many Method objects pointing to it.) |
|
26455
195a6f3e0cd0
8054987: (reflect) Add sharing of annotations between instances of Executable
jfranck
parents:
25859
diff
changeset
|
89 |
// |
195a6f3e0cd0
8054987: (reflect) Add sharing of annotations between instances of Executable
jfranck
parents:
25859
diff
changeset
|
90 |
// If this branching structure would ever contain cycles, deadlocks can |
195a6f3e0cd0
8054987: (reflect) Add sharing of annotations between instances of Executable
jfranck
parents:
25859
diff
changeset
|
91 |
// occur in annotation code. |
2 | 92 |
private Method root; |
93 |
||
10127
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
9266
diff
changeset
|
94 |
// Generics infrastructure |
2 | 95 |
private String getGenericSignature() {return signature;} |
96 |
||
97 |
// Accessor for factory |
|
98 |
private GenericsFactory getFactory() { |
|
99 |
// create scope and factory |
|
100 |
return CoreReflectionFactory.make(this, MethodScope.make(this)); |
|
101 |
} |
|
102 |
||
103 |
// Accessor for generic info repository |
|
10127
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
9266
diff
changeset
|
104 |
@Override |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
9266
diff
changeset
|
105 |
MethodRepository getGenericInfo() { |
2 | 106 |
// lazily initialize repository if necessary |
107 |
if (genericInfo == null) { |
|
108 |
// create and cache generic info repository |
|
109 |
genericInfo = MethodRepository.make(getGenericSignature(), |
|
110 |
getFactory()); |
|
111 |
} |
|
112 |
return genericInfo; //return cached repository |
|
113 |
} |
|
114 |
||
115 |
/** |
|
57503
042dfb697624
8219774: Reexamine the initialization of LangReflectAccess shared secret at AccessibleObject::<clinit>
mchung
parents:
55337
diff
changeset
|
116 |
* Package-private constructor |
2 | 117 |
*/ |
3959
05a07c0a273b
5062288: (reflect) Core reflection uses raw types when it could be using wildcards
darcy
parents:
3941
diff
changeset
|
118 |
Method(Class<?> declaringClass, |
2 | 119 |
String name, |
3959
05a07c0a273b
5062288: (reflect) Core reflection uses raw types when it could be using wildcards
darcy
parents:
3941
diff
changeset
|
120 |
Class<?>[] parameterTypes, |
05a07c0a273b
5062288: (reflect) Core reflection uses raw types when it could be using wildcards
darcy
parents:
3941
diff
changeset
|
121 |
Class<?> returnType, |
05a07c0a273b
5062288: (reflect) Core reflection uses raw types when it could be using wildcards
darcy
parents:
3941
diff
changeset
|
122 |
Class<?>[] checkedExceptions, |
2 | 123 |
int modifiers, |
124 |
int slot, |
|
125 |
String signature, |
|
126 |
byte[] annotations, |
|
127 |
byte[] parameterAnnotations, |
|
10127
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
9266
diff
changeset
|
128 |
byte[] annotationDefault) { |
2 | 129 |
this.clazz = declaringClass; |
130 |
this.name = name; |
|
131 |
this.parameterTypes = parameterTypes; |
|
132 |
this.returnType = returnType; |
|
133 |
this.exceptionTypes = checkedExceptions; |
|
134 |
this.modifiers = modifiers; |
|
135 |
this.slot = slot; |
|
136 |
this.signature = signature; |
|
137 |
this.annotations = annotations; |
|
138 |
this.parameterAnnotations = parameterAnnotations; |
|
139 |
this.annotationDefault = annotationDefault; |
|
140 |
} |
|
141 |
||
142 |
/** |
|
143 |
* Package-private routine (exposed to java.lang.Class via |
|
144 |
* ReflectAccess) which returns a copy of this Method. The copy's |
|
145 |
* "root" field points to this Method. |
|
146 |
*/ |
|
147 |
Method copy() { |
|
148 |
// This routine enables sharing of MethodAccessor objects |
|
149 |
// among Method objects which refer to the same underlying |
|
150 |
// method in the VM. (All of this contortion is only necessary |
|
151 |
// because of the "accessibility" bit in AccessibleObject, |
|
152 |
// which implicitly requires that new java.lang.reflect |
|
153 |
// objects be fabricated for each reflective call on Class |
|
154 |
// objects.) |
|
26455
195a6f3e0cd0
8054987: (reflect) Add sharing of annotations between instances of Executable
jfranck
parents:
25859
diff
changeset
|
155 |
if (this.root != null) |
195a6f3e0cd0
8054987: (reflect) Add sharing of annotations between instances of Executable
jfranck
parents:
25859
diff
changeset
|
156 |
throw new IllegalArgumentException("Can not copy a non-root Method"); |
195a6f3e0cd0
8054987: (reflect) Add sharing of annotations between instances of Executable
jfranck
parents:
25859
diff
changeset
|
157 |
|
2 | 158 |
Method res = new Method(clazz, name, parameterTypes, returnType, |
159 |
exceptionTypes, modifiers, slot, signature, |
|
160 |
annotations, parameterAnnotations, annotationDefault); |
|
161 |
res.root = this; |
|
162 |
// Might as well eagerly propagate this if already present |
|
163 |
res.methodAccessor = methodAccessor; |
|
164 |
return res; |
|
165 |
} |
|
166 |
||
26455
195a6f3e0cd0
8054987: (reflect) Add sharing of annotations between instances of Executable
jfranck
parents:
25859
diff
changeset
|
167 |
/** |
32268
9fe7ee60d49d
8073056: Repeating annotations throws java.security.AccessControlException with a SecurityManager
jfranck
parents:
32033
diff
changeset
|
168 |
* Make a copy of a leaf method. |
9fe7ee60d49d
8073056: Repeating annotations throws java.security.AccessControlException with a SecurityManager
jfranck
parents:
32033
diff
changeset
|
169 |
*/ |
9fe7ee60d49d
8073056: Repeating annotations throws java.security.AccessControlException with a SecurityManager
jfranck
parents:
32033
diff
changeset
|
170 |
Method leafCopy() { |
9fe7ee60d49d
8073056: Repeating annotations throws java.security.AccessControlException with a SecurityManager
jfranck
parents:
32033
diff
changeset
|
171 |
if (this.root == null) |
9fe7ee60d49d
8073056: Repeating annotations throws java.security.AccessControlException with a SecurityManager
jfranck
parents:
32033
diff
changeset
|
172 |
throw new IllegalArgumentException("Can only leafCopy a non-root Method"); |
9fe7ee60d49d
8073056: Repeating annotations throws java.security.AccessControlException with a SecurityManager
jfranck
parents:
32033
diff
changeset
|
173 |
|
9fe7ee60d49d
8073056: Repeating annotations throws java.security.AccessControlException with a SecurityManager
jfranck
parents:
32033
diff
changeset
|
174 |
Method res = new Method(clazz, name, parameterTypes, returnType, |
9fe7ee60d49d
8073056: Repeating annotations throws java.security.AccessControlException with a SecurityManager
jfranck
parents:
32033
diff
changeset
|
175 |
exceptionTypes, modifiers, slot, signature, |
9fe7ee60d49d
8073056: Repeating annotations throws java.security.AccessControlException with a SecurityManager
jfranck
parents:
32033
diff
changeset
|
176 |
annotations, parameterAnnotations, annotationDefault); |
9fe7ee60d49d
8073056: Repeating annotations throws java.security.AccessControlException with a SecurityManager
jfranck
parents:
32033
diff
changeset
|
177 |
res.root = root; |
9fe7ee60d49d
8073056: Repeating annotations throws java.security.AccessControlException with a SecurityManager
jfranck
parents:
32033
diff
changeset
|
178 |
res.methodAccessor = methodAccessor; |
9fe7ee60d49d
8073056: Repeating annotations throws java.security.AccessControlException with a SecurityManager
jfranck
parents:
32033
diff
changeset
|
179 |
return res; |
9fe7ee60d49d
8073056: Repeating annotations throws java.security.AccessControlException with a SecurityManager
jfranck
parents:
32033
diff
changeset
|
180 |
} |
9fe7ee60d49d
8073056: Repeating annotations throws java.security.AccessControlException with a SecurityManager
jfranck
parents:
32033
diff
changeset
|
181 |
|
43712
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42997
diff
changeset
|
182 |
/** |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42997
diff
changeset
|
183 |
* @throws InaccessibleObjectException {@inheritDoc} |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42997
diff
changeset
|
184 |
* @throws SecurityException {@inheritDoc} |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42997
diff
changeset
|
185 |
*/ |
36511 | 186 |
@Override |
187 |
@CallerSensitive |
|
188 |
public void setAccessible(boolean flag) { |
|
189 |
AccessibleObject.checkPermission(); |
|
190 |
if (flag) checkCanSetAccessible(Reflection.getCallerClass()); |
|
191 |
setAccessible0(flag); |
|
192 |
} |
|
193 |
||
194 |
@Override |
|
195 |
void checkCanSetAccessible(Class<?> caller) { |
|
196 |
checkCanSetAccessible(caller, clazz); |
|
197 |
} |
|
198 |
||
26455
195a6f3e0cd0
8054987: (reflect) Add sharing of annotations between instances of Executable
jfranck
parents:
25859
diff
changeset
|
199 |
@Override |
50091
05979f6ba560
8202113: Reflection API is causing caller classes to leak
mchung
parents:
49273
diff
changeset
|
200 |
Method getRoot() { |
26455
195a6f3e0cd0
8054987: (reflect) Add sharing of annotations between instances of Executable
jfranck
parents:
25859
diff
changeset
|
201 |
return root; |
195a6f3e0cd0
8054987: (reflect) Add sharing of annotations between instances of Executable
jfranck
parents:
25859
diff
changeset
|
202 |
} |
195a6f3e0cd0
8054987: (reflect) Add sharing of annotations between instances of Executable
jfranck
parents:
25859
diff
changeset
|
203 |
|
10127
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
9266
diff
changeset
|
204 |
@Override |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
9266
diff
changeset
|
205 |
boolean hasGenericInformation() { |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
9266
diff
changeset
|
206 |
return (getGenericSignature() != null); |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
9266
diff
changeset
|
207 |
} |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
9266
diff
changeset
|
208 |
|
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
9266
diff
changeset
|
209 |
@Override |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
9266
diff
changeset
|
210 |
byte[] getAnnotationBytes() { |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
9266
diff
changeset
|
211 |
return annotations; |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
9266
diff
changeset
|
212 |
} |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
9266
diff
changeset
|
213 |
|
2 | 214 |
/** |
42228
dd6cc832ffd4
8169479: java.lang.reflect.Constructor class has wrong api documentation
darcy
parents:
41560
diff
changeset
|
215 |
* Returns the {@code Class} object representing the class or interface |
dd6cc832ffd4
8169479: java.lang.reflect.Constructor class has wrong api documentation
darcy
parents:
41560
diff
changeset
|
216 |
* that declares the method represented by this object. |
2 | 217 |
*/ |
10127
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
9266
diff
changeset
|
218 |
@Override |
2 | 219 |
public Class<?> getDeclaringClass() { |
220 |
return clazz; |
|
221 |
} |
|
222 |
||
223 |
/** |
|
224 |
* Returns the name of the method represented by this {@code Method} |
|
225 |
* object, as a {@code String}. |
|
226 |
*/ |
|
10127
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
9266
diff
changeset
|
227 |
@Override |
2 | 228 |
public String getName() { |
229 |
return name; |
|
230 |
} |
|
231 |
||
232 |
/** |
|
10127
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
9266
diff
changeset
|
233 |
* {@inheritDoc} |
2 | 234 |
*/ |
10127
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
9266
diff
changeset
|
235 |
@Override |
2 | 236 |
public int getModifiers() { |
237 |
return modifiers; |
|
238 |
} |
|
239 |
||
240 |
/** |
|
10127
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
9266
diff
changeset
|
241 |
* {@inheritDoc} |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
9266
diff
changeset
|
242 |
* @throws GenericSignatureFormatError {@inheritDoc} |
2 | 243 |
* @since 1.5 |
244 |
*/ |
|
10127
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
9266
diff
changeset
|
245 |
@Override |
13795
73850c397272
7193406: Clean-up JDK Build Warnings in java.util, java.io
dxu
parents:
10342
diff
changeset
|
246 |
@SuppressWarnings({"rawtypes", "unchecked"}) |
2 | 247 |
public TypeVariable<Method>[] getTypeParameters() { |
248 |
if (getGenericSignature() != null) |
|
249 |
return (TypeVariable<Method>[])getGenericInfo().getTypeParameters(); |
|
250 |
else |
|
251 |
return (TypeVariable<Method>[])new TypeVariable[0]; |
|
252 |
} |
|
253 |
||
254 |
/** |
|
255 |
* Returns a {@code Class} object that represents the formal return type |
|
256 |
* of the method represented by this {@code Method} object. |
|
257 |
* |
|
258 |
* @return the return type for the method this object represents |
|
259 |
*/ |
|
260 |
public Class<?> getReturnType() { |
|
261 |
return returnType; |
|
262 |
} |
|
263 |
||
264 |
/** |
|
265 |
* Returns a {@code Type} object that represents the formal return |
|
266 |
* type of the method represented by this {@code Method} object. |
|
267 |
* |
|
268 |
* <p>If the return type is a parameterized type, |
|
269 |
* the {@code Type} object returned must accurately reflect |
|
55337
ae3dbc712839
7086604: (reflect) Clarifications to javadoc for getGeneric*Type methods in j.l.r
darcy
parents:
54952
diff
changeset
|
270 |
* the actual type arguments used in the source code. |
2 | 271 |
* |
272 |
* <p>If the return type is a type variable or a parameterized type, it |
|
273 |
* is created. Otherwise, it is resolved. |
|
274 |
* |
|
275 |
* @return a {@code Type} object that represents the formal return |
|
276 |
* type of the underlying method |
|
277 |
* @throws GenericSignatureFormatError |
|
278 |
* if the generic method signature does not conform to the format |
|
9266
121fb370f179
7032960: API files in java.awt need to be updated for references to JVM Spec with editions/hyperlinks
jjh
parents:
9029
diff
changeset
|
279 |
* specified in |
121fb370f179
7032960: API files in java.awt need to be updated for references to JVM Spec with editions/hyperlinks
jjh
parents:
9029
diff
changeset
|
280 |
* <cite>The Java™ Virtual Machine Specification</cite> |
2 | 281 |
* @throws TypeNotPresentException if the underlying method's |
282 |
* return type refers to a non-existent type declaration |
|
283 |
* @throws MalformedParameterizedTypeException if the |
|
284 |
* underlying method's return typed refers to a parameterized |
|
285 |
* type that cannot be instantiated for any reason |
|
286 |
* @since 1.5 |
|
287 |
*/ |
|
288 |
public Type getGenericReturnType() { |
|
289 |
if (getGenericSignature() != null) { |
|
290 |
return getGenericInfo().getReturnType(); |
|
291 |
} else { return getReturnType();} |
|
292 |
} |
|
293 |
||
42997
5f83f2054eca
8172190: Re-apply the fix for bugs 8062389, 8029459, 8061950
plevart
parents:
42948
diff
changeset
|
294 |
@Override |
5f83f2054eca
8172190: Re-apply the fix for bugs 8062389, 8029459, 8061950
plevart
parents:
42948
diff
changeset
|
295 |
Class<?>[] getSharedParameterTypes() { |
5f83f2054eca
8172190: Re-apply the fix for bugs 8062389, 8029459, 8061950
plevart
parents:
42948
diff
changeset
|
296 |
return parameterTypes; |
5f83f2054eca
8172190: Re-apply the fix for bugs 8062389, 8029459, 8061950
plevart
parents:
42948
diff
changeset
|
297 |
} |
5f83f2054eca
8172190: Re-apply the fix for bugs 8062389, 8029459, 8061950
plevart
parents:
42948
diff
changeset
|
298 |
|
49273
af8ab4f90a32
8199862: Examine ProxyBuilder::referencedTypes startup cost
redestad
parents:
47216
diff
changeset
|
299 |
@Override |
af8ab4f90a32
8199862: Examine ProxyBuilder::referencedTypes startup cost
redestad
parents:
47216
diff
changeset
|
300 |
Class<?>[] getSharedExceptionTypes() { |
af8ab4f90a32
8199862: Examine ProxyBuilder::referencedTypes startup cost
redestad
parents:
47216
diff
changeset
|
301 |
return exceptionTypes; |
af8ab4f90a32
8199862: Examine ProxyBuilder::referencedTypes startup cost
redestad
parents:
47216
diff
changeset
|
302 |
} |
af8ab4f90a32
8199862: Examine ProxyBuilder::referencedTypes startup cost
redestad
parents:
47216
diff
changeset
|
303 |
|
2 | 304 |
/** |
10127
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
9266
diff
changeset
|
305 |
* {@inheritDoc} |
2 | 306 |
*/ |
10127
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
9266
diff
changeset
|
307 |
@Override |
2 | 308 |
public Class<?>[] getParameterTypes() { |
10342
ca0984bc9d32
7077389: Reflection classes do not build with javac -Xlint:all -Werror
jjg
parents:
10127
diff
changeset
|
309 |
return parameterTypes.clone(); |
2 | 310 |
} |
311 |
||
312 |
/** |
|
10127
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
9266
diff
changeset
|
313 |
* {@inheritDoc} |
22083
1ac4a52255f4
8030785: Missing "since 1.8" javadoc for java.lang.reflect.Method:getParameterCount
darcy
parents:
20482
diff
changeset
|
314 |
* @since 1.8 |
15294
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
14910
diff
changeset
|
315 |
*/ |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
14910
diff
changeset
|
316 |
public int getParameterCount() { return parameterTypes.length; } |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
14910
diff
changeset
|
317 |
|
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
14910
diff
changeset
|
318 |
|
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
14910
diff
changeset
|
319 |
/** |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
14910
diff
changeset
|
320 |
* {@inheritDoc} |
10127
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
9266
diff
changeset
|
321 |
* @throws GenericSignatureFormatError {@inheritDoc} |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
9266
diff
changeset
|
322 |
* @throws TypeNotPresentException {@inheritDoc} |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
9266
diff
changeset
|
323 |
* @throws MalformedParameterizedTypeException {@inheritDoc} |
2 | 324 |
* @since 1.5 |
325 |
*/ |
|
10127
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
9266
diff
changeset
|
326 |
@Override |
2 | 327 |
public Type[] getGenericParameterTypes() { |
10127
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
9266
diff
changeset
|
328 |
return super.getGenericParameterTypes(); |
2 | 329 |
} |
330 |
||
331 |
/** |
|
10127
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
9266
diff
changeset
|
332 |
* {@inheritDoc} |
2 | 333 |
*/ |
10127
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
9266
diff
changeset
|
334 |
@Override |
2 | 335 |
public Class<?>[] getExceptionTypes() { |
10342
ca0984bc9d32
7077389: Reflection classes do not build with javac -Xlint:all -Werror
jjg
parents:
10127
diff
changeset
|
336 |
return exceptionTypes.clone(); |
2 | 337 |
} |
338 |
||
339 |
/** |
|
10127
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
9266
diff
changeset
|
340 |
* {@inheritDoc} |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
9266
diff
changeset
|
341 |
* @throws GenericSignatureFormatError {@inheritDoc} |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
9266
diff
changeset
|
342 |
* @throws TypeNotPresentException {@inheritDoc} |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
9266
diff
changeset
|
343 |
* @throws MalformedParameterizedTypeException {@inheritDoc} |
2 | 344 |
* @since 1.5 |
345 |
*/ |
|
10127
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
9266
diff
changeset
|
346 |
@Override |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
9266
diff
changeset
|
347 |
public Type[] getGenericExceptionTypes() { |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
9266
diff
changeset
|
348 |
return super.getGenericExceptionTypes(); |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
9266
diff
changeset
|
349 |
} |
2 | 350 |
|
351 |
/** |
|
352 |
* Compares this {@code Method} against the specified object. Returns |
|
353 |
* true if the objects are the same. Two {@code Methods} are the same if |
|
354 |
* they were declared by the same class and have the same name |
|
355 |
* and formal parameter types and return type. |
|
356 |
*/ |
|
357 |
public boolean equals(Object obj) { |
|
358 |
if (obj != null && obj instanceof Method) { |
|
359 |
Method other = (Method)obj; |
|
360 |
if ((getDeclaringClass() == other.getDeclaringClass()) |
|
361 |
&& (getName() == other.getName())) { |
|
362 |
if (!returnType.equals(other.getReturnType())) |
|
363 |
return false; |
|
10127
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
9266
diff
changeset
|
364 |
return equalParamTypes(parameterTypes, other.parameterTypes); |
2 | 365 |
} |
366 |
} |
|
367 |
return false; |
|
368 |
} |
|
369 |
||
370 |
/** |
|
371 |
* Returns a hashcode for this {@code Method}. The hashcode is computed |
|
372 |
* as the exclusive-or of the hashcodes for the underlying |
|
373 |
* method's declaring class name and the method's name. |
|
374 |
*/ |
|
375 |
public int hashCode() { |
|
376 |
return getDeclaringClass().getName().hashCode() ^ getName().hashCode(); |
|
377 |
} |
|
378 |
||
379 |
/** |
|
380 |
* Returns a string describing this {@code Method}. The string is |
|
381 |
* formatted as the method access modifiers, if any, followed by |
|
382 |
* the method return type, followed by a space, followed by the |
|
383 |
* class declaring the method, followed by a period, followed by |
|
384 |
* the method name, followed by a parenthesized, comma-separated |
|
385 |
* list of the method's formal parameter types. If the method |
|
386 |
* throws checked exceptions, the parameter list is followed by a |
|
42228
dd6cc832ffd4
8169479: java.lang.reflect.Constructor class has wrong api documentation
darcy
parents:
41560
diff
changeset
|
387 |
* space, followed by the word "{@code throws}" followed by a |
2 | 388 |
* comma-separated list of the thrown exception types. |
389 |
* For example: |
|
390 |
* <pre> |
|
391 |
* public boolean java.lang.Object.equals(java.lang.Object) |
|
392 |
* </pre> |
|
393 |
* |
|
394 |
* <p>The access modifiers are placed in canonical order as |
|
395 |
* specified by "The Java Language Specification". This is |
|
396 |
* {@code public}, {@code protected} or {@code private} first, |
|
397 |
* and then other modifiers in the following order: |
|
16743
b0b34102bb4c
6298888: Add toGenericString to j.l.Class and getTypeName to j.l.reflect.Type
darcy
parents:
16729
diff
changeset
|
398 |
* {@code abstract}, {@code default}, {@code static}, {@code final}, |
b0b34102bb4c
6298888: Add toGenericString to j.l.Class and getTypeName to j.l.reflect.Type
darcy
parents:
16729
diff
changeset
|
399 |
* {@code synchronized}, {@code native}, {@code strictfp}. |
16729
3b26e313ad81
8004979: java.lang.reflect.Modifier.toString should include "default"
darcy
parents:
16496
diff
changeset
|
400 |
* |
3b26e313ad81
8004979: java.lang.reflect.Modifier.toString should include "default"
darcy
parents:
16496
diff
changeset
|
401 |
* @return a string describing this {@code Method} |
3b26e313ad81
8004979: java.lang.reflect.Modifier.toString should include "default"
darcy
parents:
16496
diff
changeset
|
402 |
* |
3b26e313ad81
8004979: java.lang.reflect.Modifier.toString should include "default"
darcy
parents:
16496
diff
changeset
|
403 |
* @jls 8.4.3 Method Modifiers |
54952
a978d86ac389
8224175: Fix inconsistencies in @jls and @jvms tags
darcy
parents:
52427
diff
changeset
|
404 |
* @jls 9.4 Method Declarations |
29125
83b9bf8a6c2a
8073952: Spec of j.l.r.Method.toString/toGenericString need to be clarified
darcy
parents:
26455
diff
changeset
|
405 |
* @jls 9.6.1 Annotation Type Elements |
2 | 406 |
*/ |
407 |
public String toString() { |
|
10127
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
9266
diff
changeset
|
408 |
return sharedToString(Modifier.methodModifiers(), |
16729
3b26e313ad81
8004979: java.lang.reflect.Modifier.toString should include "default"
darcy
parents:
16496
diff
changeset
|
409 |
isDefault(), |
10127
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
9266
diff
changeset
|
410 |
parameterTypes, |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
9266
diff
changeset
|
411 |
exceptionTypes); |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
9266
diff
changeset
|
412 |
} |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
9266
diff
changeset
|
413 |
|
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
9266
diff
changeset
|
414 |
@Override |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
9266
diff
changeset
|
415 |
void specificToStringHeader(StringBuilder sb) { |
16743
b0b34102bb4c
6298888: Add toGenericString to j.l.Class and getTypeName to j.l.reflect.Type
darcy
parents:
16729
diff
changeset
|
416 |
sb.append(getReturnType().getTypeName()).append(' '); |
b0b34102bb4c
6298888: Add toGenericString to j.l.Class and getTypeName to j.l.reflect.Type
darcy
parents:
16729
diff
changeset
|
417 |
sb.append(getDeclaringClass().getTypeName()).append('.'); |
10127
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
9266
diff
changeset
|
418 |
sb.append(getName()); |
2 | 419 |
} |
420 |
||
44359
c6761862ca0b
8174823: Module system implementation refresh (3/2017)
alanb
parents:
43712
diff
changeset
|
421 |
@Override |
c6761862ca0b
8174823: Module system implementation refresh (3/2017)
alanb
parents:
43712
diff
changeset
|
422 |
String toShortString() { |
57827
425412369353
8207814: (proxy) upgrade the proxy class generator
rriggs
parents:
57503
diff
changeset
|
423 |
return "method " + getDeclaringClass().getTypeName() + |
425412369353
8207814: (proxy) upgrade the proxy class generator
rriggs
parents:
57503
diff
changeset
|
424 |
'.' + toShortSignature(); |
425412369353
8207814: (proxy) upgrade the proxy class generator
rriggs
parents:
57503
diff
changeset
|
425 |
} |
425412369353
8207814: (proxy) upgrade the proxy class generator
rriggs
parents:
57503
diff
changeset
|
426 |
|
425412369353
8207814: (proxy) upgrade the proxy class generator
rriggs
parents:
57503
diff
changeset
|
427 |
String toShortSignature() { |
425412369353
8207814: (proxy) upgrade the proxy class generator
rriggs
parents:
57503
diff
changeset
|
428 |
StringJoiner sj = new StringJoiner(",", getName() + "(", ")"); |
44359
c6761862ca0b
8174823: Module system implementation refresh (3/2017)
alanb
parents:
43712
diff
changeset
|
429 |
for (Class<?> parameterType : getParameterTypes()) { |
c6761862ca0b
8174823: Module system implementation refresh (3/2017)
alanb
parents:
43712
diff
changeset
|
430 |
sj.add(parameterType.getTypeName()); |
c6761862ca0b
8174823: Module system implementation refresh (3/2017)
alanb
parents:
43712
diff
changeset
|
431 |
} |
57827
425412369353
8207814: (proxy) upgrade the proxy class generator
rriggs
parents:
57503
diff
changeset
|
432 |
return sj.toString(); |
44359
c6761862ca0b
8174823: Module system implementation refresh (3/2017)
alanb
parents:
43712
diff
changeset
|
433 |
} |
c6761862ca0b
8174823: Module system implementation refresh (3/2017)
alanb
parents:
43712
diff
changeset
|
434 |
|
2 | 435 |
/** |
52380
6b31efbf833e
6304578: (reflect) toGenericString fails to print bounds of type variables on generic methods
darcy
parents:
50735
diff
changeset
|
436 |
* Returns a string describing this {@code Method}, including type |
6b31efbf833e
6304578: (reflect) toGenericString fails to print bounds of type variables on generic methods
darcy
parents:
50735
diff
changeset
|
437 |
* parameters. The string is formatted as the method access |
2 | 438 |
* modifiers, if any, followed by an angle-bracketed |
439 |
* comma-separated list of the method's type parameters, if any, |
|
52380
6b31efbf833e
6304578: (reflect) toGenericString fails to print bounds of type variables on generic methods
darcy
parents:
50735
diff
changeset
|
440 |
* including informative bounds of the type parameters, if any, |
2 | 441 |
* followed by the method's generic return type, followed by a |
442 |
* space, followed by the class declaring the method, followed by |
|
443 |
* a period, followed by the method name, followed by a |
|
444 |
* parenthesized, comma-separated list of the method's generic |
|
445 |
* formal parameter types. |
|
446 |
* |
|
447 |
* If this method was declared to take a variable number of |
|
448 |
* arguments, instead of denoting the last parameter as |
|
32033
bf24e33c7919
8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents:
31671
diff
changeset
|
449 |
* "<code><i>Type</i>[]</code>", it is denoted as |
bf24e33c7919
8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents:
31671
diff
changeset
|
450 |
* "<code><i>Type</i>...</code>". |
2 | 451 |
* |
452 |
* A space is used to separate access modifiers from one another |
|
453 |
* and from the type parameters or return type. If there are no |
|
454 |
* type parameters, the type parameter list is elided; if the type |
|
455 |
* parameter list is present, a space separates the list from the |
|
456 |
* class name. If the method is declared to throw exceptions, the |
|
457 |
* parameter list is followed by a space, followed by the word |
|
42228
dd6cc832ffd4
8169479: java.lang.reflect.Constructor class has wrong api documentation
darcy
parents:
41560
diff
changeset
|
458 |
* "{@code throws}" followed by a comma-separated list of the generic |
dd6cc832ffd4
8169479: java.lang.reflect.Constructor class has wrong api documentation
darcy
parents:
41560
diff
changeset
|
459 |
* thrown exception types. |
2 | 460 |
* |
461 |
* <p>The access modifiers are placed in canonical order as |
|
462 |
* specified by "The Java Language Specification". This is |
|
463 |
* {@code public}, {@code protected} or {@code private} first, |
|
464 |
* and then other modifiers in the following order: |
|
16743
b0b34102bb4c
6298888: Add toGenericString to j.l.Class and getTypeName to j.l.reflect.Type
darcy
parents:
16729
diff
changeset
|
465 |
* {@code abstract}, {@code default}, {@code static}, {@code final}, |
b0b34102bb4c
6298888: Add toGenericString to j.l.Class and getTypeName to j.l.reflect.Type
darcy
parents:
16729
diff
changeset
|
466 |
* {@code synchronized}, {@code native}, {@code strictfp}. |
2 | 467 |
* |
468 |
* @return a string describing this {@code Method}, |
|
469 |
* include type parameters |
|
470 |
* |
|
471 |
* @since 1.5 |
|
16729
3b26e313ad81
8004979: java.lang.reflect.Modifier.toString should include "default"
darcy
parents:
16496
diff
changeset
|
472 |
* |
3b26e313ad81
8004979: java.lang.reflect.Modifier.toString should include "default"
darcy
parents:
16496
diff
changeset
|
473 |
* @jls 8.4.3 Method Modifiers |
54952
a978d86ac389
8224175: Fix inconsistencies in @jls and @jvms tags
darcy
parents:
52427
diff
changeset
|
474 |
* @jls 9.4 Method Declarations |
29125
83b9bf8a6c2a
8073952: Spec of j.l.r.Method.toString/toGenericString need to be clarified
darcy
parents:
26455
diff
changeset
|
475 |
* @jls 9.6.1 Annotation Type Elements |
2 | 476 |
*/ |
10127
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
9266
diff
changeset
|
477 |
@Override |
2 | 478 |
public String toGenericString() { |
16729
3b26e313ad81
8004979: java.lang.reflect.Modifier.toString should include "default"
darcy
parents:
16496
diff
changeset
|
479 |
return sharedToGenericString(Modifier.methodModifiers(), isDefault()); |
10127
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
9266
diff
changeset
|
480 |
} |
2 | 481 |
|
10127
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
9266
diff
changeset
|
482 |
@Override |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
9266
diff
changeset
|
483 |
void specificToGenericStringHeader(StringBuilder sb) { |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
9266
diff
changeset
|
484 |
Type genRetType = getGenericReturnType(); |
16743
b0b34102bb4c
6298888: Add toGenericString to j.l.Class and getTypeName to j.l.reflect.Type
darcy
parents:
16729
diff
changeset
|
485 |
sb.append(genRetType.getTypeName()).append(' '); |
b0b34102bb4c
6298888: Add toGenericString to j.l.Class and getTypeName to j.l.reflect.Type
darcy
parents:
16729
diff
changeset
|
486 |
sb.append(getDeclaringClass().getTypeName()).append('.'); |
10127
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
9266
diff
changeset
|
487 |
sb.append(getName()); |
2 | 488 |
} |
489 |
||
490 |
/** |
|
491 |
* Invokes the underlying method represented by this {@code Method} |
|
492 |
* object, on the specified object with the specified parameters. |
|
493 |
* Individual parameters are automatically unwrapped to match |
|
494 |
* primitive formal parameters, and both primitive and reference |
|
495 |
* parameters are subject to method invocation conversions as |
|
496 |
* necessary. |
|
497 |
* |
|
498 |
* <p>If the underlying method is static, then the specified {@code obj} |
|
499 |
* argument is ignored. It may be null. |
|
500 |
* |
|
501 |
* <p>If the number of formal parameters required by the underlying method is |
|
502 |
* 0, the supplied {@code args} array may be of length 0 or null. |
|
503 |
* |
|
504 |
* <p>If the underlying method is an instance method, it is invoked |
|
505 |
* using dynamic method lookup as documented in The Java Language |
|
50735
2f2af62dfac7
8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
50091
diff
changeset
|
506 |
* Specification, section 15.12.4.4; in particular, |
2f2af62dfac7
8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
50091
diff
changeset
|
507 |
* overriding based on the runtime type of the target object may occur. |
2 | 508 |
* |
509 |
* <p>If the underlying method is static, the class that declared |
|
510 |
* the method is initialized if it has not already been initialized. |
|
511 |
* |
|
512 |
* <p>If the method completes normally, the value it returns is |
|
513 |
* returned to the caller of invoke; if the value has a primitive |
|
514 |
* type, it is first appropriately wrapped in an object. However, |
|
515 |
* if the value has the type of an array of a primitive type, the |
|
516 |
* elements of the array are <i>not</i> wrapped in objects; in |
|
517 |
* other words, an array of primitive type is returned. If the |
|
518 |
* underlying method return type is void, the invocation returns |
|
519 |
* null. |
|
520 |
* |
|
521 |
* @param obj the object the underlying method is invoked from |
|
522 |
* @param args the arguments used for the method call |
|
523 |
* @return the result of dispatching the method represented by |
|
524 |
* this object on {@code obj} with parameters |
|
525 |
* {@code args} |
|
526 |
* |
|
58242
94bb65cb37d3
8230648: Replace @exception tag with @throws in java.base
jboes
parents:
57827
diff
changeset
|
527 |
* @throws IllegalAccessException if this {@code Method} object |
9022
b2e8758b10fd
6543593: (reflect) Clarify private final field mutability
darcy
parents:
5506
diff
changeset
|
528 |
* is enforcing Java language access control and the underlying |
2 | 529 |
* method is inaccessible. |
58242
94bb65cb37d3
8230648: Replace @exception tag with @throws in java.base
jboes
parents:
57827
diff
changeset
|
530 |
* @throws IllegalArgumentException if the method is an |
2 | 531 |
* instance method and the specified object argument |
532 |
* is not an instance of the class or interface |
|
533 |
* declaring the underlying method (or of a subclass |
|
534 |
* or implementor thereof); if the number of actual |
|
535 |
* and formal parameters differ; if an unwrapping |
|
536 |
* conversion for primitive arguments fails; or if, |
|
537 |
* after possible unwrapping, a parameter value |
|
538 |
* cannot be converted to the corresponding formal |
|
539 |
* parameter type by a method invocation conversion. |
|
58242
94bb65cb37d3
8230648: Replace @exception tag with @throws in java.base
jboes
parents:
57827
diff
changeset
|
540 |
* @throws InvocationTargetException if the underlying method |
2 | 541 |
* throws an exception. |
58242
94bb65cb37d3
8230648: Replace @exception tag with @throws in java.base
jboes
parents:
57827
diff
changeset
|
542 |
* @throws NullPointerException if the specified object is null |
2 | 543 |
* and the method is an instance method. |
58242
94bb65cb37d3
8230648: Replace @exception tag with @throws in java.base
jboes
parents:
57827
diff
changeset
|
544 |
* @throws ExceptionInInitializerError if the initialization |
2 | 545 |
* provoked by this method fails. |
546 |
*/ |
|
16906
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
16743
diff
changeset
|
547 |
@CallerSensitive |
40175
8df87018d96a
8161379: Force inline methods calling Reflection.getCallerClass
redestad
parents:
38882
diff
changeset
|
548 |
@ForceInline // to ensure Reflection.getCallerClass optimization |
31671
362e0c0acece
8076112: Add @HotSpotIntrinsicCandidate annotation to indicate methods for which Java Runtime has intrinsics
zmajo
parents:
29125
diff
changeset
|
549 |
@HotSpotIntrinsicCandidate |
2 | 550 |
public Object invoke(Object obj, Object... args) |
551 |
throws IllegalAccessException, IllegalArgumentException, |
|
552 |
InvocationTargetException |
|
553 |
{ |
|
554 |
if (!override) { |
|
36511 | 555 |
Class<?> caller = Reflection.getCallerClass(); |
41560
a66e7ee16cf9
6378384: (reflect) subclass can’t access superclass’s protected fields and methods by reflection
plevart
parents:
40175
diff
changeset
|
556 |
checkAccess(caller, clazz, |
a66e7ee16cf9
6378384: (reflect) subclass can’t access superclass’s protected fields and methods by reflection
plevart
parents:
40175
diff
changeset
|
557 |
Modifier.isStatic(modifiers) ? null : obj.getClass(), |
a66e7ee16cf9
6378384: (reflect) subclass can’t access superclass’s protected fields and methods by reflection
plevart
parents:
40175
diff
changeset
|
558 |
modifiers); |
2 | 559 |
} |
9029
e92fcf58f684
6565585: Remove critical section in Method.invoke, Constructor.newInstance, Field.getFieldAccessor improving performance
mduigou
parents:
9022
diff
changeset
|
560 |
MethodAccessor ma = methodAccessor; // read volatile |
e92fcf58f684
6565585: Remove critical section in Method.invoke, Constructor.newInstance, Field.getFieldAccessor improving performance
mduigou
parents:
9022
diff
changeset
|
561 |
if (ma == null) { |
e92fcf58f684
6565585: Remove critical section in Method.invoke, Constructor.newInstance, Field.getFieldAccessor improving performance
mduigou
parents:
9022
diff
changeset
|
562 |
ma = acquireMethodAccessor(); |
e92fcf58f684
6565585: Remove critical section in Method.invoke, Constructor.newInstance, Field.getFieldAccessor improving performance
mduigou
parents:
9022
diff
changeset
|
563 |
} |
e92fcf58f684
6565585: Remove critical section in Method.invoke, Constructor.newInstance, Field.getFieldAccessor improving performance
mduigou
parents:
9022
diff
changeset
|
564 |
return ma.invoke(obj, args); |
2 | 565 |
} |
566 |
||
567 |
/** |
|
568 |
* Returns {@code true} if this method is a bridge |
|
569 |
* method; returns {@code false} otherwise. |
|
570 |
* |
|
571 |
* @return true if and only if this method is a bridge |
|
572 |
* method as defined by the Java Language Specification. |
|
573 |
* @since 1.5 |
|
574 |
*/ |
|
575 |
public boolean isBridge() { |
|
576 |
return (getModifiers() & Modifier.BRIDGE) != 0; |
|
577 |
} |
|
578 |
||
579 |
/** |
|
10127
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
9266
diff
changeset
|
580 |
* {@inheritDoc} |
2 | 581 |
* @since 1.5 |
582 |
*/ |
|
10127
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
9266
diff
changeset
|
583 |
@Override |
2 | 584 |
public boolean isVarArgs() { |
10127
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
9266
diff
changeset
|
585 |
return super.isVarArgs(); |
2 | 586 |
} |
587 |
||
588 |
/** |
|
10127
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
9266
diff
changeset
|
589 |
* {@inheritDoc} |
14910 | 590 |
* @jls 13.1 The Form of a Binary |
2 | 591 |
* @since 1.5 |
592 |
*/ |
|
10127
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
9266
diff
changeset
|
593 |
@Override |
2 | 594 |
public boolean isSynthetic() { |
10127
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
9266
diff
changeset
|
595 |
return super.isSynthetic(); |
2 | 596 |
} |
597 |
||
14904 | 598 |
/** |
599 |
* Returns {@code true} if this method is a default |
|
600 |
* method; returns {@code false} otherwise. |
|
601 |
* |
|
16496 | 602 |
* A default method is a public non-abstract instance method, that |
603 |
* is, a non-static method with a body, declared in an interface |
|
604 |
* type. |
|
14904 | 605 |
* |
606 |
* @return true if and only if this method is a default |
|
607 |
* method as defined by the Java Language Specification. |
|
608 |
* @since 1.8 |
|
609 |
*/ |
|
610 |
public boolean isDefault() { |
|
16496 | 611 |
// Default methods are public non-abstract instance methods |
612 |
// declared in an interface. |
|
613 |
return ((getModifiers() & (Modifier.ABSTRACT | Modifier.PUBLIC | Modifier.STATIC)) == |
|
614 |
Modifier.PUBLIC) && getDeclaringClass().isInterface(); |
|
14904 | 615 |
} |
616 |
||
2 | 617 |
// NOTE that there is no synchronization used here. It is correct |
618 |
// (though not efficient) to generate more than one MethodAccessor |
|
619 |
// for a given Method. However, avoiding synchronization will |
|
620 |
// probably make the implementation more scalable. |
|
9029
e92fcf58f684
6565585: Remove critical section in Method.invoke, Constructor.newInstance, Field.getFieldAccessor improving performance
mduigou
parents:
9022
diff
changeset
|
621 |
private MethodAccessor acquireMethodAccessor() { |
2 | 622 |
// First check to see if one has been created yet, and take it |
623 |
// if so |
|
624 |
MethodAccessor tmp = null; |
|
625 |
if (root != null) tmp = root.getMethodAccessor(); |
|
626 |
if (tmp != null) { |
|
627 |
methodAccessor = tmp; |
|
9029
e92fcf58f684
6565585: Remove critical section in Method.invoke, Constructor.newInstance, Field.getFieldAccessor improving performance
mduigou
parents:
9022
diff
changeset
|
628 |
} else { |
e92fcf58f684
6565585: Remove critical section in Method.invoke, Constructor.newInstance, Field.getFieldAccessor improving performance
mduigou
parents:
9022
diff
changeset
|
629 |
// Otherwise fabricate one and propagate it up to the root |
e92fcf58f684
6565585: Remove critical section in Method.invoke, Constructor.newInstance, Field.getFieldAccessor improving performance
mduigou
parents:
9022
diff
changeset
|
630 |
tmp = reflectionFactory.newMethodAccessor(this); |
e92fcf58f684
6565585: Remove critical section in Method.invoke, Constructor.newInstance, Field.getFieldAccessor improving performance
mduigou
parents:
9022
diff
changeset
|
631 |
setMethodAccessor(tmp); |
2 | 632 |
} |
9029
e92fcf58f684
6565585: Remove critical section in Method.invoke, Constructor.newInstance, Field.getFieldAccessor improving performance
mduigou
parents:
9022
diff
changeset
|
633 |
|
e92fcf58f684
6565585: Remove critical section in Method.invoke, Constructor.newInstance, Field.getFieldAccessor improving performance
mduigou
parents:
9022
diff
changeset
|
634 |
return tmp; |
2 | 635 |
} |
636 |
||
637 |
// Returns MethodAccessor for this Method object, not looking up |
|
638 |
// the chain to the root |
|
639 |
MethodAccessor getMethodAccessor() { |
|
640 |
return methodAccessor; |
|
641 |
} |
|
642 |
||
643 |
// Sets the MethodAccessor for this Method object and |
|
644 |
// (recursively) its root |
|
645 |
void setMethodAccessor(MethodAccessor accessor) { |
|
646 |
methodAccessor = accessor; |
|
647 |
// Propagate up |
|
648 |
if (root != null) { |
|
649 |
root.setMethodAccessor(accessor); |
|
650 |
} |
|
651 |
} |
|
652 |
||
653 |
/** |
|
654 |
* Returns the default value for the annotation member represented by |
|
655 |
* this {@code Method} instance. If the member is of a primitive type, |
|
656 |
* an instance of the corresponding wrapper type is returned. Returns |
|
657 |
* null if no default is associated with the member, or if the method |
|
658 |
* instance does not represent a declared member of an annotation type. |
|
659 |
* |
|
660 |
* @return the default value for the annotation member represented |
|
661 |
* by this {@code Method} instance. |
|
662 |
* @throws TypeNotPresentException if the annotation is of type |
|
663 |
* {@link Class} and no definition can be found for the |
|
664 |
* default class value. |
|
665 |
* @since 1.5 |
|
666 |
*/ |
|
667 |
public Object getDefaultValue() { |
|
668 |
if (annotationDefault == null) |
|
669 |
return null; |
|
3959
05a07c0a273b
5062288: (reflect) Core reflection uses raw types when it could be using wildcards
darcy
parents:
3941
diff
changeset
|
670 |
Class<?> memberType = AnnotationType.invocationHandlerReturnType( |
2 | 671 |
getReturnType()); |
672 |
Object result = AnnotationParser.parseMemberValue( |
|
673 |
memberType, ByteBuffer.wrap(annotationDefault), |
|
32834
e1dca5fe4de3
8137056: Move SharedSecrets and interface friends out of sun.misc
chegar
parents:
32268
diff
changeset
|
674 |
SharedSecrets.getJavaLangAccess(). |
2 | 675 |
getConstantPool(getDeclaringClass()), |
676 |
getDeclaringClass()); |
|
38882
efb06b82374b
5041778: (ann) AnnotationFormatError if "default" Class type not found
darcy
parents:
37363
diff
changeset
|
677 |
if (result instanceof ExceptionProxy) { |
efb06b82374b
5041778: (ann) AnnotationFormatError if "default" Class type not found
darcy
parents:
37363
diff
changeset
|
678 |
if (result instanceof TypeNotPresentExceptionProxy) { |
efb06b82374b
5041778: (ann) AnnotationFormatError if "default" Class type not found
darcy
parents:
37363
diff
changeset
|
679 |
TypeNotPresentExceptionProxy proxy = (TypeNotPresentExceptionProxy)result; |
efb06b82374b
5041778: (ann) AnnotationFormatError if "default" Class type not found
darcy
parents:
37363
diff
changeset
|
680 |
throw new TypeNotPresentException(proxy.typeName(), proxy.getCause()); |
efb06b82374b
5041778: (ann) AnnotationFormatError if "default" Class type not found
darcy
parents:
37363
diff
changeset
|
681 |
} |
2 | 682 |
throw new AnnotationFormatError("Invalid default: " + this); |
38882
efb06b82374b
5041778: (ann) AnnotationFormatError if "default" Class type not found
darcy
parents:
37363
diff
changeset
|
683 |
} |
2 | 684 |
return result; |
685 |
} |
|
686 |
||
687 |
/** |
|
10127
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
9266
diff
changeset
|
688 |
* {@inheritDoc} |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
9266
diff
changeset
|
689 |
* @throws NullPointerException {@inheritDoc} |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
9266
diff
changeset
|
690 |
* @since 1.5 |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
9266
diff
changeset
|
691 |
*/ |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
9266
diff
changeset
|
692 |
public <T extends Annotation> T getAnnotation(Class<T> annotationClass) { |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
9266
diff
changeset
|
693 |
return super.getAnnotation(annotationClass); |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
9266
diff
changeset
|
694 |
} |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
9266
diff
changeset
|
695 |
|
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
9266
diff
changeset
|
696 |
/** |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
9266
diff
changeset
|
697 |
* {@inheritDoc} |
2 | 698 |
* @since 1.5 |
699 |
*/ |
|
10127
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
9266
diff
changeset
|
700 |
public Annotation[] getDeclaredAnnotations() { |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
9266
diff
changeset
|
701 |
return super.getDeclaredAnnotations(); |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
9266
diff
changeset
|
702 |
} |
2 | 703 |
|
10127
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
9266
diff
changeset
|
704 |
/** |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
9266
diff
changeset
|
705 |
* {@inheritDoc} |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
9266
diff
changeset
|
706 |
* @since 1.5 |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
9266
diff
changeset
|
707 |
*/ |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
9266
diff
changeset
|
708 |
@Override |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
9266
diff
changeset
|
709 |
public Annotation[][] getParameterAnnotations() { |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
9266
diff
changeset
|
710 |
return sharedGetParameterAnnotations(parameterTypes, parameterAnnotations); |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
9266
diff
changeset
|
711 |
} |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
9266
diff
changeset
|
712 |
|
15510
898d924a7efd
8004698: Implement Core Reflection for Type Annotations
jfranck
parents:
15294
diff
changeset
|
713 |
/** |
898d924a7efd
8004698: Implement Core Reflection for Type Annotations
jfranck
parents:
15294
diff
changeset
|
714 |
* {@inheritDoc} |
898d924a7efd
8004698: Implement Core Reflection for Type Annotations
jfranck
parents:
15294
diff
changeset
|
715 |
* @since 1.8 |
898d924a7efd
8004698: Implement Core Reflection for Type Annotations
jfranck
parents:
15294
diff
changeset
|
716 |
*/ |
16058
5b8d8cec6280
8007808: Missing method: Executable.getAnnotatedReturnType()
jfranck
parents:
15510
diff
changeset
|
717 |
@Override |
15510
898d924a7efd
8004698: Implement Core Reflection for Type Annotations
jfranck
parents:
15294
diff
changeset
|
718 |
public AnnotatedType getAnnotatedReturnType() { |
898d924a7efd
8004698: Implement Core Reflection for Type Annotations
jfranck
parents:
15294
diff
changeset
|
719 |
return getAnnotatedReturnType0(getGenericReturnType()); |
898d924a7efd
8004698: Implement Core Reflection for Type Annotations
jfranck
parents:
15294
diff
changeset
|
720 |
} |
898d924a7efd
8004698: Implement Core Reflection for Type Annotations
jfranck
parents:
15294
diff
changeset
|
721 |
|
10127
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
9266
diff
changeset
|
722 |
@Override |
45332
9c9e51c44638
8074977: Constructor.getAnnotatedParameterTypes returns wrong value
darcy
parents:
44359
diff
changeset
|
723 |
boolean handleParameterNumberMismatch(int resultLength, int numParameters) { |
10127
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
9266
diff
changeset
|
724 |
throw new AnnotationFormatError("Parameter annotations don't match number of parameters"); |
2 | 725 |
} |
726 |
} |