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