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