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 |
/* |
55337
ae3dbc712839
7086604: (reflect) Clarifications to javadoc for getGeneric*Type methods in j.l.r
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 |
||
52427
3c6aa484536c
8211122: Reduce the number of internal classes made accessible to jdk.unsupported
mchung
parents:
50091
diff
changeset
|
28 |
import jdk.internal.access.SharedSecrets; |
37363
329dba26ffd2
8137058: Clear out all non-Critical APIs from sun.reflect
chegar
parents:
36511
diff
changeset
|
29 |
import jdk.internal.reflect.CallerSensitive; |
329dba26ffd2
8137058: Clear out all non-Critical APIs from sun.reflect
chegar
parents:
36511
diff
changeset
|
30 |
import jdk.internal.reflect.FieldAccessor; |
329dba26ffd2
8137058: Clear out all non-Critical APIs from sun.reflect
chegar
parents:
36511
diff
changeset
|
31 |
import jdk.internal.reflect.Reflection; |
40175
8df87018d96a
8161379: Force inline methods calling Reflection.getCallerClass
redestad
parents:
37880
diff
changeset
|
32 |
import jdk.internal.vm.annotation.ForceInline; |
2 | 33 |
import sun.reflect.generics.repository.FieldRepository; |
34 |
import sun.reflect.generics.factory.CoreReflectionFactory; |
|
35 |
import sun.reflect.generics.factory.GenericsFactory; |
|
36 |
import sun.reflect.generics.scope.ClassScope; |
|
37 |
import java.lang.annotation.Annotation; |
|
38 |
import java.util.Map; |
|
14676
985410ec95e3
7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents:
14342
diff
changeset
|
39 |
import java.util.Objects; |
2 | 40 |
import sun.reflect.annotation.AnnotationParser; |
14676
985410ec95e3
7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents:
14342
diff
changeset
|
41 |
import sun.reflect.annotation.AnnotationSupport; |
15510
898d924a7efd
8004698: Implement Core Reflection for Type Annotations
jfranck
parents:
14905
diff
changeset
|
42 |
import sun.reflect.annotation.TypeAnnotation; |
898d924a7efd
8004698: Implement Core Reflection for Type Annotations
jfranck
parents:
14905
diff
changeset
|
43 |
import sun.reflect.annotation.TypeAnnotationParser; |
2 | 44 |
|
45 |
/** |
|
46 |
* A {@code Field} provides information about, and dynamic access to, a |
|
47 |
* single field of a class or an interface. The reflected field may |
|
48 |
* be a class (static) field or an instance field. |
|
49 |
* |
|
50 |
* <p>A {@code Field} permits widening conversions to occur during a get or |
|
51 |
* set access operation, but throws an {@code IllegalArgumentException} if a |
|
52 |
* narrowing conversion would occur. |
|
53 |
* |
|
54 |
* @see Member |
|
55 |
* @see java.lang.Class |
|
56 |
* @see java.lang.Class#getFields() |
|
57 |
* @see java.lang.Class#getField(String) |
|
58 |
* @see java.lang.Class#getDeclaredFields() |
|
59 |
* @see java.lang.Class#getDeclaredField(String) |
|
60 |
* |
|
61 |
* @author Kenneth Russell |
|
62 |
* @author Nakul Saraiya |
|
45434
4582657c7260
8181082: class-level since tag issues in java.base & java.datatransfer module
mli
parents:
44359
diff
changeset
|
63 |
* @since 1.1 |
2 | 64 |
*/ |
65 |
public final |
|
66 |
class Field extends AccessibleObject implements Member { |
|
67 |
||
3959
05a07c0a273b
5062288: (reflect) Core reflection uses raw types when it could be using wildcards
darcy
parents:
2174
diff
changeset
|
68 |
private Class<?> clazz; |
2 | 69 |
private int slot; |
70 |
// This is guaranteed to be interned by the VM in the 1.4 |
|
71 |
// reflection implementation |
|
72 |
private String name; |
|
3959
05a07c0a273b
5062288: (reflect) Core reflection uses raw types when it could be using wildcards
darcy
parents:
2174
diff
changeset
|
73 |
private Class<?> type; |
2 | 74 |
private int modifiers; |
75 |
// Generics and annotations support |
|
76 |
private transient String signature; |
|
77 |
// generic info repository; lazily initialized |
|
78 |
private transient FieldRepository genericInfo; |
|
79 |
private byte[] annotations; |
|
80 |
// Cached field accessor created without override |
|
81 |
private FieldAccessor fieldAccessor; |
|
82 |
// Cached field accessor created with override |
|
83 |
private FieldAccessor overrideFieldAccessor; |
|
84 |
// For sharing of FieldAccessors. This branching structure is |
|
85 |
// currently only two levels deep (i.e., one root Field and |
|
86 |
// potentially many Field objects pointing to it.) |
|
26455
195a6f3e0cd0
8054987: (reflect) Add sharing of annotations between instances of Executable
jfranck
parents:
25859
diff
changeset
|
87 |
// |
195a6f3e0cd0
8054987: (reflect) Add sharing of annotations between instances of Executable
jfranck
parents:
25859
diff
changeset
|
88 |
// 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
|
89 |
// occur in annotation code. |
2 | 90 |
private Field root; |
91 |
||
92 |
// Generics infrastructure |
|
93 |
||
94 |
private String getGenericSignature() {return signature;} |
|
95 |
||
96 |
// Accessor for factory |
|
97 |
private GenericsFactory getFactory() { |
|
98 |
Class<?> c = getDeclaringClass(); |
|
99 |
// create scope and factory |
|
100 |
return CoreReflectionFactory.make(c, ClassScope.make(c)); |
|
101 |
} |
|
102 |
||
103 |
// Accessor for generic info repository |
|
104 |
private FieldRepository getGenericInfo() { |
|
105 |
// lazily initialize repository if necessary |
|
106 |
if (genericInfo == null) { |
|
107 |
// create and cache generic info repository |
|
108 |
genericInfo = FieldRepository.make(getGenericSignature(), |
|
109 |
getFactory()); |
|
110 |
} |
|
111 |
return genericInfo; //return cached repository |
|
112 |
} |
|
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:
2174
diff
changeset
|
118 |
Field(Class<?> declaringClass, |
2 | 119 |
String name, |
3959
05a07c0a273b
5062288: (reflect) Core reflection uses raw types when it could be using wildcards
darcy
parents:
2174
diff
changeset
|
120 |
Class<?> type, |
2 | 121 |
int modifiers, |
122 |
int slot, |
|
123 |
String signature, |
|
124 |
byte[] annotations) |
|
125 |
{ |
|
126 |
this.clazz = declaringClass; |
|
127 |
this.name = name; |
|
128 |
this.type = type; |
|
129 |
this.modifiers = modifiers; |
|
130 |
this.slot = slot; |
|
131 |
this.signature = signature; |
|
132 |
this.annotations = annotations; |
|
133 |
} |
|
134 |
||
135 |
/** |
|
136 |
* Package-private routine (exposed to java.lang.Class via |
|
137 |
* ReflectAccess) which returns a copy of this Field. The copy's |
|
138 |
* "root" field points to this Field. |
|
139 |
*/ |
|
140 |
Field copy() { |
|
141 |
// This routine enables sharing of FieldAccessor objects |
|
142 |
// among Field objects which refer to the same underlying |
|
143 |
// method in the VM. (All of this contortion is only necessary |
|
144 |
// because of the "accessibility" bit in AccessibleObject, |
|
145 |
// which implicitly requires that new java.lang.reflect |
|
146 |
// objects be fabricated for each reflective call on Class |
|
147 |
// objects.) |
|
26455
195a6f3e0cd0
8054987: (reflect) Add sharing of annotations between instances of Executable
jfranck
parents:
25859
diff
changeset
|
148 |
if (this.root != null) |
195a6f3e0cd0
8054987: (reflect) Add sharing of annotations between instances of Executable
jfranck
parents:
25859
diff
changeset
|
149 |
throw new IllegalArgumentException("Can not copy a non-root Field"); |
195a6f3e0cd0
8054987: (reflect) Add sharing of annotations between instances of Executable
jfranck
parents:
25859
diff
changeset
|
150 |
|
2 | 151 |
Field res = new Field(clazz, name, type, modifiers, slot, signature, annotations); |
152 |
res.root = this; |
|
153 |
// Might as well eagerly propagate this if already present |
|
154 |
res.fieldAccessor = fieldAccessor; |
|
155 |
res.overrideFieldAccessor = overrideFieldAccessor; |
|
14905
ca1bf7f03ffb
8004699: Add type annotation storage to Constructor, Field and Method
darcy
parents:
14676
diff
changeset
|
156 |
|
2 | 157 |
return res; |
158 |
} |
|
159 |
||
43712
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
41560
diff
changeset
|
160 |
/** |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
41560
diff
changeset
|
161 |
* @throws InaccessibleObjectException {@inheritDoc} |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
41560
diff
changeset
|
162 |
* @throws SecurityException {@inheritDoc} |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
41560
diff
changeset
|
163 |
*/ |
36511 | 164 |
@Override |
165 |
@CallerSensitive |
|
166 |
public void setAccessible(boolean flag) { |
|
167 |
AccessibleObject.checkPermission(); |
|
168 |
if (flag) checkCanSetAccessible(Reflection.getCallerClass()); |
|
169 |
setAccessible0(flag); |
|
170 |
} |
|
171 |
||
172 |
@Override |
|
173 |
void checkCanSetAccessible(Class<?> caller) { |
|
174 |
checkCanSetAccessible(caller, clazz); |
|
175 |
} |
|
176 |
||
2 | 177 |
/** |
178 |
* Returns the {@code Class} object representing the class or interface |
|
179 |
* that declares the field represented by this {@code Field} object. |
|
180 |
*/ |
|
36511 | 181 |
@Override |
2 | 182 |
public Class<?> getDeclaringClass() { |
183 |
return clazz; |
|
184 |
} |
|
185 |
||
186 |
/** |
|
187 |
* Returns the name of the field represented by this {@code Field} object. |
|
188 |
*/ |
|
189 |
public String getName() { |
|
190 |
return name; |
|
191 |
} |
|
192 |
||
193 |
/** |
|
194 |
* Returns the Java language modifiers for the field represented |
|
195 |
* by this {@code Field} object, as an integer. The {@code Modifier} class should |
|
196 |
* be used to decode the modifiers. |
|
197 |
* |
|
198 |
* @see Modifier |
|
199 |
*/ |
|
200 |
public int getModifiers() { |
|
201 |
return modifiers; |
|
202 |
} |
|
203 |
||
204 |
/** |
|
205 |
* Returns {@code true} if this field represents an element of |
|
206 |
* an enumerated type; returns {@code false} otherwise. |
|
207 |
* |
|
208 |
* @return {@code true} if and only if this field represents an element of |
|
209 |
* an enumerated type. |
|
210 |
* @since 1.5 |
|
211 |
*/ |
|
212 |
public boolean isEnumConstant() { |
|
213 |
return (getModifiers() & Modifier.ENUM) != 0; |
|
214 |
} |
|
215 |
||
216 |
/** |
|
217 |
* Returns {@code true} if this field is a synthetic |
|
218 |
* field; returns {@code false} otherwise. |
|
219 |
* |
|
220 |
* @return true if and only if this field is a synthetic |
|
221 |
* field as defined by the Java Language Specification. |
|
222 |
* @since 1.5 |
|
223 |
*/ |
|
224 |
public boolean isSynthetic() { |
|
225 |
return Modifier.isSynthetic(getModifiers()); |
|
226 |
} |
|
227 |
||
228 |
/** |
|
229 |
* Returns a {@code Class} object that identifies the |
|
230 |
* declared type for the field represented by this |
|
231 |
* {@code Field} object. |
|
232 |
* |
|
233 |
* @return a {@code Class} object identifying the declared |
|
234 |
* type of the field represented by this object |
|
235 |
*/ |
|
236 |
public Class<?> getType() { |
|
237 |
return type; |
|
238 |
} |
|
239 |
||
240 |
/** |
|
241 |
* Returns a {@code Type} object that represents the declared type for |
|
242 |
* the field represented by this {@code Field} object. |
|
243 |
* |
|
55337
ae3dbc712839
7086604: (reflect) Clarifications to javadoc for getGeneric*Type methods in j.l.r
darcy
parents:
52427
diff
changeset
|
244 |
* <p>If the declared type of the field is a parameterized type, |
ae3dbc712839
7086604: (reflect) Clarifications to javadoc for getGeneric*Type methods in j.l.r
darcy
parents:
52427
diff
changeset
|
245 |
* the {@code Type} object returned must accurately reflect the |
ae3dbc712839
7086604: (reflect) Clarifications to javadoc for getGeneric*Type methods in j.l.r
darcy
parents:
52427
diff
changeset
|
246 |
* actual type arguments used in the source code. |
2 | 247 |
* |
248 |
* <p>If the type of the underlying field is a type variable or a |
|
249 |
* parameterized type, it is created. Otherwise, it is resolved. |
|
250 |
* |
|
251 |
* @return a {@code Type} object that represents the declared type for |
|
252 |
* the field represented by this {@code Field} object |
|
253 |
* @throws GenericSignatureFormatError if the generic field |
|
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
|
254 |
* signature does not conform to the format 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
|
255 |
* <cite>The Java™ Virtual Machine Specification</cite> |
2 | 256 |
* @throws TypeNotPresentException if the generic type |
257 |
* signature of the underlying field refers to a non-existent |
|
258 |
* type declaration |
|
259 |
* @throws MalformedParameterizedTypeException if the generic |
|
260 |
* signature of the underlying field refers to a parameterized type |
|
261 |
* that cannot be instantiated for any reason |
|
262 |
* @since 1.5 |
|
263 |
*/ |
|
264 |
public Type getGenericType() { |
|
265 |
if (getGenericSignature() != null) |
|
266 |
return getGenericInfo().getGenericType(); |
|
267 |
else |
|
268 |
return getType(); |
|
269 |
} |
|
270 |
||
271 |
||
272 |
/** |
|
273 |
* Compares this {@code Field} against the specified object. Returns |
|
274 |
* true if the objects are the same. Two {@code Field} objects are the same if |
|
275 |
* they were declared by the same class and have the same name |
|
276 |
* and type. |
|
277 |
*/ |
|
278 |
public boolean equals(Object obj) { |
|
279 |
if (obj != null && obj instanceof Field) { |
|
280 |
Field other = (Field)obj; |
|
281 |
return (getDeclaringClass() == other.getDeclaringClass()) |
|
282 |
&& (getName() == other.getName()) |
|
283 |
&& (getType() == other.getType()); |
|
284 |
} |
|
285 |
return false; |
|
286 |
} |
|
287 |
||
288 |
/** |
|
289 |
* Returns a hashcode for this {@code Field}. This is computed as the |
|
290 |
* exclusive-or of the hashcodes for the underlying field's |
|
291 |
* declaring class name and its name. |
|
292 |
*/ |
|
293 |
public int hashCode() { |
|
294 |
return getDeclaringClass().getName().hashCode() ^ getName().hashCode(); |
|
295 |
} |
|
296 |
||
297 |
/** |
|
298 |
* Returns a string describing this {@code Field}. The format is |
|
299 |
* the access modifiers for the field, if any, followed |
|
300 |
* by the field type, followed by a space, followed by |
|
301 |
* the fully-qualified name of the class declaring the field, |
|
302 |
* followed by a period, followed by the name of the field. |
|
303 |
* For example: |
|
304 |
* <pre> |
|
305 |
* public static final int java.lang.Thread.MIN_PRIORITY |
|
306 |
* private int java.io.FileDescriptor.fd |
|
307 |
* </pre> |
|
308 |
* |
|
309 |
* <p>The modifiers are placed in canonical order as specified by |
|
310 |
* "The Java Language Specification". This is {@code public}, |
|
311 |
* {@code protected} or {@code private} first, and then other |
|
312 |
* modifiers in the following order: {@code static}, {@code final}, |
|
313 |
* {@code transient}, {@code volatile}. |
|
16729
3b26e313ad81
8004979: java.lang.reflect.Modifier.toString should include "default"
darcy
parents:
15659
diff
changeset
|
314 |
* |
3b26e313ad81
8004979: java.lang.reflect.Modifier.toString should include "default"
darcy
parents:
15659
diff
changeset
|
315 |
* @return a string describing this {@code Field} |
3b26e313ad81
8004979: java.lang.reflect.Modifier.toString should include "default"
darcy
parents:
15659
diff
changeset
|
316 |
* @jls 8.3.1 Field Modifiers |
2 | 317 |
*/ |
318 |
public String toString() { |
|
319 |
int mod = getModifiers(); |
|
320 |
return (((mod == 0) ? "" : (Modifier.toString(mod) + " ")) |
|
16743
b0b34102bb4c
6298888: Add toGenericString to j.l.Class and getTypeName to j.l.reflect.Type
darcy
parents:
16729
diff
changeset
|
321 |
+ getType().getTypeName() + " " |
b0b34102bb4c
6298888: Add toGenericString to j.l.Class and getTypeName to j.l.reflect.Type
darcy
parents:
16729
diff
changeset
|
322 |
+ getDeclaringClass().getTypeName() + "." |
2 | 323 |
+ getName()); |
324 |
} |
|
325 |
||
44359
c6761862ca0b
8174823: Module system implementation refresh (3/2017)
alanb
parents:
43712
diff
changeset
|
326 |
@Override |
c6761862ca0b
8174823: Module system implementation refresh (3/2017)
alanb
parents:
43712
diff
changeset
|
327 |
String toShortString() { |
c6761862ca0b
8174823: Module system implementation refresh (3/2017)
alanb
parents:
43712
diff
changeset
|
328 |
return "field " + getDeclaringClass().getTypeName() + "." + getName(); |
c6761862ca0b
8174823: Module system implementation refresh (3/2017)
alanb
parents:
43712
diff
changeset
|
329 |
} |
c6761862ca0b
8174823: Module system implementation refresh (3/2017)
alanb
parents:
43712
diff
changeset
|
330 |
|
2 | 331 |
/** |
332 |
* Returns a string describing this {@code Field}, including |
|
333 |
* its generic type. The format is the access modifiers for the |
|
334 |
* field, if any, followed by the generic field type, followed by |
|
335 |
* a space, followed by the fully-qualified name of the class |
|
336 |
* declaring the field, followed by a period, followed by the name |
|
337 |
* of the field. |
|
338 |
* |
|
339 |
* <p>The modifiers are placed in canonical order as specified by |
|
340 |
* "The Java Language Specification". This is {@code public}, |
|
341 |
* {@code protected} or {@code private} first, and then other |
|
342 |
* modifiers in the following order: {@code static}, {@code final}, |
|
343 |
* {@code transient}, {@code volatile}. |
|
344 |
* |
|
345 |
* @return a string describing this {@code Field}, including |
|
346 |
* its generic type |
|
347 |
* |
|
348 |
* @since 1.5 |
|
16729
3b26e313ad81
8004979: java.lang.reflect.Modifier.toString should include "default"
darcy
parents:
15659
diff
changeset
|
349 |
* @jls 8.3.1 Field Modifiers |
2 | 350 |
*/ |
351 |
public String toGenericString() { |
|
352 |
int mod = getModifiers(); |
|
353 |
Type fieldType = getGenericType(); |
|
354 |
return (((mod == 0) ? "" : (Modifier.toString(mod) + " ")) |
|
16743
b0b34102bb4c
6298888: Add toGenericString to j.l.Class and getTypeName to j.l.reflect.Type
darcy
parents:
16729
diff
changeset
|
355 |
+ fieldType.getTypeName() + " " |
b0b34102bb4c
6298888: Add toGenericString to j.l.Class and getTypeName to j.l.reflect.Type
darcy
parents:
16729
diff
changeset
|
356 |
+ getDeclaringClass().getTypeName() + "." |
2 | 357 |
+ getName()); |
358 |
} |
|
359 |
||
360 |
/** |
|
361 |
* Returns the value of the field represented by this {@code Field}, on |
|
362 |
* the specified object. The value is automatically wrapped in an |
|
363 |
* object if it has a primitive type. |
|
364 |
* |
|
365 |
* <p>The underlying field's value is obtained as follows: |
|
366 |
* |
|
367 |
* <p>If the underlying field is a static field, the {@code obj} argument |
|
368 |
* is ignored; it may be null. |
|
369 |
* |
|
370 |
* <p>Otherwise, the underlying field is an instance field. If the |
|
371 |
* specified {@code obj} argument is null, the method throws a |
|
372 |
* {@code NullPointerException}. If the specified object is not an |
|
373 |
* instance of the class or interface declaring the underlying |
|
374 |
* field, the method throws an {@code IllegalArgumentException}. |
|
375 |
* |
|
9022
b2e8758b10fd
6543593: (reflect) Clarify private final field mutability
darcy
parents:
5506
diff
changeset
|
376 |
* <p>If this {@code Field} object is enforcing Java language access control, and |
2 | 377 |
* the underlying field is inaccessible, the method throws an |
378 |
* {@code IllegalAccessException}. |
|
379 |
* If the underlying field is static, the class that declared the |
|
380 |
* field is initialized if it has not already been initialized. |
|
381 |
* |
|
382 |
* <p>Otherwise, the value is retrieved from the underlying instance |
|
383 |
* or static field. If the field has a primitive type, the value |
|
384 |
* is wrapped in an object before being returned, otherwise it is |
|
385 |
* returned as is. |
|
386 |
* |
|
387 |
* <p>If the field is hidden in the type of {@code obj}, |
|
388 |
* the field's value is obtained according to the preceding rules. |
|
389 |
* |
|
390 |
* @param obj object from which the represented field's value is |
|
391 |
* to be extracted |
|
392 |
* @return the value of the represented field in object |
|
393 |
* {@code obj}; primitive values are wrapped in an appropriate |
|
394 |
* object before being returned |
|
395 |
* |
|
58242
94bb65cb37d3
8230648: Replace @exception tag with @throws in java.base
jboes
parents:
57503
diff
changeset
|
396 |
* @throws IllegalAccessException if this {@code Field} object |
9022
b2e8758b10fd
6543593: (reflect) Clarify private final field mutability
darcy
parents:
5506
diff
changeset
|
397 |
* is enforcing Java language access control and the underlying |
b2e8758b10fd
6543593: (reflect) Clarify private final field mutability
darcy
parents:
5506
diff
changeset
|
398 |
* field is inaccessible. |
58242
94bb65cb37d3
8230648: Replace @exception tag with @throws in java.base
jboes
parents:
57503
diff
changeset
|
399 |
* @throws IllegalArgumentException if the specified object is not an |
2 | 400 |
* instance of the class or interface declaring the underlying |
401 |
* field (or a subclass or implementor thereof). |
|
58242
94bb65cb37d3
8230648: Replace @exception tag with @throws in java.base
jboes
parents:
57503
diff
changeset
|
402 |
* @throws NullPointerException if the specified object is null |
2 | 403 |
* and the field is an instance field. |
58242
94bb65cb37d3
8230648: Replace @exception tag with @throws in java.base
jboes
parents:
57503
diff
changeset
|
404 |
* @throws ExceptionInInitializerError if the initialization provoked |
2 | 405 |
* by this method fails. |
406 |
*/ |
|
16906
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
16743
diff
changeset
|
407 |
@CallerSensitive |
40175
8df87018d96a
8161379: Force inline methods calling Reflection.getCallerClass
redestad
parents:
37880
diff
changeset
|
408 |
@ForceInline // to ensure Reflection.getCallerClass optimization |
2 | 409 |
public Object get(Object obj) |
410 |
throws IllegalArgumentException, IllegalAccessException |
|
411 |
{ |
|
16906
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
16743
diff
changeset
|
412 |
if (!override) { |
36511 | 413 |
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
|
414 |
checkAccess(caller, obj); |
16906
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
16743
diff
changeset
|
415 |
} |
2 | 416 |
return getFieldAccessor(obj).get(obj); |
417 |
} |
|
418 |
||
419 |
/** |
|
420 |
* Gets the value of a static or instance {@code boolean} field. |
|
421 |
* |
|
422 |
* @param obj the object to extract the {@code boolean} value |
|
423 |
* from |
|
424 |
* @return the value of the {@code boolean} field |
|
425 |
* |
|
58242
94bb65cb37d3
8230648: Replace @exception tag with @throws in java.base
jboes
parents:
57503
diff
changeset
|
426 |
* @throws IllegalAccessException if this {@code Field} object |
9022
b2e8758b10fd
6543593: (reflect) Clarify private final field mutability
darcy
parents:
5506
diff
changeset
|
427 |
* is enforcing Java language access control and the underlying |
b2e8758b10fd
6543593: (reflect) Clarify private final field mutability
darcy
parents:
5506
diff
changeset
|
428 |
* field is inaccessible. |
58242
94bb65cb37d3
8230648: Replace @exception tag with @throws in java.base
jboes
parents:
57503
diff
changeset
|
429 |
* @throws IllegalArgumentException if the specified object is not |
2 | 430 |
* an instance of the class or interface declaring the |
431 |
* underlying field (or a subclass or implementor |
|
432 |
* thereof), or if the field value cannot be |
|
433 |
* converted to the type {@code boolean} by a |
|
434 |
* widening conversion. |
|
58242
94bb65cb37d3
8230648: Replace @exception tag with @throws in java.base
jboes
parents:
57503
diff
changeset
|
435 |
* @throws NullPointerException if the specified object is null |
2 | 436 |
* and the field is an instance field. |
58242
94bb65cb37d3
8230648: Replace @exception tag with @throws in java.base
jboes
parents:
57503
diff
changeset
|
437 |
* @throws ExceptionInInitializerError if the initialization provoked |
2 | 438 |
* by this method fails. |
439 |
* @see Field#get |
|
440 |
*/ |
|
16906
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
16743
diff
changeset
|
441 |
@CallerSensitive |
40175
8df87018d96a
8161379: Force inline methods calling Reflection.getCallerClass
redestad
parents:
37880
diff
changeset
|
442 |
@ForceInline // to ensure Reflection.getCallerClass optimization |
2 | 443 |
public boolean getBoolean(Object obj) |
444 |
throws IllegalArgumentException, IllegalAccessException |
|
445 |
{ |
|
16906
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
16743
diff
changeset
|
446 |
if (!override) { |
36511 | 447 |
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
|
448 |
checkAccess(caller, obj); |
16906
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
16743
diff
changeset
|
449 |
} |
2 | 450 |
return getFieldAccessor(obj).getBoolean(obj); |
451 |
} |
|
452 |
||
453 |
/** |
|
454 |
* Gets the value of a static or instance {@code byte} field. |
|
455 |
* |
|
456 |
* @param obj the object to extract the {@code byte} value |
|
457 |
* from |
|
458 |
* @return the value of the {@code byte} field |
|
459 |
* |
|
58242
94bb65cb37d3
8230648: Replace @exception tag with @throws in java.base
jboes
parents:
57503
diff
changeset
|
460 |
* @throws IllegalAccessException if this {@code Field} object |
9022
b2e8758b10fd
6543593: (reflect) Clarify private final field mutability
darcy
parents:
5506
diff
changeset
|
461 |
* is enforcing Java language access control and the underlying |
b2e8758b10fd
6543593: (reflect) Clarify private final field mutability
darcy
parents:
5506
diff
changeset
|
462 |
* field is inaccessible. |
58242
94bb65cb37d3
8230648: Replace @exception tag with @throws in java.base
jboes
parents:
57503
diff
changeset
|
463 |
* @throws IllegalArgumentException if the specified object is not |
2 | 464 |
* an instance of the class or interface declaring the |
465 |
* underlying field (or a subclass or implementor |
|
466 |
* thereof), or if the field value cannot be |
|
467 |
* converted to the type {@code byte} by a |
|
468 |
* widening conversion. |
|
58242
94bb65cb37d3
8230648: Replace @exception tag with @throws in java.base
jboes
parents:
57503
diff
changeset
|
469 |
* @throws NullPointerException if the specified object is null |
2 | 470 |
* and the field is an instance field. |
58242
94bb65cb37d3
8230648: Replace @exception tag with @throws in java.base
jboes
parents:
57503
diff
changeset
|
471 |
* @throws ExceptionInInitializerError if the initialization provoked |
2 | 472 |
* by this method fails. |
473 |
* @see Field#get |
|
474 |
*/ |
|
16906
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
16743
diff
changeset
|
475 |
@CallerSensitive |
40175
8df87018d96a
8161379: Force inline methods calling Reflection.getCallerClass
redestad
parents:
37880
diff
changeset
|
476 |
@ForceInline // to ensure Reflection.getCallerClass optimization |
2 | 477 |
public byte getByte(Object obj) |
478 |
throws IllegalArgumentException, IllegalAccessException |
|
479 |
{ |
|
16906
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
16743
diff
changeset
|
480 |
if (!override) { |
36511 | 481 |
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
|
482 |
checkAccess(caller, obj); |
16906
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
16743
diff
changeset
|
483 |
} |
2 | 484 |
return getFieldAccessor(obj).getByte(obj); |
485 |
} |
|
486 |
||
487 |
/** |
|
488 |
* Gets the value of a static or instance field of type |
|
489 |
* {@code char} or of another primitive type convertible to |
|
490 |
* type {@code char} via a widening conversion. |
|
491 |
* |
|
492 |
* @param obj the object to extract the {@code char} value |
|
493 |
* from |
|
494 |
* @return the value of the field converted to type {@code char} |
|
495 |
* |
|
58242
94bb65cb37d3
8230648: Replace @exception tag with @throws in java.base
jboes
parents:
57503
diff
changeset
|
496 |
* @throws IllegalAccessException if this {@code Field} object |
9022
b2e8758b10fd
6543593: (reflect) Clarify private final field mutability
darcy
parents:
5506
diff
changeset
|
497 |
* is enforcing Java language access control and the underlying |
b2e8758b10fd
6543593: (reflect) Clarify private final field mutability
darcy
parents:
5506
diff
changeset
|
498 |
* field is inaccessible. |
58242
94bb65cb37d3
8230648: Replace @exception tag with @throws in java.base
jboes
parents:
57503
diff
changeset
|
499 |
* @throws IllegalArgumentException if the specified object is not |
2 | 500 |
* an instance of the class or interface declaring the |
501 |
* underlying field (or a subclass or implementor |
|
502 |
* thereof), or if the field value cannot be |
|
503 |
* converted to the type {@code char} by a |
|
504 |
* widening conversion. |
|
58242
94bb65cb37d3
8230648: Replace @exception tag with @throws in java.base
jboes
parents:
57503
diff
changeset
|
505 |
* @throws NullPointerException if the specified object is null |
2 | 506 |
* and the field is an instance field. |
58242
94bb65cb37d3
8230648: Replace @exception tag with @throws in java.base
jboes
parents:
57503
diff
changeset
|
507 |
* @throws ExceptionInInitializerError if the initialization provoked |
2 | 508 |
* by this method fails. |
509 |
* @see Field#get |
|
510 |
*/ |
|
16906
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
16743
diff
changeset
|
511 |
@CallerSensitive |
40175
8df87018d96a
8161379: Force inline methods calling Reflection.getCallerClass
redestad
parents:
37880
diff
changeset
|
512 |
@ForceInline // to ensure Reflection.getCallerClass optimization |
2 | 513 |
public char getChar(Object obj) |
514 |
throws IllegalArgumentException, IllegalAccessException |
|
515 |
{ |
|
16906
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
16743
diff
changeset
|
516 |
if (!override) { |
36511 | 517 |
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
|
518 |
checkAccess(caller, obj); |
16906
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
16743
diff
changeset
|
519 |
} |
2 | 520 |
return getFieldAccessor(obj).getChar(obj); |
521 |
} |
|
522 |
||
523 |
/** |
|
524 |
* Gets the value of a static or instance field of type |
|
525 |
* {@code short} or of another primitive type convertible to |
|
526 |
* type {@code short} via a widening conversion. |
|
527 |
* |
|
528 |
* @param obj the object to extract the {@code short} value |
|
529 |
* from |
|
530 |
* @return the value of the field converted to type {@code short} |
|
531 |
* |
|
58242
94bb65cb37d3
8230648: Replace @exception tag with @throws in java.base
jboes
parents:
57503
diff
changeset
|
532 |
* @throws IllegalAccessException if this {@code Field} object |
9022
b2e8758b10fd
6543593: (reflect) Clarify private final field mutability
darcy
parents:
5506
diff
changeset
|
533 |
* is enforcing Java language access control and the underlying |
b2e8758b10fd
6543593: (reflect) Clarify private final field mutability
darcy
parents:
5506
diff
changeset
|
534 |
* field is inaccessible. |
58242
94bb65cb37d3
8230648: Replace @exception tag with @throws in java.base
jboes
parents:
57503
diff
changeset
|
535 |
* @throws IllegalArgumentException if the specified object is not |
2 | 536 |
* an instance of the class or interface declaring the |
537 |
* underlying field (or a subclass or implementor |
|
538 |
* thereof), or if the field value cannot be |
|
539 |
* converted to the type {@code short} by a |
|
540 |
* widening conversion. |
|
58242
94bb65cb37d3
8230648: Replace @exception tag with @throws in java.base
jboes
parents:
57503
diff
changeset
|
541 |
* @throws NullPointerException if the specified object is null |
2 | 542 |
* and the field is an instance field. |
58242
94bb65cb37d3
8230648: Replace @exception tag with @throws in java.base
jboes
parents:
57503
diff
changeset
|
543 |
* @throws ExceptionInInitializerError if the initialization provoked |
2 | 544 |
* by this method fails. |
545 |
* @see Field#get |
|
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:
37880
diff
changeset
|
548 |
@ForceInline // to ensure Reflection.getCallerClass optimization |
2 | 549 |
public short getShort(Object obj) |
550 |
throws IllegalArgumentException, IllegalAccessException |
|
551 |
{ |
|
16906
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
16743
diff
changeset
|
552 |
if (!override) { |
36511 | 553 |
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
|
554 |
checkAccess(caller, obj); |
16906
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
16743
diff
changeset
|
555 |
} |
2 | 556 |
return getFieldAccessor(obj).getShort(obj); |
557 |
} |
|
558 |
||
559 |
/** |
|
560 |
* Gets the value of a static or instance field of type |
|
561 |
* {@code int} or of another primitive type convertible to |
|
562 |
* type {@code int} via a widening conversion. |
|
563 |
* |
|
564 |
* @param obj the object to extract the {@code int} value |
|
565 |
* from |
|
566 |
* @return the value of the field converted to type {@code int} |
|
567 |
* |
|
58242
94bb65cb37d3
8230648: Replace @exception tag with @throws in java.base
jboes
parents:
57503
diff
changeset
|
568 |
* @throws IllegalAccessException if this {@code Field} object |
9022
b2e8758b10fd
6543593: (reflect) Clarify private final field mutability
darcy
parents:
5506
diff
changeset
|
569 |
* is enforcing Java language access control and the underlying |
b2e8758b10fd
6543593: (reflect) Clarify private final field mutability
darcy
parents:
5506
diff
changeset
|
570 |
* field is inaccessible. |
58242
94bb65cb37d3
8230648: Replace @exception tag with @throws in java.base
jboes
parents:
57503
diff
changeset
|
571 |
* @throws IllegalArgumentException if the specified object is not |
2 | 572 |
* an instance of the class or interface declaring the |
573 |
* underlying field (or a subclass or implementor |
|
574 |
* thereof), or if the field value cannot be |
|
575 |
* converted to the type {@code int} by a |
|
576 |
* widening conversion. |
|
58242
94bb65cb37d3
8230648: Replace @exception tag with @throws in java.base
jboes
parents:
57503
diff
changeset
|
577 |
* @throws NullPointerException if the specified object is null |
2 | 578 |
* and the field is an instance field. |
58242
94bb65cb37d3
8230648: Replace @exception tag with @throws in java.base
jboes
parents:
57503
diff
changeset
|
579 |
* @throws ExceptionInInitializerError if the initialization provoked |
2 | 580 |
* by this method fails. |
581 |
* @see Field#get |
|
582 |
*/ |
|
16906
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
16743
diff
changeset
|
583 |
@CallerSensitive |
40175
8df87018d96a
8161379: Force inline methods calling Reflection.getCallerClass
redestad
parents:
37880
diff
changeset
|
584 |
@ForceInline // to ensure Reflection.getCallerClass optimization |
2 | 585 |
public int getInt(Object obj) |
586 |
throws IllegalArgumentException, IllegalAccessException |
|
587 |
{ |
|
16906
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
16743
diff
changeset
|
588 |
if (!override) { |
36511 | 589 |
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
|
590 |
checkAccess(caller, obj); |
16906
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
16743
diff
changeset
|
591 |
} |
2 | 592 |
return getFieldAccessor(obj).getInt(obj); |
593 |
} |
|
594 |
||
595 |
/** |
|
596 |
* Gets the value of a static or instance field of type |
|
597 |
* {@code long} or of another primitive type convertible to |
|
598 |
* type {@code long} via a widening conversion. |
|
599 |
* |
|
600 |
* @param obj the object to extract the {@code long} value |
|
601 |
* from |
|
602 |
* @return the value of the field converted to type {@code long} |
|
603 |
* |
|
58242
94bb65cb37d3
8230648: Replace @exception tag with @throws in java.base
jboes
parents:
57503
diff
changeset
|
604 |
* @throws IllegalAccessException if this {@code Field} object |
9022
b2e8758b10fd
6543593: (reflect) Clarify private final field mutability
darcy
parents:
5506
diff
changeset
|
605 |
* is enforcing Java language access control and the underlying |
b2e8758b10fd
6543593: (reflect) Clarify private final field mutability
darcy
parents:
5506
diff
changeset
|
606 |
* field is inaccessible. |
58242
94bb65cb37d3
8230648: Replace @exception tag with @throws in java.base
jboes
parents:
57503
diff
changeset
|
607 |
* @throws IllegalArgumentException if the specified object is not |
2 | 608 |
* an instance of the class or interface declaring the |
609 |
* underlying field (or a subclass or implementor |
|
610 |
* thereof), or if the field value cannot be |
|
611 |
* converted to the type {@code long} by a |
|
612 |
* widening conversion. |
|
58242
94bb65cb37d3
8230648: Replace @exception tag with @throws in java.base
jboes
parents:
57503
diff
changeset
|
613 |
* @throws NullPointerException if the specified object is null |
2 | 614 |
* and the field is an instance field. |
58242
94bb65cb37d3
8230648: Replace @exception tag with @throws in java.base
jboes
parents:
57503
diff
changeset
|
615 |
* @throws ExceptionInInitializerError if the initialization provoked |
2 | 616 |
* by this method fails. |
617 |
* @see Field#get |
|
618 |
*/ |
|
16906
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
16743
diff
changeset
|
619 |
@CallerSensitive |
40175
8df87018d96a
8161379: Force inline methods calling Reflection.getCallerClass
redestad
parents:
37880
diff
changeset
|
620 |
@ForceInline // to ensure Reflection.getCallerClass optimization |
2 | 621 |
public long getLong(Object obj) |
622 |
throws IllegalArgumentException, IllegalAccessException |
|
623 |
{ |
|
16906
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
16743
diff
changeset
|
624 |
if (!override) { |
36511 | 625 |
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
|
626 |
checkAccess(caller, obj); |
16906
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
16743
diff
changeset
|
627 |
} |
2 | 628 |
return getFieldAccessor(obj).getLong(obj); |
629 |
} |
|
630 |
||
631 |
/** |
|
632 |
* Gets the value of a static or instance field of type |
|
633 |
* {@code float} or of another primitive type convertible to |
|
634 |
* type {@code float} via a widening conversion. |
|
635 |
* |
|
636 |
* @param obj the object to extract the {@code float} value |
|
637 |
* from |
|
638 |
* @return the value of the field converted to type {@code float} |
|
639 |
* |
|
58242
94bb65cb37d3
8230648: Replace @exception tag with @throws in java.base
jboes
parents:
57503
diff
changeset
|
640 |
* @throws IllegalAccessException if this {@code Field} object |
9022
b2e8758b10fd
6543593: (reflect) Clarify private final field mutability
darcy
parents:
5506
diff
changeset
|
641 |
* is enforcing Java language access control and the underlying |
b2e8758b10fd
6543593: (reflect) Clarify private final field mutability
darcy
parents:
5506
diff
changeset
|
642 |
* field is inaccessible. |
58242
94bb65cb37d3
8230648: Replace @exception tag with @throws in java.base
jboes
parents:
57503
diff
changeset
|
643 |
* @throws IllegalArgumentException if the specified object is not |
2 | 644 |
* an instance of the class or interface declaring the |
645 |
* underlying field (or a subclass or implementor |
|
646 |
* thereof), or if the field value cannot be |
|
647 |
* converted to the type {@code float} by a |
|
648 |
* widening conversion. |
|
58242
94bb65cb37d3
8230648: Replace @exception tag with @throws in java.base
jboes
parents:
57503
diff
changeset
|
649 |
* @throws NullPointerException if the specified object is null |
2 | 650 |
* and the field is an instance field. |
58242
94bb65cb37d3
8230648: Replace @exception tag with @throws in java.base
jboes
parents:
57503
diff
changeset
|
651 |
* @throws ExceptionInInitializerError if the initialization provoked |
2 | 652 |
* by this method fails. |
653 |
* @see Field#get |
|
654 |
*/ |
|
16906
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
16743
diff
changeset
|
655 |
@CallerSensitive |
40175
8df87018d96a
8161379: Force inline methods calling Reflection.getCallerClass
redestad
parents:
37880
diff
changeset
|
656 |
@ForceInline // to ensure Reflection.getCallerClass optimization |
2 | 657 |
public float getFloat(Object obj) |
658 |
throws IllegalArgumentException, IllegalAccessException |
|
659 |
{ |
|
16906
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
16743
diff
changeset
|
660 |
if (!override) { |
36511 | 661 |
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
|
662 |
checkAccess(caller, obj); |
16906
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
16743
diff
changeset
|
663 |
} |
2 | 664 |
return getFieldAccessor(obj).getFloat(obj); |
665 |
} |
|
666 |
||
667 |
/** |
|
668 |
* Gets the value of a static or instance field of type |
|
669 |
* {@code double} or of another primitive type convertible to |
|
670 |
* type {@code double} via a widening conversion. |
|
671 |
* |
|
672 |
* @param obj the object to extract the {@code double} value |
|
673 |
* from |
|
674 |
* @return the value of the field converted to type {@code double} |
|
675 |
* |
|
58242
94bb65cb37d3
8230648: Replace @exception tag with @throws in java.base
jboes
parents:
57503
diff
changeset
|
676 |
* @throws IllegalAccessException if this {@code Field} object |
9022
b2e8758b10fd
6543593: (reflect) Clarify private final field mutability
darcy
parents:
5506
diff
changeset
|
677 |
* is enforcing Java language access control and the underlying |
b2e8758b10fd
6543593: (reflect) Clarify private final field mutability
darcy
parents:
5506
diff
changeset
|
678 |
* field is inaccessible. |
58242
94bb65cb37d3
8230648: Replace @exception tag with @throws in java.base
jboes
parents:
57503
diff
changeset
|
679 |
* @throws IllegalArgumentException if the specified object is not |
2 | 680 |
* an instance of the class or interface declaring the |
681 |
* underlying field (or a subclass or implementor |
|
682 |
* thereof), or if the field value cannot be |
|
683 |
* converted to the type {@code double} by a |
|
684 |
* widening conversion. |
|
58242
94bb65cb37d3
8230648: Replace @exception tag with @throws in java.base
jboes
parents:
57503
diff
changeset
|
685 |
* @throws NullPointerException if the specified object is null |
2 | 686 |
* and the field is an instance field. |
58242
94bb65cb37d3
8230648: Replace @exception tag with @throws in java.base
jboes
parents:
57503
diff
changeset
|
687 |
* @throws ExceptionInInitializerError if the initialization provoked |
2 | 688 |
* by this method fails. |
689 |
* @see Field#get |
|
690 |
*/ |
|
16906
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
16743
diff
changeset
|
691 |
@CallerSensitive |
40175
8df87018d96a
8161379: Force inline methods calling Reflection.getCallerClass
redestad
parents:
37880
diff
changeset
|
692 |
@ForceInline // to ensure Reflection.getCallerClass optimization |
2 | 693 |
public double getDouble(Object obj) |
694 |
throws IllegalArgumentException, IllegalAccessException |
|
695 |
{ |
|
16906
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
16743
diff
changeset
|
696 |
if (!override) { |
36511 | 697 |
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
|
698 |
checkAccess(caller, obj); |
16906
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
16743
diff
changeset
|
699 |
} |
2 | 700 |
return getFieldAccessor(obj).getDouble(obj); |
701 |
} |
|
702 |
||
703 |
/** |
|
704 |
* Sets the field represented by this {@code Field} object on the |
|
705 |
* specified object argument to the specified new value. The new |
|
706 |
* value is automatically unwrapped if the underlying field has a |
|
707 |
* primitive type. |
|
708 |
* |
|
709 |
* <p>The operation proceeds as follows: |
|
710 |
* |
|
711 |
* <p>If the underlying field is static, the {@code obj} argument is |
|
712 |
* ignored; it may be null. |
|
713 |
* |
|
714 |
* <p>Otherwise the underlying field is an instance field. If the |
|
715 |
* specified object argument is null, the method throws a |
|
716 |
* {@code NullPointerException}. If the specified object argument is not |
|
717 |
* an instance of the class or interface declaring the underlying |
|
718 |
* field, the method throws an {@code IllegalArgumentException}. |
|
719 |
* |
|
9022
b2e8758b10fd
6543593: (reflect) Clarify private final field mutability
darcy
parents:
5506
diff
changeset
|
720 |
* <p>If this {@code Field} object is enforcing Java language access control, and |
2 | 721 |
* the underlying field is inaccessible, the method throws an |
722 |
* {@code IllegalAccessException}. |
|
723 |
* |
|
724 |
* <p>If the underlying field is final, the method throws an |
|
9022
b2e8758b10fd
6543593: (reflect) Clarify private final field mutability
darcy
parents:
5506
diff
changeset
|
725 |
* {@code IllegalAccessException} unless {@code setAccessible(true)} |
b2e8758b10fd
6543593: (reflect) Clarify private final field mutability
darcy
parents:
5506
diff
changeset
|
726 |
* has succeeded for this {@code Field} object |
b2e8758b10fd
6543593: (reflect) Clarify private final field mutability
darcy
parents:
5506
diff
changeset
|
727 |
* and the field is non-static. Setting a final field in this way |
2 | 728 |
* is meaningful only during deserialization or reconstruction of |
729 |
* instances of classes with blank final fields, before they are |
|
730 |
* made available for access by other parts of a program. Use in |
|
731 |
* any other context may have unpredictable effects, including cases |
|
732 |
* in which other parts of a program continue to use the original |
|
733 |
* value of this field. |
|
734 |
* |
|
735 |
* <p>If the underlying field is of a primitive type, an unwrapping |
|
736 |
* conversion is attempted to convert the new value to a value of |
|
737 |
* a primitive type. If this attempt fails, the method throws an |
|
738 |
* {@code IllegalArgumentException}. |
|
739 |
* |
|
740 |
* <p>If, after possible unwrapping, the new value cannot be |
|
741 |
* converted to the type of the underlying field by an identity or |
|
742 |
* widening conversion, the method throws an |
|
743 |
* {@code IllegalArgumentException}. |
|
744 |
* |
|
745 |
* <p>If the underlying field is static, the class that declared the |
|
746 |
* field is initialized if it has not already been initialized. |
|
747 |
* |
|
748 |
* <p>The field is set to the possibly unwrapped and widened new value. |
|
749 |
* |
|
750 |
* <p>If the field is hidden in the type of {@code obj}, |
|
751 |
* the field's value is set according to the preceding rules. |
|
752 |
* |
|
753 |
* @param obj the object whose field should be modified |
|
754 |
* @param value the new value for the field of {@code obj} |
|
755 |
* being modified |
|
756 |
* |
|
58242
94bb65cb37d3
8230648: Replace @exception tag with @throws in java.base
jboes
parents:
57503
diff
changeset
|
757 |
* @throws IllegalAccessException if this {@code Field} object |
9022
b2e8758b10fd
6543593: (reflect) Clarify private final field mutability
darcy
parents:
5506
diff
changeset
|
758 |
* is enforcing Java language access control and the underlying |
b2e8758b10fd
6543593: (reflect) Clarify private final field mutability
darcy
parents:
5506
diff
changeset
|
759 |
* field is either inaccessible or final. |
58242
94bb65cb37d3
8230648: Replace @exception tag with @throws in java.base
jboes
parents:
57503
diff
changeset
|
760 |
* @throws IllegalArgumentException if the specified object is not an |
2 | 761 |
* instance of the class or interface declaring the underlying |
762 |
* field (or a subclass or implementor thereof), |
|
763 |
* or if an unwrapping conversion fails. |
|
58242
94bb65cb37d3
8230648: Replace @exception tag with @throws in java.base
jboes
parents:
57503
diff
changeset
|
764 |
* @throws NullPointerException if the specified object is null |
2 | 765 |
* and the field is an instance field. |
58242
94bb65cb37d3
8230648: Replace @exception tag with @throws in java.base
jboes
parents:
57503
diff
changeset
|
766 |
* @throws ExceptionInInitializerError if the initialization provoked |
2 | 767 |
* by this method fails. |
768 |
*/ |
|
16906
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
16743
diff
changeset
|
769 |
@CallerSensitive |
40175
8df87018d96a
8161379: Force inline methods calling Reflection.getCallerClass
redestad
parents:
37880
diff
changeset
|
770 |
@ForceInline // to ensure Reflection.getCallerClass optimization |
2 | 771 |
public void set(Object obj, Object value) |
772 |
throws IllegalArgumentException, IllegalAccessException |
|
773 |
{ |
|
16906
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
16743
diff
changeset
|
774 |
if (!override) { |
36511 | 775 |
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
|
776 |
checkAccess(caller, obj); |
16906
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
16743
diff
changeset
|
777 |
} |
2 | 778 |
getFieldAccessor(obj).set(obj, value); |
779 |
} |
|
780 |
||
781 |
/** |
|
782 |
* Sets the value of a field as a {@code boolean} on the specified object. |
|
783 |
* This method is equivalent to |
|
784 |
* {@code set(obj, zObj)}, |
|
785 |
* where {@code zObj} is a {@code Boolean} object and |
|
786 |
* {@code zObj.booleanValue() == z}. |
|
787 |
* |
|
788 |
* @param obj the object whose field should be modified |
|
789 |
* @param z the new value for the field of {@code obj} |
|
790 |
* being modified |
|
791 |
* |
|
58242
94bb65cb37d3
8230648: Replace @exception tag with @throws in java.base
jboes
parents:
57503
diff
changeset
|
792 |
* @throws IllegalAccessException if this {@code Field} object |
9022
b2e8758b10fd
6543593: (reflect) Clarify private final field mutability
darcy
parents:
5506
diff
changeset
|
793 |
* is enforcing Java language access control and the underlying |
b2e8758b10fd
6543593: (reflect) Clarify private final field mutability
darcy
parents:
5506
diff
changeset
|
794 |
* field is either inaccessible or final. |
58242
94bb65cb37d3
8230648: Replace @exception tag with @throws in java.base
jboes
parents:
57503
diff
changeset
|
795 |
* @throws IllegalArgumentException if the specified object is not an |
2 | 796 |
* instance of the class or interface declaring the underlying |
797 |
* field (or a subclass or implementor thereof), |
|
798 |
* or if an unwrapping conversion fails. |
|
58242
94bb65cb37d3
8230648: Replace @exception tag with @throws in java.base
jboes
parents:
57503
diff
changeset
|
799 |
* @throws NullPointerException if the specified object is null |
2 | 800 |
* and the field is an instance field. |
58242
94bb65cb37d3
8230648: Replace @exception tag with @throws in java.base
jboes
parents:
57503
diff
changeset
|
801 |
* @throws ExceptionInInitializerError if the initialization provoked |
2 | 802 |
* by this method fails. |
803 |
* @see Field#set |
|
804 |
*/ |
|
16906
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
16743
diff
changeset
|
805 |
@CallerSensitive |
40175
8df87018d96a
8161379: Force inline methods calling Reflection.getCallerClass
redestad
parents:
37880
diff
changeset
|
806 |
@ForceInline // to ensure Reflection.getCallerClass optimization |
2 | 807 |
public void setBoolean(Object obj, boolean z) |
808 |
throws IllegalArgumentException, IllegalAccessException |
|
809 |
{ |
|
16906
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
16743
diff
changeset
|
810 |
if (!override) { |
36511 | 811 |
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
|
812 |
checkAccess(caller, obj); |
16906
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
16743
diff
changeset
|
813 |
} |
2 | 814 |
getFieldAccessor(obj).setBoolean(obj, z); |
815 |
} |
|
816 |
||
817 |
/** |
|
818 |
* Sets the value of a field as a {@code byte} on the specified object. |
|
819 |
* This method is equivalent to |
|
820 |
* {@code set(obj, bObj)}, |
|
821 |
* where {@code bObj} is a {@code Byte} object and |
|
822 |
* {@code bObj.byteValue() == b}. |
|
823 |
* |
|
824 |
* @param obj the object whose field should be modified |
|
825 |
* @param b the new value for the field of {@code obj} |
|
826 |
* being modified |
|
827 |
* |
|
58242
94bb65cb37d3
8230648: Replace @exception tag with @throws in java.base
jboes
parents:
57503
diff
changeset
|
828 |
* @throws IllegalAccessException if this {@code Field} object |
9022
b2e8758b10fd
6543593: (reflect) Clarify private final field mutability
darcy
parents:
5506
diff
changeset
|
829 |
* is enforcing Java language access control and the underlying |
b2e8758b10fd
6543593: (reflect) Clarify private final field mutability
darcy
parents:
5506
diff
changeset
|
830 |
* field is either inaccessible or final. |
58242
94bb65cb37d3
8230648: Replace @exception tag with @throws in java.base
jboes
parents:
57503
diff
changeset
|
831 |
* @throws IllegalArgumentException if the specified object is not an |
2 | 832 |
* instance of the class or interface declaring the underlying |
833 |
* field (or a subclass or implementor thereof), |
|
834 |
* or if an unwrapping conversion fails. |
|
58242
94bb65cb37d3
8230648: Replace @exception tag with @throws in java.base
jboes
parents:
57503
diff
changeset
|
835 |
* @throws NullPointerException if the specified object is null |
2 | 836 |
* and the field is an instance field. |
58242
94bb65cb37d3
8230648: Replace @exception tag with @throws in java.base
jboes
parents:
57503
diff
changeset
|
837 |
* @throws ExceptionInInitializerError if the initialization provoked |
2 | 838 |
* by this method fails. |
839 |
* @see Field#set |
|
840 |
*/ |
|
16906
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
16743
diff
changeset
|
841 |
@CallerSensitive |
40175
8df87018d96a
8161379: Force inline methods calling Reflection.getCallerClass
redestad
parents:
37880
diff
changeset
|
842 |
@ForceInline // to ensure Reflection.getCallerClass optimization |
2 | 843 |
public void setByte(Object obj, byte b) |
844 |
throws IllegalArgumentException, IllegalAccessException |
|
845 |
{ |
|
16906
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
16743
diff
changeset
|
846 |
if (!override) { |
36511 | 847 |
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
|
848 |
checkAccess(caller, obj); |
16906
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
16743
diff
changeset
|
849 |
} |
2 | 850 |
getFieldAccessor(obj).setByte(obj, b); |
851 |
} |
|
852 |
||
853 |
/** |
|
854 |
* Sets the value of a field as a {@code char} on the specified object. |
|
855 |
* This method is equivalent to |
|
856 |
* {@code set(obj, cObj)}, |
|
857 |
* where {@code cObj} is a {@code Character} object and |
|
858 |
* {@code cObj.charValue() == c}. |
|
859 |
* |
|
860 |
* @param obj the object whose field should be modified |
|
861 |
* @param c the new value for the field of {@code obj} |
|
862 |
* being modified |
|
863 |
* |
|
58242
94bb65cb37d3
8230648: Replace @exception tag with @throws in java.base
jboes
parents:
57503
diff
changeset
|
864 |
* @throws IllegalAccessException if this {@code Field} object |
9022
b2e8758b10fd
6543593: (reflect) Clarify private final field mutability
darcy
parents:
5506
diff
changeset
|
865 |
* is enforcing Java language access control and the underlying |
b2e8758b10fd
6543593: (reflect) Clarify private final field mutability
darcy
parents:
5506
diff
changeset
|
866 |
* field is either inaccessible or final. |
58242
94bb65cb37d3
8230648: Replace @exception tag with @throws in java.base
jboes
parents:
57503
diff
changeset
|
867 |
* @throws IllegalArgumentException if the specified object is not an |
2 | 868 |
* instance of the class or interface declaring the underlying |
869 |
* field (or a subclass or implementor thereof), |
|
870 |
* or if an unwrapping conversion fails. |
|
58242
94bb65cb37d3
8230648: Replace @exception tag with @throws in java.base
jboes
parents:
57503
diff
changeset
|
871 |
* @throws NullPointerException if the specified object is null |
2 | 872 |
* and the field is an instance field. |
58242
94bb65cb37d3
8230648: Replace @exception tag with @throws in java.base
jboes
parents:
57503
diff
changeset
|
873 |
* @throws ExceptionInInitializerError if the initialization provoked |
2 | 874 |
* by this method fails. |
875 |
* @see Field#set |
|
876 |
*/ |
|
16906
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
16743
diff
changeset
|
877 |
@CallerSensitive |
40175
8df87018d96a
8161379: Force inline methods calling Reflection.getCallerClass
redestad
parents:
37880
diff
changeset
|
878 |
@ForceInline // to ensure Reflection.getCallerClass optimization |
2 | 879 |
public void setChar(Object obj, char c) |
880 |
throws IllegalArgumentException, IllegalAccessException |
|
881 |
{ |
|
16906
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
16743
diff
changeset
|
882 |
if (!override) { |
36511 | 883 |
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
|
884 |
checkAccess(caller, obj); |
16906
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
16743
diff
changeset
|
885 |
} |
2 | 886 |
getFieldAccessor(obj).setChar(obj, c); |
887 |
} |
|
888 |
||
889 |
/** |
|
890 |
* Sets the value of a field as a {@code short} on the specified object. |
|
891 |
* This method is equivalent to |
|
892 |
* {@code set(obj, sObj)}, |
|
893 |
* where {@code sObj} is a {@code Short} object and |
|
894 |
* {@code sObj.shortValue() == s}. |
|
895 |
* |
|
896 |
* @param obj the object whose field should be modified |
|
897 |
* @param s the new value for the field of {@code obj} |
|
898 |
* being modified |
|
899 |
* |
|
58242
94bb65cb37d3
8230648: Replace @exception tag with @throws in java.base
jboes
parents:
57503
diff
changeset
|
900 |
* @throws IllegalAccessException if this {@code Field} object |
9022
b2e8758b10fd
6543593: (reflect) Clarify private final field mutability
darcy
parents:
5506
diff
changeset
|
901 |
* is enforcing Java language access control and the underlying |
b2e8758b10fd
6543593: (reflect) Clarify private final field mutability
darcy
parents:
5506
diff
changeset
|
902 |
* field is either inaccessible or final. |
58242
94bb65cb37d3
8230648: Replace @exception tag with @throws in java.base
jboes
parents:
57503
diff
changeset
|
903 |
* @throws IllegalArgumentException if the specified object is not an |
2 | 904 |
* instance of the class or interface declaring the underlying |
905 |
* field (or a subclass or implementor thereof), |
|
906 |
* or if an unwrapping conversion fails. |
|
58242
94bb65cb37d3
8230648: Replace @exception tag with @throws in java.base
jboes
parents:
57503
diff
changeset
|
907 |
* @throws NullPointerException if the specified object is null |
2 | 908 |
* and the field is an instance field. |
58242
94bb65cb37d3
8230648: Replace @exception tag with @throws in java.base
jboes
parents:
57503
diff
changeset
|
909 |
* @throws ExceptionInInitializerError if the initialization provoked |
2 | 910 |
* by this method fails. |
911 |
* @see Field#set |
|
912 |
*/ |
|
16906
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
16743
diff
changeset
|
913 |
@CallerSensitive |
40175
8df87018d96a
8161379: Force inline methods calling Reflection.getCallerClass
redestad
parents:
37880
diff
changeset
|
914 |
@ForceInline // to ensure Reflection.getCallerClass optimization |
2 | 915 |
public void setShort(Object obj, short s) |
916 |
throws IllegalArgumentException, IllegalAccessException |
|
917 |
{ |
|
16906
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
16743
diff
changeset
|
918 |
if (!override) { |
36511 | 919 |
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
|
920 |
checkAccess(caller, obj); |
16906
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
16743
diff
changeset
|
921 |
} |
2 | 922 |
getFieldAccessor(obj).setShort(obj, s); |
923 |
} |
|
924 |
||
925 |
/** |
|
926 |
* Sets the value of a field as an {@code int} on the specified object. |
|
927 |
* This method is equivalent to |
|
928 |
* {@code set(obj, iObj)}, |
|
37880 | 929 |
* where {@code iObj} is an {@code Integer} object and |
2 | 930 |
* {@code iObj.intValue() == i}. |
931 |
* |
|
932 |
* @param obj the object whose field should be modified |
|
933 |
* @param i the new value for the field of {@code obj} |
|
934 |
* being modified |
|
935 |
* |
|
58242
94bb65cb37d3
8230648: Replace @exception tag with @throws in java.base
jboes
parents:
57503
diff
changeset
|
936 |
* @throws IllegalAccessException if this {@code Field} object |
9022
b2e8758b10fd
6543593: (reflect) Clarify private final field mutability
darcy
parents:
5506
diff
changeset
|
937 |
* is enforcing Java language access control and the underlying |
b2e8758b10fd
6543593: (reflect) Clarify private final field mutability
darcy
parents:
5506
diff
changeset
|
938 |
* field is either inaccessible or final. |
58242
94bb65cb37d3
8230648: Replace @exception tag with @throws in java.base
jboes
parents:
57503
diff
changeset
|
939 |
* @throws IllegalArgumentException if the specified object is not an |
2 | 940 |
* instance of the class or interface declaring the underlying |
941 |
* field (or a subclass or implementor thereof), |
|
942 |
* or if an unwrapping conversion fails. |
|
58242
94bb65cb37d3
8230648: Replace @exception tag with @throws in java.base
jboes
parents:
57503
diff
changeset
|
943 |
* @throws NullPointerException if the specified object is null |
2 | 944 |
* and the field is an instance field. |
58242
94bb65cb37d3
8230648: Replace @exception tag with @throws in java.base
jboes
parents:
57503
diff
changeset
|
945 |
* @throws ExceptionInInitializerError if the initialization provoked |
2 | 946 |
* by this method fails. |
947 |
* @see Field#set |
|
948 |
*/ |
|
16906
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
16743
diff
changeset
|
949 |
@CallerSensitive |
40175
8df87018d96a
8161379: Force inline methods calling Reflection.getCallerClass
redestad
parents:
37880
diff
changeset
|
950 |
@ForceInline // to ensure Reflection.getCallerClass optimization |
2 | 951 |
public void setInt(Object obj, int i) |
952 |
throws IllegalArgumentException, IllegalAccessException |
|
953 |
{ |
|
16906
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
16743
diff
changeset
|
954 |
if (!override) { |
36511 | 955 |
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
|
956 |
checkAccess(caller, obj); |
16906
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
16743
diff
changeset
|
957 |
} |
2 | 958 |
getFieldAccessor(obj).setInt(obj, i); |
959 |
} |
|
960 |
||
961 |
/** |
|
962 |
* Sets the value of a field as a {@code long} on the specified object. |
|
963 |
* This method is equivalent to |
|
964 |
* {@code set(obj, lObj)}, |
|
965 |
* where {@code lObj} is a {@code Long} object and |
|
966 |
* {@code lObj.longValue() == l}. |
|
967 |
* |
|
968 |
* @param obj the object whose field should be modified |
|
969 |
* @param l the new value for the field of {@code obj} |
|
970 |
* being modified |
|
971 |
* |
|
58242
94bb65cb37d3
8230648: Replace @exception tag with @throws in java.base
jboes
parents:
57503
diff
changeset
|
972 |
* @throws IllegalAccessException if this {@code Field} object |
9022
b2e8758b10fd
6543593: (reflect) Clarify private final field mutability
darcy
parents:
5506
diff
changeset
|
973 |
* is enforcing Java language access control and the underlying |
b2e8758b10fd
6543593: (reflect) Clarify private final field mutability
darcy
parents:
5506
diff
changeset
|
974 |
* field is either inaccessible or final. |
58242
94bb65cb37d3
8230648: Replace @exception tag with @throws in java.base
jboes
parents:
57503
diff
changeset
|
975 |
* @throws IllegalArgumentException if the specified object is not an |
2 | 976 |
* instance of the class or interface declaring the underlying |
977 |
* field (or a subclass or implementor thereof), |
|
978 |
* or if an unwrapping conversion fails. |
|
58242
94bb65cb37d3
8230648: Replace @exception tag with @throws in java.base
jboes
parents:
57503
diff
changeset
|
979 |
* @throws NullPointerException if the specified object is null |
2 | 980 |
* and the field is an instance field. |
58242
94bb65cb37d3
8230648: Replace @exception tag with @throws in java.base
jboes
parents:
57503
diff
changeset
|
981 |
* @throws ExceptionInInitializerError if the initialization provoked |
2 | 982 |
* by this method fails. |
983 |
* @see Field#set |
|
984 |
*/ |
|
16906
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
16743
diff
changeset
|
985 |
@CallerSensitive |
40175
8df87018d96a
8161379: Force inline methods calling Reflection.getCallerClass
redestad
parents:
37880
diff
changeset
|
986 |
@ForceInline // to ensure Reflection.getCallerClass optimization |
2 | 987 |
public void setLong(Object obj, long l) |
988 |
throws IllegalArgumentException, IllegalAccessException |
|
989 |
{ |
|
16906
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
16743
diff
changeset
|
990 |
if (!override) { |
36511 | 991 |
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
|
992 |
checkAccess(caller, obj); |
16906
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
16743
diff
changeset
|
993 |
} |
2 | 994 |
getFieldAccessor(obj).setLong(obj, l); |
995 |
} |
|
996 |
||
997 |
/** |
|
998 |
* Sets the value of a field as a {@code float} on the specified object. |
|
999 |
* This method is equivalent to |
|
1000 |
* {@code set(obj, fObj)}, |
|
1001 |
* where {@code fObj} is a {@code Float} object and |
|
1002 |
* {@code fObj.floatValue() == f}. |
|
1003 |
* |
|
1004 |
* @param obj the object whose field should be modified |
|
1005 |
* @param f the new value for the field of {@code obj} |
|
1006 |
* being modified |
|
1007 |
* |
|
58242
94bb65cb37d3
8230648: Replace @exception tag with @throws in java.base
jboes
parents:
57503
diff
changeset
|
1008 |
* @throws IllegalAccessException if this {@code Field} object |
9022
b2e8758b10fd
6543593: (reflect) Clarify private final field mutability
darcy
parents:
5506
diff
changeset
|
1009 |
* is enforcing Java language access control and the underlying |
b2e8758b10fd
6543593: (reflect) Clarify private final field mutability
darcy
parents:
5506
diff
changeset
|
1010 |
* field is either inaccessible or final. |
58242
94bb65cb37d3
8230648: Replace @exception tag with @throws in java.base
jboes
parents:
57503
diff
changeset
|
1011 |
* @throws IllegalArgumentException if the specified object is not an |
2 | 1012 |
* instance of the class or interface declaring the underlying |
1013 |
* field (or a subclass or implementor thereof), |
|
1014 |
* or if an unwrapping conversion fails. |
|
58242
94bb65cb37d3
8230648: Replace @exception tag with @throws in java.base
jboes
parents:
57503
diff
changeset
|
1015 |
* @throws NullPointerException if the specified object is null |
2 | 1016 |
* and the field is an instance field. |
58242
94bb65cb37d3
8230648: Replace @exception tag with @throws in java.base
jboes
parents:
57503
diff
changeset
|
1017 |
* @throws ExceptionInInitializerError if the initialization provoked |
2 | 1018 |
* by this method fails. |
1019 |
* @see Field#set |
|
1020 |
*/ |
|
16906
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
16743
diff
changeset
|
1021 |
@CallerSensitive |
40175
8df87018d96a
8161379: Force inline methods calling Reflection.getCallerClass
redestad
parents:
37880
diff
changeset
|
1022 |
@ForceInline // to ensure Reflection.getCallerClass optimization |
2 | 1023 |
public void setFloat(Object obj, float f) |
1024 |
throws IllegalArgumentException, IllegalAccessException |
|
1025 |
{ |
|
16906
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
16743
diff
changeset
|
1026 |
if (!override) { |
36511 | 1027 |
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
|
1028 |
checkAccess(caller, obj); |
16906
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
16743
diff
changeset
|
1029 |
} |
2 | 1030 |
getFieldAccessor(obj).setFloat(obj, f); |
1031 |
} |
|
1032 |
||
1033 |
/** |
|
1034 |
* Sets the value of a field as a {@code double} on the specified object. |
|
1035 |
* This method is equivalent to |
|
1036 |
* {@code set(obj, dObj)}, |
|
1037 |
* where {@code dObj} is a {@code Double} object and |
|
1038 |
* {@code dObj.doubleValue() == d}. |
|
1039 |
* |
|
1040 |
* @param obj the object whose field should be modified |
|
1041 |
* @param d the new value for the field of {@code obj} |
|
1042 |
* being modified |
|
1043 |
* |
|
58242
94bb65cb37d3
8230648: Replace @exception tag with @throws in java.base
jboes
parents:
57503
diff
changeset
|
1044 |
* @throws IllegalAccessException if this {@code Field} object |
9022
b2e8758b10fd
6543593: (reflect) Clarify private final field mutability
darcy
parents:
5506
diff
changeset
|
1045 |
* is enforcing Java language access control and the underlying |
b2e8758b10fd
6543593: (reflect) Clarify private final field mutability
darcy
parents:
5506
diff
changeset
|
1046 |
* field is either inaccessible or final. |
58242
94bb65cb37d3
8230648: Replace @exception tag with @throws in java.base
jboes
parents:
57503
diff
changeset
|
1047 |
* @throws IllegalArgumentException if the specified object is not an |
2 | 1048 |
* instance of the class or interface declaring the underlying |
1049 |
* field (or a subclass or implementor thereof), |
|
1050 |
* or if an unwrapping conversion fails. |
|
58242
94bb65cb37d3
8230648: Replace @exception tag with @throws in java.base
jboes
parents:
57503
diff
changeset
|
1051 |
* @throws NullPointerException if the specified object is null |
2 | 1052 |
* and the field is an instance field. |
58242
94bb65cb37d3
8230648: Replace @exception tag with @throws in java.base
jboes
parents:
57503
diff
changeset
|
1053 |
* @throws ExceptionInInitializerError if the initialization provoked |
2 | 1054 |
* by this method fails. |
1055 |
* @see Field#set |
|
1056 |
*/ |
|
16906
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
16743
diff
changeset
|
1057 |
@CallerSensitive |
40175
8df87018d96a
8161379: Force inline methods calling Reflection.getCallerClass
redestad
parents:
37880
diff
changeset
|
1058 |
@ForceInline // to ensure Reflection.getCallerClass optimization |
2 | 1059 |
public void setDouble(Object obj, double d) |
1060 |
throws IllegalArgumentException, IllegalAccessException |
|
1061 |
{ |
|
16906
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
16743
diff
changeset
|
1062 |
if (!override) { |
36511 | 1063 |
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
|
1064 |
checkAccess(caller, obj); |
16906
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
16743
diff
changeset
|
1065 |
} |
2 | 1066 |
getFieldAccessor(obj).setDouble(obj, d); |
1067 |
} |
|
1068 |
||
41560
a66e7ee16cf9
6378384: (reflect) subclass can’t access superclass’s protected fields and methods by reflection
plevart
parents:
40175
diff
changeset
|
1069 |
// check access to field |
a66e7ee16cf9
6378384: (reflect) subclass can’t access superclass’s protected fields and methods by reflection
plevart
parents:
40175
diff
changeset
|
1070 |
private void checkAccess(Class<?> caller, Object obj) |
a66e7ee16cf9
6378384: (reflect) subclass can’t access superclass’s protected fields and methods by reflection
plevart
parents:
40175
diff
changeset
|
1071 |
throws IllegalAccessException |
a66e7ee16cf9
6378384: (reflect) subclass can’t access superclass’s protected fields and methods by reflection
plevart
parents:
40175
diff
changeset
|
1072 |
{ |
a66e7ee16cf9
6378384: (reflect) subclass can’t access superclass’s protected fields and methods by reflection
plevart
parents:
40175
diff
changeset
|
1073 |
checkAccess(caller, clazz, |
a66e7ee16cf9
6378384: (reflect) subclass can’t access superclass’s protected fields and methods by reflection
plevart
parents:
40175
diff
changeset
|
1074 |
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
|
1075 |
modifiers); |
a66e7ee16cf9
6378384: (reflect) subclass can’t access superclass’s protected fields and methods by reflection
plevart
parents:
40175
diff
changeset
|
1076 |
} |
a66e7ee16cf9
6378384: (reflect) subclass can’t access superclass’s protected fields and methods by reflection
plevart
parents:
40175
diff
changeset
|
1077 |
|
16906
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
16743
diff
changeset
|
1078 |
// security check is done before calling this method |
2 | 1079 |
private FieldAccessor getFieldAccessor(Object obj) |
1080 |
throws IllegalAccessException |
|
1081 |
{ |
|
1082 |
boolean ov = override; |
|
16906
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
16743
diff
changeset
|
1083 |
FieldAccessor a = (ov) ? overrideFieldAccessor : fieldAccessor; |
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
16743
diff
changeset
|
1084 |
return (a != null) ? a : acquireFieldAccessor(ov); |
2 | 1085 |
} |
1086 |
||
1087 |
// NOTE that there is no synchronization used here. It is correct |
|
1088 |
// (though not efficient) to generate more than one FieldAccessor |
|
1089 |
// for a given Field. However, avoiding synchronization will |
|
1090 |
// probably make the implementation more scalable. |
|
1091 |
private FieldAccessor acquireFieldAccessor(boolean overrideFinalCheck) { |
|
1092 |
// First check to see if one has been created yet, and take it |
|
1093 |
// if so |
|
1094 |
FieldAccessor tmp = null; |
|
1095 |
if (root != null) tmp = root.getFieldAccessor(overrideFinalCheck); |
|
1096 |
if (tmp != null) { |
|
1097 |
if (overrideFinalCheck) |
|
1098 |
overrideFieldAccessor = tmp; |
|
1099 |
else |
|
1100 |
fieldAccessor = tmp; |
|
1101 |
} else { |
|
1102 |
// Otherwise fabricate one and propagate it up to the root |
|
1103 |
tmp = reflectionFactory.newFieldAccessor(this, overrideFinalCheck); |
|
1104 |
setFieldAccessor(tmp, overrideFinalCheck); |
|
1105 |
} |
|
9029
e92fcf58f684
6565585: Remove critical section in Method.invoke, Constructor.newInstance, Field.getFieldAccessor improving performance
mduigou
parents:
9022
diff
changeset
|
1106 |
|
2 | 1107 |
return tmp; |
1108 |
} |
|
1109 |
||
1110 |
// Returns FieldAccessor for this Field object, not looking up |
|
1111 |
// the chain to the root |
|
1112 |
private FieldAccessor getFieldAccessor(boolean overrideFinalCheck) { |
|
1113 |
return (overrideFinalCheck)? overrideFieldAccessor : fieldAccessor; |
|
1114 |
} |
|
1115 |
||
1116 |
// Sets the FieldAccessor for this Field object and |
|
1117 |
// (recursively) its root |
|
1118 |
private void setFieldAccessor(FieldAccessor accessor, boolean overrideFinalCheck) { |
|
1119 |
if (overrideFinalCheck) |
|
1120 |
overrideFieldAccessor = accessor; |
|
1121 |
else |
|
1122 |
fieldAccessor = accessor; |
|
1123 |
// Propagate up |
|
1124 |
if (root != null) { |
|
1125 |
root.setFieldAccessor(accessor, overrideFinalCheck); |
|
1126 |
} |
|
1127 |
} |
|
1128 |
||
50091
05979f6ba560
8202113: Reflection API is causing caller classes to leak
mchung
parents:
47216
diff
changeset
|
1129 |
@Override |
05979f6ba560
8202113: Reflection API is causing caller classes to leak
mchung
parents:
47216
diff
changeset
|
1130 |
Field getRoot() { |
05979f6ba560
8202113: Reflection API is causing caller classes to leak
mchung
parents:
47216
diff
changeset
|
1131 |
return root; |
05979f6ba560
8202113: Reflection API is causing caller classes to leak
mchung
parents:
47216
diff
changeset
|
1132 |
} |
05979f6ba560
8202113: Reflection API is causing caller classes to leak
mchung
parents:
47216
diff
changeset
|
1133 |
|
2 | 1134 |
/** |
1135 |
* @throws NullPointerException {@inheritDoc} |
|
1136 |
* @since 1.5 |
|
1137 |
*/ |
|
1138 |
public <T extends Annotation> T getAnnotation(Class<T> annotationClass) { |
|
14676
985410ec95e3
7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents:
14342
diff
changeset
|
1139 |
Objects.requireNonNull(annotationClass); |
15511
8f45487ac694
8005712: Simplify support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents:
15510
diff
changeset
|
1140 |
return annotationClass.cast(declaredAnnotations().get(annotationClass)); |
2 | 1141 |
} |
1142 |
||
1143 |
/** |
|
14676
985410ec95e3
7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents:
14342
diff
changeset
|
1144 |
* {@inheritDoc} |
985410ec95e3
7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents:
14342
diff
changeset
|
1145 |
* @throws NullPointerException {@inheritDoc} |
985410ec95e3
7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents:
14342
diff
changeset
|
1146 |
* @since 1.8 |
985410ec95e3
7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents:
14342
diff
changeset
|
1147 |
*/ |
15659
e575dab44ff5
8007278: Rename j.l.r.AnnotatedElement.getAnnotations(Class) to getAnnotationsByType(Class)
jfranck
parents:
15511
diff
changeset
|
1148 |
@Override |
e575dab44ff5
8007278: Rename j.l.r.AnnotatedElement.getAnnotations(Class) to getAnnotationsByType(Class)
jfranck
parents:
15511
diff
changeset
|
1149 |
public <T extends Annotation> T[] getAnnotationsByType(Class<T> annotationClass) { |
14676
985410ec95e3
7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents:
14342
diff
changeset
|
1150 |
Objects.requireNonNull(annotationClass); |
985410ec95e3
7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents:
14342
diff
changeset
|
1151 |
|
21316
ca0a7cd228c9
8004912: Repeating annotations - getAnnotationsByType(Class<T>) is not working as expected for few inheritance scenarios
alundblad
parents:
20482
diff
changeset
|
1152 |
return AnnotationSupport.getDirectlyAndIndirectlyPresent(declaredAnnotations(), annotationClass); |
14676
985410ec95e3
7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents:
14342
diff
changeset
|
1153 |
} |
985410ec95e3
7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents:
14342
diff
changeset
|
1154 |
|
985410ec95e3
7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents:
14342
diff
changeset
|
1155 |
/** |
985410ec95e3
7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents:
14342
diff
changeset
|
1156 |
* {@inheritDoc} |
2 | 1157 |
*/ |
1158 |
public Annotation[] getDeclaredAnnotations() { |
|
15511
8f45487ac694
8005712: Simplify support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents:
15510
diff
changeset
|
1159 |
return AnnotationParser.toArray(declaredAnnotations()); |
2 | 1160 |
} |
1161 |
||
28431
a5c817e7ddb5
8068736: Avoid synchronization on Executable/Field.declaredAnnotations
redestad
parents:
26455
diff
changeset
|
1162 |
private transient volatile Map<Class<? extends Annotation>, Annotation> declaredAnnotations; |
2 | 1163 |
|
28431
a5c817e7ddb5
8068736: Avoid synchronization on Executable/Field.declaredAnnotations
redestad
parents:
26455
diff
changeset
|
1164 |
private Map<Class<? extends Annotation>, Annotation> declaredAnnotations() { |
a5c817e7ddb5
8068736: Avoid synchronization on Executable/Field.declaredAnnotations
redestad
parents:
26455
diff
changeset
|
1165 |
Map<Class<? extends Annotation>, Annotation> declAnnos; |
a5c817e7ddb5
8068736: Avoid synchronization on Executable/Field.declaredAnnotations
redestad
parents:
26455
diff
changeset
|
1166 |
if ((declAnnos = declaredAnnotations) == null) { |
a5c817e7ddb5
8068736: Avoid synchronization on Executable/Field.declaredAnnotations
redestad
parents:
26455
diff
changeset
|
1167 |
synchronized (this) { |
a5c817e7ddb5
8068736: Avoid synchronization on Executable/Field.declaredAnnotations
redestad
parents:
26455
diff
changeset
|
1168 |
if ((declAnnos = declaredAnnotations) == null) { |
a5c817e7ddb5
8068736: Avoid synchronization on Executable/Field.declaredAnnotations
redestad
parents:
26455
diff
changeset
|
1169 |
Field root = this.root; |
a5c817e7ddb5
8068736: Avoid synchronization on Executable/Field.declaredAnnotations
redestad
parents:
26455
diff
changeset
|
1170 |
if (root != null) { |
a5c817e7ddb5
8068736: Avoid synchronization on Executable/Field.declaredAnnotations
redestad
parents:
26455
diff
changeset
|
1171 |
declAnnos = root.declaredAnnotations(); |
a5c817e7ddb5
8068736: Avoid synchronization on Executable/Field.declaredAnnotations
redestad
parents:
26455
diff
changeset
|
1172 |
} else { |
a5c817e7ddb5
8068736: Avoid synchronization on Executable/Field.declaredAnnotations
redestad
parents:
26455
diff
changeset
|
1173 |
declAnnos = AnnotationParser.parseAnnotations( |
a5c817e7ddb5
8068736: Avoid synchronization on Executable/Field.declaredAnnotations
redestad
parents:
26455
diff
changeset
|
1174 |
annotations, |
32834
e1dca5fe4de3
8137056: Move SharedSecrets and interface friends out of sun.misc
chegar
parents:
28431
diff
changeset
|
1175 |
SharedSecrets.getJavaLangAccess() |
28431
a5c817e7ddb5
8068736: Avoid synchronization on Executable/Field.declaredAnnotations
redestad
parents:
26455
diff
changeset
|
1176 |
.getConstantPool(getDeclaringClass()), |
a5c817e7ddb5
8068736: Avoid synchronization on Executable/Field.declaredAnnotations
redestad
parents:
26455
diff
changeset
|
1177 |
getDeclaringClass()); |
a5c817e7ddb5
8068736: Avoid synchronization on Executable/Field.declaredAnnotations
redestad
parents:
26455
diff
changeset
|
1178 |
} |
a5c817e7ddb5
8068736: Avoid synchronization on Executable/Field.declaredAnnotations
redestad
parents:
26455
diff
changeset
|
1179 |
declaredAnnotations = declAnnos; |
a5c817e7ddb5
8068736: Avoid synchronization on Executable/Field.declaredAnnotations
redestad
parents:
26455
diff
changeset
|
1180 |
} |
26455
195a6f3e0cd0
8054987: (reflect) Add sharing of annotations between instances of Executable
jfranck
parents:
25859
diff
changeset
|
1181 |
} |
2 | 1182 |
} |
28431
a5c817e7ddb5
8068736: Avoid synchronization on Executable/Field.declaredAnnotations
redestad
parents:
26455
diff
changeset
|
1183 |
return declAnnos; |
2 | 1184 |
} |
15510
898d924a7efd
8004698: Implement Core Reflection for Type Annotations
jfranck
parents:
14905
diff
changeset
|
1185 |
|
20482
6dc1f81f522c
8009719: core reflection should get type annotation data from the VM lazily
jfranck
parents:
18546
diff
changeset
|
1186 |
private native byte[] getTypeAnnotationBytes0(); |
6dc1f81f522c
8009719: core reflection should get type annotation data from the VM lazily
jfranck
parents:
18546
diff
changeset
|
1187 |
|
15510
898d924a7efd
8004698: Implement Core Reflection for Type Annotations
jfranck
parents:
14905
diff
changeset
|
1188 |
/** |
898d924a7efd
8004698: Implement Core Reflection for Type Annotations
jfranck
parents:
14905
diff
changeset
|
1189 |
* Returns an AnnotatedType object that represents the use of a type to specify |
898d924a7efd
8004698: Implement Core Reflection for Type Annotations
jfranck
parents:
14905
diff
changeset
|
1190 |
* the declared type of the field represented by this Field. |
18546
862067c6481c
8017550: Fix doclint issues in java.lang and subpackages
darcy
parents:
17450
diff
changeset
|
1191 |
* @return an object representing the declared type of the field |
862067c6481c
8017550: Fix doclint issues in java.lang and subpackages
darcy
parents:
17450
diff
changeset
|
1192 |
* represented by this Field |
15510
898d924a7efd
8004698: Implement Core Reflection for Type Annotations
jfranck
parents:
14905
diff
changeset
|
1193 |
* |
898d924a7efd
8004698: Implement Core Reflection for Type Annotations
jfranck
parents:
14905
diff
changeset
|
1194 |
* @since 1.8 |
898d924a7efd
8004698: Implement Core Reflection for Type Annotations
jfranck
parents:
14905
diff
changeset
|
1195 |
*/ |
898d924a7efd
8004698: Implement Core Reflection for Type Annotations
jfranck
parents:
14905
diff
changeset
|
1196 |
public AnnotatedType getAnnotatedType() { |
20482
6dc1f81f522c
8009719: core reflection should get type annotation data from the VM lazily
jfranck
parents:
18546
diff
changeset
|
1197 |
return TypeAnnotationParser.buildAnnotatedType(getTypeAnnotationBytes0(), |
32834
e1dca5fe4de3
8137056: Move SharedSecrets and interface friends out of sun.misc
chegar
parents:
28431
diff
changeset
|
1198 |
SharedSecrets.getJavaLangAccess(). |
15510
898d924a7efd
8004698: Implement Core Reflection for Type Annotations
jfranck
parents:
14905
diff
changeset
|
1199 |
getConstantPool(getDeclaringClass()), |
898d924a7efd
8004698: Implement Core Reflection for Type Annotations
jfranck
parents:
14905
diff
changeset
|
1200 |
this, |
898d924a7efd
8004698: Implement Core Reflection for Type Annotations
jfranck
parents:
14905
diff
changeset
|
1201 |
getDeclaringClass(), |
898d924a7efd
8004698: Implement Core Reflection for Type Annotations
jfranck
parents:
14905
diff
changeset
|
1202 |
getGenericType(), |
17450
0f704861915e
8007073: Implement Core Reflection for Type Annotations on parameters
jfranck
parents:
16906
diff
changeset
|
1203 |
TypeAnnotation.TypeAnnotationTarget.FIELD); |
2 | 1204 |
} |
15510
898d924a7efd
8004698: Implement Core Reflection for Type Annotations
jfranck
parents:
14905
diff
changeset
|
1205 |
} |