jdk/src/share/classes/java/lang/reflect/Field.java
author jfranck
Fri, 10 May 2013 10:20:13 +0200
changeset 17450 0f704861915e
parent 16906 44dfee24cb71
child 18546 862067c6481c
permissions -rw-r--r--
8007073: Implement Core Reflection for Type Annotations on parameters Reviewed-by: darcy, abuckley
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     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
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3959
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3959
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3959
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3959
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3959
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package java.lang.reflect;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
16906
44dfee24cb71 8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents: 16743
diff changeset
    28
import sun.reflect.CallerSensitive;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import sun.reflect.FieldAccessor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import sun.reflect.Reflection;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import sun.reflect.generics.repository.FieldRepository;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import sun.reflect.generics.factory.CoreReflectionFactory;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import sun.reflect.generics.factory.GenericsFactory;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import sun.reflect.generics.scope.ClassScope;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.lang.annotation.Annotation;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    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
90ce3da70b43 Initial load
duke
parents:
diff changeset
    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
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * A {@code Field} provides information about, and dynamic access to, a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * single field of a class or an interface.  The reflected field may
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * be a class (static) field or an instance field.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * <p>A {@code Field} permits widening conversions to occur during a get or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * set access operation, but throws an {@code IllegalArgumentException} if a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * narrowing conversion would occur.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * @see Member
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * @see java.lang.Class
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * @see java.lang.Class#getFields()
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * @see java.lang.Class#getField(String)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * @see java.lang.Class#getDeclaredFields()
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * @see java.lang.Class#getDeclaredField(String)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * @author Kenneth Russell
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 * @author Nakul Saraiya
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
public final
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
class Field extends AccessibleObject implements Member {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    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
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    private int                 slot;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    // This is guaranteed to be interned by the VM in the 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    // reflection implementation
90ce3da70b43 Initial load
duke
parents:
diff changeset
    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
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    private int                 modifiers;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    // Generics and annotations support
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    private transient String    signature;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    // generic info repository; lazily initialized
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    private transient FieldRepository genericInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    private byte[]              annotations;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    // Cached field accessor created without override
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    private FieldAccessor fieldAccessor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    // Cached field accessor created with override
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    private FieldAccessor overrideFieldAccessor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    // For sharing of FieldAccessors. This branching structure is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    // currently only two levels deep (i.e., one root Field and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    // potentially many Field objects pointing to it.)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    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
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    // Generics infrastructure
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    private String getGenericSignature() {return signature;}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    // Accessor for factory
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    private GenericsFactory getFactory() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
        Class<?> c = getDeclaringClass();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
        // create scope and factory
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
        return CoreReflectionFactory.make(c, ClassScope.make(c));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    // Accessor for generic info repository
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    private FieldRepository getGenericInfo() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        // lazily initialize repository if necessary
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        if (genericInfo == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
            // create and cache generic info repository
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
            genericInfo = FieldRepository.make(getGenericSignature(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
                                               getFactory());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
        return genericInfo; //return cached repository
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     * Package-private constructor used by ReflectAccess to enable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
     * instantiation of these objects in Java code from the java.lang
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
     * package via sun.reflect.LangReflectAccess.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
          int modifiers,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
          int slot,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
          String signature,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
          byte[] annotations)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
        this.clazz = declaringClass;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
        this.name = name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
        this.type = type;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
        this.modifiers = modifiers;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
        this.slot = slot;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
        this.signature = signature;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        this.annotations = annotations;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
     * Package-private routine (exposed to java.lang.Class via
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
     * ReflectAccess) which returns a copy of this Field. The copy's
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     * "root" field points to this Field.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
    Field copy() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
        // This routine enables sharing of FieldAccessor objects
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
        // among Field objects which refer to the same underlying
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        // method in the VM. (All of this contortion is only necessary
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        // because of the "accessibility" bit in AccessibleObject,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
        // which implicitly requires that new java.lang.reflect
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
        // objects be fabricated for each reflective call on Class
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
        // objects.)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
        Field res = new Field(clazz, name, type, modifiers, slot, signature, annotations);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
        res.root = this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
        // Might as well eagerly propagate this if already present
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
        res.fieldAccessor = fieldAccessor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
        return res;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
     * Returns the {@code Class} object representing the class or interface
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
     * that declares the field represented by this {@code Field} object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
    public Class<?> getDeclaringClass() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
        return clazz;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
     * Returns the name of the field represented by this {@code Field} object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
    public String getName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
        return name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
     * Returns the Java language modifiers for the field represented
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
     * by this {@code Field} object, as an integer. The {@code Modifier} class should
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
     * be used to decode the modifiers.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
     * @see Modifier
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
    public int getModifiers() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
        return modifiers;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
     * Returns {@code true} if this field represents an element of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
     * an enumerated type; returns {@code false} otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
     * @return {@code true} if and only if this field represents an element of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
     * an enumerated type.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
    public boolean isEnumConstant() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
        return (getModifiers() & Modifier.ENUM) != 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
     * Returns {@code true} if this field is a synthetic
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
     * field; returns {@code false} otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
     * @return true if and only if this field is a synthetic
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
     * field as defined by the Java Language Specification.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
    public boolean isSynthetic() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
        return Modifier.isSynthetic(getModifiers());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
     * Returns a {@code Class} object that identifies the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
     * declared type for the field represented by this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
     * {@code Field} object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
     * @return a {@code Class} object identifying the declared
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
     * type of the field represented by this object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
    public Class<?> getType() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
        return type;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
     * Returns a {@code Type} object that represents the declared type for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
     * the field represented by this {@code Field} object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
     * <p>If the {@code Type} is a parameterized type, the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
     * {@code Type} object returned must accurately reflect the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
     * actual type parameters used in the source code.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
     * <p>If the type of the underlying field is a type variable or a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
     * parameterized type, it is created. Otherwise, it is resolved.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
     * @return a {@code Type} object that represents the declared type for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
     *     the field represented by this {@code Field} object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   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&trade; Virtual Machine Specification</cite>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
     * @throws TypeNotPresentException if the generic type
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
     *     signature of the underlying field refers to a non-existent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
     *     type declaration
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
     * @throws MalformedParameterizedTypeException if the generic
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
     *     signature of the underlying field refers to a parameterized type
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
     *     that cannot be instantiated for any reason
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
    public Type getGenericType() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
        if (getGenericSignature() != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
            return getGenericInfo().getGenericType();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
        else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
            return getType();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
     * Compares this {@code Field} against the specified object.  Returns
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
     * true if the objects are the same.  Two {@code Field} objects are the same if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
     * they were declared by the same class and have the same name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
     * and type.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
    public boolean equals(Object obj) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
        if (obj != null && obj instanceof Field) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
            Field other = (Field)obj;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
            return (getDeclaringClass() == other.getDeclaringClass())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
                && (getName() == other.getName())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
                && (getType() == other.getType());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
     * Returns a hashcode for this {@code Field}.  This is computed as the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
     * exclusive-or of the hashcodes for the underlying field's
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
     * declaring class name and its name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
    public int hashCode() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
        return getDeclaringClass().getName().hashCode() ^ getName().hashCode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
     * Returns a string describing this {@code Field}.  The format is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
     * the access modifiers for the field, if any, followed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
     * by the field type, followed by a space, followed by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
     * the fully-qualified name of the class declaring the field,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
     * followed by a period, followed by the name of the field.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
     * For example:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
     *    public static final int java.lang.Thread.MIN_PRIORITY
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
     *    private int java.io.FileDescriptor.fd
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
     * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
     * <p>The modifiers are placed in canonical order as specified by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
     * "The Java Language Specification".  This is {@code public},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
     * {@code protected} or {@code private} first, and then other
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
     * modifiers in the following order: {@code static}, {@code final},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
    public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
        int mod = getModifiers();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
            + getName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
     * Returns a string describing this {@code Field}, including
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
     * its generic type.  The format is the access modifiers for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
     * field, if any, followed by the generic field type, followed by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
     * a space, followed by the fully-qualified name of the class
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
     * declaring the field, followed by a period, followed by the name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
     * of the field.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
     * <p>The modifiers are placed in canonical order as specified by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
     * "The Java Language Specification".  This is {@code public},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
     * {@code protected} or {@code private} first, and then other
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
     * modifiers in the following order: {@code static}, {@code final},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
     * {@code transient}, {@code volatile}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
     * @return a string describing this {@code Field}, including
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
     * its generic type
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
    public String toGenericString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
        int mod = getModifiers();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
        Type fieldType = getGenericType();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
            + getName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
     * Returns the value of the field represented by this {@code Field}, on
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
     * the specified object. The value is automatically wrapped in an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
     * object if it has a primitive type.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
     * <p>The underlying field's value is obtained as follows:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
     * <p>If the underlying field is a static field, the {@code obj} argument
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
     * is ignored; it may be null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
     * <p>Otherwise, the underlying field is an instance field.  If the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
     * specified {@code obj} argument is null, the method throws a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
     * {@code NullPointerException}. If the specified object is not an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
     * instance of the class or interface declaring the underlying
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
     * field, the method throws an {@code IllegalArgumentException}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
     * the underlying field is inaccessible, the method throws an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
     * {@code IllegalAccessException}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
     * If the underlying field is static, the class that declared the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
     * field is initialized if it has not already been initialized.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
     * <p>Otherwise, the value is retrieved from the underlying instance
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
     * or static field.  If the field has a primitive type, the value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
     * is wrapped in an object before being returned, otherwise it is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
     * returned as is.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
     * <p>If the field is hidden in the type of {@code obj},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
     * the field's value is obtained according to the preceding rules.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
     * @param obj object from which the represented field's value is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
     * to be extracted
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
     * @return the value of the represented field in object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
     * {@code obj}; primitive values are wrapped in an appropriate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
     * object before being returned
90ce3da70b43 Initial load
duke
parents:
diff changeset
   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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
     * @exception IllegalArgumentException  if the specified object is not an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
     *              instance of the class or interface declaring the underlying
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
     *              field (or a subclass or implementor thereof).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
     * @exception NullPointerException      if the specified object is null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
     *              and the field is an instance field.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
     * @exception ExceptionInInitializerError if the initialization provoked
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
     *              by this method fails.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
     */
16906
44dfee24cb71 8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents: 16743
diff changeset
   380
    @CallerSensitive
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
    public Object get(Object obj)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
        throws IllegalArgumentException, IllegalAccessException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
        return getFieldAccessor(obj).get(obj);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
     * Gets the value of a static or instance {@code boolean} field.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
     * @param obj the object to extract the {@code boolean} value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
     * from
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
     * @return the value of the {@code boolean} field
90ce3da70b43 Initial load
duke
parents:
diff changeset
   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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
     * @exception IllegalArgumentException  if the specified object is not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
     *              an instance of the class or interface declaring the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
     *              underlying field (or a subclass or implementor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
     *              thereof), or if the field value cannot be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
     *              converted to the type {@code boolean} by a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
     *              widening conversion.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
     * @exception NullPointerException      if the specified object is null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
     *              and the field is an instance field.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
     * @exception ExceptionInInitializerError if the initialization provoked
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
     *              by this method fails.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
     * @see       Field#get
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
     */
16906
44dfee24cb71 8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents: 16743
diff changeset
   415
    @CallerSensitive
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
    public boolean getBoolean(Object obj)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
        throws IllegalArgumentException, IllegalAccessException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
        return getFieldAccessor(obj).getBoolean(obj);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
     * Gets the value of a static or instance {@code byte} field.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
     * @param obj the object to extract the {@code byte} value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
     * from
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
     * @return the value of the {@code byte} field
90ce3da70b43 Initial load
duke
parents:
diff changeset
   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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
     * @exception IllegalArgumentException  if the specified object is not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
     *              an instance of the class or interface declaring the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
     *              underlying field (or a subclass or implementor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
     *              thereof), or if the field value cannot be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
     *              converted to the type {@code byte} by a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
     *              widening conversion.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
     * @exception NullPointerException      if the specified object is null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
     *              and the field is an instance field.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
     * @exception ExceptionInInitializerError if the initialization provoked
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
     *              by this method fails.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
     * @see       Field#get
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
     */
16906
44dfee24cb71 8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents: 16743
diff changeset
   450
    @CallerSensitive
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
    public byte getByte(Object obj)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
        throws IllegalArgumentException, IllegalAccessException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
        return getFieldAccessor(obj).getByte(obj);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
     * Gets the value of a static or instance field of type
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
     * {@code char} or of another primitive type convertible to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
     * type {@code char} via a widening conversion.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
     * @param obj the object to extract the {@code char} value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
     * from
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
     * @return the value of the field converted to type {@code char}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
     * @exception IllegalArgumentException  if the specified object is not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
     *              an instance of the class or interface declaring the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
     *              underlying field (or a subclass or implementor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
     *              thereof), or if the field value cannot be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
     *              converted to the type {@code char} by a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
     *              widening conversion.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
     * @exception NullPointerException      if the specified object is null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
     *              and the field is an instance field.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
     * @exception ExceptionInInitializerError if the initialization provoked
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
     *              by this method fails.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
     * @see Field#get
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
     */
16906
44dfee24cb71 8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents: 16743
diff changeset
   487
    @CallerSensitive
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
    public char getChar(Object obj)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
        throws IllegalArgumentException, IllegalAccessException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
        return getFieldAccessor(obj).getChar(obj);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
     * Gets the value of a static or instance field of type
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
     * {@code short} or of another primitive type convertible to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
     * type {@code short} via a widening conversion.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
     * @param obj the object to extract the {@code short} value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
     * from
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
     * @return the value of the field converted to type {@code short}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
     * @exception IllegalArgumentException  if the specified object is not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
     *              an instance of the class or interface declaring the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
     *              underlying field (or a subclass or implementor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
     *              thereof), or if the field value cannot be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
     *              converted to the type {@code short} by a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
     *              widening conversion.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
     * @exception NullPointerException      if the specified object is null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
     *              and the field is an instance field.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
     * @exception ExceptionInInitializerError if the initialization provoked
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
     *              by this method fails.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
     * @see       Field#get
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
     */
16906
44dfee24cb71 8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents: 16743
diff changeset
   524
    @CallerSensitive
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
    public short getShort(Object obj)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
        throws IllegalArgumentException, IllegalAccessException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
        return getFieldAccessor(obj).getShort(obj);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
     * Gets the value of a static or instance field of type
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
     * {@code int} or of another primitive type convertible to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
     * type {@code int} via a widening conversion.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
     * @param obj the object to extract the {@code int} value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
     * from
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
     * @return the value of the field converted to type {@code int}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
     * @exception IllegalArgumentException  if the specified object is not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
     *              an instance of the class or interface declaring the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
     *              underlying field (or a subclass or implementor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
     *              thereof), or if the field value cannot be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
     *              converted to the type {@code int} by a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
     *              widening conversion.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
     * @exception NullPointerException      if the specified object is null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
     *              and the field is an instance field.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
     * @exception ExceptionInInitializerError if the initialization provoked
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
     *              by this method fails.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
     * @see       Field#get
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
     */
16906
44dfee24cb71 8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents: 16743
diff changeset
   561
    @CallerSensitive
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
    public int getInt(Object obj)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
        throws IllegalArgumentException, IllegalAccessException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
        return getFieldAccessor(obj).getInt(obj);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
     * Gets the value of a static or instance field of type
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
     * {@code long} or of another primitive type convertible to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
     * type {@code long} via a widening conversion.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
     * @param obj the object to extract the {@code long} value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
     * from
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
     * @return the value of the field converted to type {@code long}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
     * @exception IllegalArgumentException  if the specified object is not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
     *              an instance of the class or interface declaring the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
     *              underlying field (or a subclass or implementor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
     *              thereof), or if the field value cannot be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
     *              converted to the type {@code long} by a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
     *              widening conversion.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
     * @exception NullPointerException      if the specified object is null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
     *              and the field is an instance field.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
     * @exception ExceptionInInitializerError if the initialization provoked
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
     *              by this method fails.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
     * @see       Field#get
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
     */
16906
44dfee24cb71 8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents: 16743
diff changeset
   598
    @CallerSensitive
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
    public long getLong(Object obj)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
        throws IllegalArgumentException, IllegalAccessException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
        return getFieldAccessor(obj).getLong(obj);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
     * Gets the value of a static or instance field of type
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
     * {@code float} or of another primitive type convertible to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
     * type {@code float} via a widening conversion.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
     * @param obj the object to extract the {@code float} value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
     * from
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
     * @return the value of the field converted to type {@code float}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
     * @exception IllegalArgumentException  if the specified object is not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
     *              an instance of the class or interface declaring the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
     *              underlying field (or a subclass or implementor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
     *              thereof), or if the field value cannot be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
     *              converted to the type {@code float} by a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
     *              widening conversion.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
     * @exception NullPointerException      if the specified object is null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
     *              and the field is an instance field.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
     * @exception ExceptionInInitializerError if the initialization provoked
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
     *              by this method fails.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
     * @see Field#get
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
     */
16906
44dfee24cb71 8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents: 16743
diff changeset
   635
    @CallerSensitive
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
    public float getFloat(Object obj)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
        throws IllegalArgumentException, IllegalAccessException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
        return getFieldAccessor(obj).getFloat(obj);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
     * Gets the value of a static or instance field of type
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
     * {@code double} or of another primitive type convertible to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
     * type {@code double} via a widening conversion.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
     * @param obj the object to extract the {@code double} value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
     * from
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
     * @return the value of the field converted to type {@code double}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
     * @exception IllegalArgumentException  if the specified object is not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
     *              an instance of the class or interface declaring the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
     *              underlying field (or a subclass or implementor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
     *              thereof), or if the field value cannot be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
     *              converted to the type {@code double} by a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
     *              widening conversion.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
     * @exception NullPointerException      if the specified object is null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
     *              and the field is an instance field.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
     * @exception ExceptionInInitializerError if the initialization provoked
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
     *              by this method fails.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
     * @see       Field#get
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
     */
16906
44dfee24cb71 8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents: 16743
diff changeset
   672
    @CallerSensitive
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
    public double getDouble(Object obj)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
        throws IllegalArgumentException, IllegalAccessException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
        return getFieldAccessor(obj).getDouble(obj);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
     * Sets the field represented by this {@code Field} object on the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
     * specified object argument to the specified new value. The new
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
     * value is automatically unwrapped if the underlying field has a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
     * primitive type.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
     * <p>The operation proceeds as follows:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
     * <p>If the underlying field is static, the {@code obj} argument is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
     * ignored; it may be null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
     * <p>Otherwise the underlying field is an instance field.  If the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
     * specified object argument is null, the method throws a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
     * {@code NullPointerException}.  If the specified object argument is not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
     * an instance of the class or interface declaring the underlying
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
     * field, the method throws an {@code IllegalArgumentException}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
     * the underlying field is inaccessible, the method throws an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
     * {@code IllegalAccessException}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
     * is meaningful only during deserialization or reconstruction of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
     * instances of classes with blank final fields, before they are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
     * made available for access by other parts of a program. Use in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
     * any other context may have unpredictable effects, including cases
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
     * in which other parts of a program continue to use the original
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
     * value of this field.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
     * <p>If the underlying field is of a primitive type, an unwrapping
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
     * conversion is attempted to convert the new value to a value of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
     * a primitive type.  If this attempt fails, the method throws an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
     * {@code IllegalArgumentException}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
     * <p>If, after possible unwrapping, the new value cannot be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
     * converted to the type of the underlying field by an identity or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
     * widening conversion, the method throws an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
     * {@code IllegalArgumentException}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
     * <p>If the underlying field is static, the class that declared the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
     * field is initialized if it has not already been initialized.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
     * <p>The field is set to the possibly unwrapped and widened new value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
     * <p>If the field is hidden in the type of {@code obj},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
     * the field's value is set according to the preceding rules.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
     * @param obj the object whose field should be modified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
     * @param value the new value for the field of {@code obj}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
     * being modified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
     * @exception IllegalArgumentException  if the specified object is not an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
     *              instance of the class or interface declaring the underlying
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
     *              field (or a subclass or implementor thereof),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
     *              or if an unwrapping conversion fails.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
     * @exception NullPointerException      if the specified object is null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
     *              and the field is an instance field.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
     * @exception ExceptionInInitializerError if the initialization provoked
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
     *              by this method fails.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
     */
16906
44dfee24cb71 8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents: 16743
diff changeset
   751
    @CallerSensitive
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
    public void set(Object obj, Object value)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
        throws IllegalArgumentException, IllegalAccessException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
        getFieldAccessor(obj).set(obj, value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
     * Sets the value of a field as a {@code boolean} on the specified object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
     * This method is equivalent to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
     * {@code set(obj, zObj)},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
     * where {@code zObj} is a {@code Boolean} object and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
     * {@code zObj.booleanValue() == z}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
     * @param obj the object whose field should be modified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
     * @param z   the new value for the field of {@code obj}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
     * being modified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
     * @exception IllegalArgumentException  if the specified object is not an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
     *              instance of the class or interface declaring the underlying
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
     *              field (or a subclass or implementor thereof),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
     *              or if an unwrapping conversion fails.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
     * @exception NullPointerException      if the specified object is null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
     *              and the field is an instance field.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
     * @exception ExceptionInInitializerError if the initialization provoked
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
     *              by this method fails.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
     * @see       Field#set
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
     */
16906
44dfee24cb71 8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents: 16743
diff changeset
   788
    @CallerSensitive
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
    public void setBoolean(Object obj, boolean z)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
        throws IllegalArgumentException, IllegalAccessException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
        getFieldAccessor(obj).setBoolean(obj, z);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
     * Sets the value of a field as a {@code byte} on the specified object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
     * This method is equivalent to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
     * {@code set(obj, bObj)},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
     * where {@code bObj} is a {@code Byte} object and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
     * {@code bObj.byteValue() == b}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
     * @param obj the object whose field should be modified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
     * @param b   the new value for the field of {@code obj}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
     * being modified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
     * @exception IllegalArgumentException  if the specified object is not an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
     *              instance of the class or interface declaring the underlying
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
     *              field (or a subclass or implementor thereof),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
     *              or if an unwrapping conversion fails.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
     * @exception NullPointerException      if the specified object is null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
     *              and the field is an instance field.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
     * @exception ExceptionInInitializerError if the initialization provoked
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
     *              by this method fails.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
     * @see       Field#set
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
     */
16906
44dfee24cb71 8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents: 16743
diff changeset
   825
    @CallerSensitive
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
    public void setByte(Object obj, byte b)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
        throws IllegalArgumentException, IllegalAccessException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
        getFieldAccessor(obj).setByte(obj, b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
     * Sets the value of a field as a {@code char} on the specified object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
     * This method is equivalent to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
     * {@code set(obj, cObj)},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
     * where {@code cObj} is a {@code Character} object and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
     * {@code cObj.charValue() == c}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
     * @param obj the object whose field should be modified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
     * @param c   the new value for the field of {@code obj}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
     * being modified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
     * @exception IllegalArgumentException  if the specified object is not an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
     *              instance of the class or interface declaring the underlying
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
     *              field (or a subclass or implementor thereof),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   855
     *              or if an unwrapping conversion fails.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
     * @exception NullPointerException      if the specified object is null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
     *              and the field is an instance field.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
     * @exception ExceptionInInitializerError if the initialization provoked
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
     *              by this method fails.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
     * @see       Field#set
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
     */
16906
44dfee24cb71 8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents: 16743
diff changeset
   862
    @CallerSensitive
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
    public void setChar(Object obj, char c)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
        throws IllegalArgumentException, IllegalAccessException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
        getFieldAccessor(obj).setChar(obj, c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   874
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
     * Sets the value of a field as a {@code short} on the specified object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
     * This method is equivalent to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
     * {@code set(obj, sObj)},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
     * where {@code sObj} is a {@code Short} object and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
     * {@code sObj.shortValue() == s}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
     * @param obj the object whose field should be modified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
     * @param s   the new value for the field of {@code obj}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
     * being modified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
     * @exception IllegalArgumentException  if the specified object is not an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
     *              instance of the class or interface declaring the underlying
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
     *              field (or a subclass or implementor thereof),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
     *              or if an unwrapping conversion fails.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
     * @exception NullPointerException      if the specified object is null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   894
     *              and the field is an instance field.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   895
     * @exception ExceptionInInitializerError if the initialization provoked
90ce3da70b43 Initial load
duke
parents:
diff changeset
   896
     *              by this method fails.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   897
     * @see       Field#set
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
     */
16906
44dfee24cb71 8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents: 16743
diff changeset
   899
    @CallerSensitive
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
    public void setShort(Object obj, short s)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   901
        throws IllegalArgumentException, IllegalAccessException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   909
        getFieldAccessor(obj).setShort(obj, s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   910
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   911
90ce3da70b43 Initial load
duke
parents:
diff changeset
   912
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   913
     * Sets the value of a field as an {@code int} on the specified object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   914
     * This method is equivalent to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   915
     * {@code set(obj, iObj)},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   916
     * where {@code iObj} is a {@code Integer} object and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   917
     * {@code iObj.intValue() == i}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   918
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   919
     * @param obj the object whose field should be modified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   920
     * @param i   the new value for the field of {@code obj}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   921
     * being modified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   926
     * @exception IllegalArgumentException  if the specified object is not an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   927
     *              instance of the class or interface declaring the underlying
90ce3da70b43 Initial load
duke
parents:
diff changeset
   928
     *              field (or a subclass or implementor thereof),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   929
     *              or if an unwrapping conversion fails.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   930
     * @exception NullPointerException      if the specified object is null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   931
     *              and the field is an instance field.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   932
     * @exception ExceptionInInitializerError if the initialization provoked
90ce3da70b43 Initial load
duke
parents:
diff changeset
   933
     *              by this method fails.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   934
     * @see       Field#set
90ce3da70b43 Initial load
duke
parents:
diff changeset
   935
     */
16906
44dfee24cb71 8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents: 16743
diff changeset
   936
    @CallerSensitive
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   937
    public void setInt(Object obj, int i)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   938
        throws IllegalArgumentException, IllegalAccessException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   946
        getFieldAccessor(obj).setInt(obj, i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   947
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   948
90ce3da70b43 Initial load
duke
parents:
diff changeset
   949
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   950
     * Sets the value of a field as a {@code long} on the specified object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   951
     * This method is equivalent to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   952
     * {@code set(obj, lObj)},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   953
     * where {@code lObj} is a {@code Long} object and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   954
     * {@code lObj.longValue() == l}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   955
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   956
     * @param obj the object whose field should be modified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   957
     * @param l   the new value for the field of {@code obj}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   958
     * being modified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   963
     * @exception IllegalArgumentException  if the specified object is not an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   964
     *              instance of the class or interface declaring the underlying
90ce3da70b43 Initial load
duke
parents:
diff changeset
   965
     *              field (or a subclass or implementor thereof),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   966
     *              or if an unwrapping conversion fails.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   967
     * @exception NullPointerException      if the specified object is null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   968
     *              and the field is an instance field.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   969
     * @exception ExceptionInInitializerError if the initialization provoked
90ce3da70b43 Initial load
duke
parents:
diff changeset
   970
     *              by this method fails.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   971
     * @see       Field#set
90ce3da70b43 Initial load
duke
parents:
diff changeset
   972
     */
16906
44dfee24cb71 8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents: 16743
diff changeset
   973
    @CallerSensitive
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   974
    public void setLong(Object obj, long l)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   975
        throws IllegalArgumentException, IllegalAccessException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   983
        getFieldAccessor(obj).setLong(obj, l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   984
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   985
90ce3da70b43 Initial load
duke
parents:
diff changeset
   986
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   987
     * Sets the value of a field as a {@code float} on the specified object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   988
     * This method is equivalent to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   989
     * {@code set(obj, fObj)},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   990
     * where {@code fObj} is a {@code Float} object and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   991
     * {@code fObj.floatValue() == f}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   992
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   993
     * @param obj the object whose field should be modified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   994
     * @param f   the new value for the field of {@code obj}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   995
     * being modified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   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
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1000
     * @exception IllegalArgumentException  if the specified object is not an
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1001
     *              instance of the class or interface declaring the underlying
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1002
     *              field (or a subclass or implementor thereof),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1003
     *              or if an unwrapping conversion fails.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1004
     * @exception NullPointerException      if the specified object is null
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1005
     *              and the field is an instance field.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1006
     * @exception ExceptionInInitializerError if the initialization provoked
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1007
     *              by this method fails.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1008
     * @see       Field#set
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1009
     */
16906
44dfee24cb71 8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents: 16743
diff changeset
  1010
    @CallerSensitive
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1011
    public void setFloat(Object obj, float f)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1012
        throws IllegalArgumentException, IllegalAccessException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  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
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1020
        getFieldAccessor(obj).setFloat(obj, f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1021
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1022
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1023
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1024
     * Sets the value of a field as a {@code double} on the specified object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1025
     * This method is equivalent to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1026
     * {@code set(obj, dObj)},
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1027
     * where {@code dObj} is a {@code Double} object and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1028
     * {@code dObj.doubleValue() == d}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1029
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1030
     * @param obj the object whose field should be modified
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1031
     * @param d   the new value for the field of {@code obj}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1032
     * being modified
90ce3da70b43 Initial load
duke
parents:
diff changeset
  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
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1037
     * @exception IllegalArgumentException  if the specified object is not an
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1038
     *              instance of the class or interface declaring the underlying
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1039
     *              field (or a subclass or implementor thereof),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1040
     *              or if an unwrapping conversion fails.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1041
     * @exception NullPointerException      if the specified object is null
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1042
     *              and the field is an instance field.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1043
     * @exception ExceptionInInitializerError if the initialization provoked
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1044
     *              by this method fails.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1045
     * @see       Field#set
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1046
     */
16906
44dfee24cb71 8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents: 16743
diff changeset
  1047
    @CallerSensitive
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1048
    public void setDouble(Object obj, double d)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1049
        throws IllegalArgumentException, IllegalAccessException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  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
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1057
        getFieldAccessor(obj).setDouble(obj, d);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1058
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  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
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1061
    private FieldAccessor getFieldAccessor(Object obj)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1062
        throws IllegalAccessException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1063
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  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
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1067
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1068
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1069
    // NOTE that there is no synchronization used here. It is correct
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1070
    // (though not efficient) to generate more than one FieldAccessor
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1071
    // for a given Field. However, avoiding synchronization will
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1072
    // probably make the implementation more scalable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1073
    private FieldAccessor acquireFieldAccessor(boolean overrideFinalCheck) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1074
        // First check to see if one has been created yet, and take it
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1075
        // if so
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1076
        FieldAccessor tmp = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1077
        if (root != null) tmp = root.getFieldAccessor(overrideFinalCheck);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1078
        if (tmp != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1079
            if (overrideFinalCheck)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1080
                overrideFieldAccessor = tmp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1081
            else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1082
                fieldAccessor = tmp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1083
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1084
            // Otherwise fabricate one and propagate it up to the root
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1085
            tmp = reflectionFactory.newFieldAccessor(this, overrideFinalCheck);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1086
            setFieldAccessor(tmp, overrideFinalCheck);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1087
        }
9029
e92fcf58f684 6565585: Remove critical section in Method.invoke, Constructor.newInstance, Field.getFieldAccessor improving performance
mduigou
parents: 9022
diff changeset
  1088
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1089
        return tmp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1090
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1091
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1092
    // Returns FieldAccessor for this Field object, not looking up
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1093
    // the chain to the root
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1094
    private FieldAccessor getFieldAccessor(boolean overrideFinalCheck) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1095
        return (overrideFinalCheck)? overrideFieldAccessor : fieldAccessor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1096
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1097
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1098
    // Sets the FieldAccessor for this Field object and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1099
    // (recursively) its root
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1100
    private void setFieldAccessor(FieldAccessor accessor, boolean overrideFinalCheck) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1101
        if (overrideFinalCheck)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1102
            overrideFieldAccessor = accessor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1103
        else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1104
            fieldAccessor = accessor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1105
        // Propagate up
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1106
        if (root != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1107
            root.setFieldAccessor(accessor, overrideFinalCheck);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1108
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1109
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1110
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1111
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1112
     * @throws NullPointerException {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1113
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1114
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  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
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1118
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1119
90ce3da70b43 Initial load
duke
parents:
diff changeset
  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
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1134
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  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
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1137
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  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
90ce3da70b43 Initial load
duke
parents:
diff changeset
  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
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1142
        if (declaredAnnotations == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1143
            declaredAnnotations = AnnotationParser.parseAnnotations(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1144
                annotations, sun.misc.SharedSecrets.getJavaLangAccess().
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1145
                getConstantPool(getDeclaringClass()),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1146
                getDeclaringClass());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1147
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1148
        return declaredAnnotations;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  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
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1165
}
15510
898d924a7efd 8004698: Implement Core Reflection for Type Annotations
jfranck
parents: 14905
diff changeset
  1166
}