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