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