1 /*
   2  * Copyright (c) 1996, 2021, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package java.lang.reflect;
  27 
  28 import jdk.internal.access.SharedSecrets;
  29 import jdk.internal.reflect.CallerSensitive;
  30 import jdk.internal.reflect.FieldAccessor;
  31 import jdk.internal.reflect.Reflection;
  32 import jdk.internal.vm.annotation.ForceInline;
  33 import jdk.internal.vm.annotation.Stable;
  34 import sun.reflect.generics.repository.FieldRepository;
  35 import sun.reflect.generics.factory.CoreReflectionFactory;
  36 import sun.reflect.generics.factory.GenericsFactory;
  37 import sun.reflect.generics.scope.ClassScope;
  38 import java.lang.annotation.Annotation;
  39 import java.util.Map;
  40 import java.util.Objects;
  41 import sun.reflect.annotation.AnnotationParser;
  42 import sun.reflect.annotation.AnnotationSupport;
  43 import sun.reflect.annotation.TypeAnnotation;
  44 import sun.reflect.annotation.TypeAnnotationParser;
  45 
  46 /**
  47  * A {@code Field} provides information about, and dynamic access to, a
  48  * single field of a class or an interface.  The reflected field may
  49  * be a class (static) field or an instance field.
  50  *
  51  * <p>A {@code Field} permits widening conversions to occur during a get or
  52  * set access operation, but throws an {@code IllegalArgumentException} if a
  53  * narrowing conversion would occur.
  54  *
  55  * @see Member
  56  * @see java.lang.Class
  57  * @see java.lang.Class#getFields()
  58  * @see java.lang.Class#getField(String)
  59  * @see java.lang.Class#getDeclaredFields()
  60  * @see java.lang.Class#getDeclaredField(String)
  61  *
  62  * @author Kenneth Russell
  63  * @author Nakul Saraiya
  64  * @since 1.1
  65  */
  66 public final
  67 class Field extends AccessibleObject implements Member {
  68 
  69     @Stable
  70     private Class<?>            clazz;
  71     private int                 slot;
  72     // This is guaranteed to be interned by the VM in the 1.4
  73     // reflection implementation
  74     private String              name;
  75     @Stable
  76     private Class<?>            type;
  77     @Stable
  78     private int                 modifiers;
  79     private boolean             trustedFinal;
  80     // Generics and annotations support
  81     private transient String    signature;
  82     // generic info repository; lazily initialized
  83     private transient FieldRepository genericInfo;
  84     private byte[]              annotations;
  85     // Cached field accessor created without override
  86     @Stable
  87     private FieldAccessor fieldAccessor;
  88     // Cached field accessor created with override
  89     @Stable
  90     private FieldAccessor overrideFieldAccessor;
  91     // For sharing of FieldAccessors. This branching structure is
  92     // currently only two levels deep (i.e., one root Field and
  93     // potentially many Field objects pointing to it.)
  94     //
  95     // If this branching structure would ever contain cycles, deadlocks can
  96     // occur in annotation code.
  97     private Field               root;
  98 
  99     // Generics infrastructure
 100 
 101     private String getGenericSignature() {return signature;}
 102 
 103     // Accessor for factory
 104     private GenericsFactory getFactory() {
 105         Class<?> c = getDeclaringClass();
 106         // create scope and factory
 107         return CoreReflectionFactory.make(c, ClassScope.make(c));
 108     }
 109 
 110     // Accessor for generic info repository
 111     private FieldRepository getGenericInfo() {
 112         // lazily initialize repository if necessary
 113         if (genericInfo == null) {
 114             // create and cache generic info repository
 115             genericInfo = FieldRepository.make(getGenericSignature(),
 116                                                getFactory());
 117         }
 118         return genericInfo; //return cached repository
 119     }
 120 
 121 
 122     /**
 123      * Package-private constructor
 124      */
 125     @SuppressWarnings("deprecation")
 126     Field(Class<?> declaringClass,
 127           String name,
 128           Class<?> type,
 129           int modifiers,
 130           boolean trustedFinal,
 131           int slot,
 132           String signature,
 133           byte[] annotations)
 134     {
 135         assert declaringClass.isPrimaryType();
 136         this.clazz = declaringClass;
 137         this.name = name;
 138         this.type = type;
 139         this.modifiers = modifiers;
 140         this.trustedFinal = trustedFinal;
 141         this.slot = slot;
 142         this.signature = signature;
 143         this.annotations = annotations;
 144     }
 145 
 146     /**
 147      * Package-private routine (exposed to java.lang.Class via
 148      * ReflectAccess) which returns a copy of this Field. The copy's
 149      * "root" field points to this Field.
 150      */
 151     Field copy() {
 152         // This routine enables sharing of FieldAccessor objects
 153         // among Field objects which refer to the same underlying
 154         // method in the VM. (All of this contortion is only necessary
 155         // because of the "accessibility" bit in AccessibleObject,
 156         // which implicitly requires that new java.lang.reflect
 157         // objects be fabricated for each reflective call on Class
 158         // objects.)
 159         if (this.root != null)
 160             throw new IllegalArgumentException("Can not copy a non-root Field");
 161 
 162         Field res = new Field(clazz, name, type, modifiers, trustedFinal, slot, signature, annotations);
 163         res.root = this;
 164         // Might as well eagerly propagate this if already present
 165         res.fieldAccessor = fieldAccessor;
 166         res.overrideFieldAccessor = overrideFieldAccessor;
 167 
 168         return res;
 169     }
 170 
 171     /**
 172      * @throws InaccessibleObjectException {@inheritDoc}
 173      * @throws SecurityException {@inheritDoc}
 174      */
 175     @Override
 176     @CallerSensitive
 177     public void setAccessible(boolean flag) {
 178         AccessibleObject.checkPermission();
 179         if (flag) checkCanSetAccessible(Reflection.getCallerClass());
 180         setAccessible0(flag);
 181     }
 182 
 183     @Override
 184     void checkCanSetAccessible(Class<?> caller) {
 185         checkCanSetAccessible(caller, clazz);
 186     }
 187 
 188     /**
 189      * Returns the {@code Class} object representing the class or interface
 190      * that declares the field represented by this {@code Field} object.
 191      */
 192     @Override
 193     public Class<?> getDeclaringClass() {
 194         return clazz;
 195     }
 196 
 197     /**
 198      * Returns the name of the field represented by this {@code Field} object.
 199      */
 200     public String getName() {
 201         return name;
 202     }
 203 
 204     /**
 205      * Returns the Java language modifiers for the field represented
 206      * by this {@code Field} object, as an integer. The {@code Modifier} class should
 207      * be used to decode the modifiers.
 208      *
 209      * @see Modifier
 210      * @jls 8.3 Field Declarations
 211      * @jls 9.3 Field (Constant) Declarations
 212      */
 213     public int getModifiers() {
 214         return modifiers;
 215     }
 216 
 217     /**
 218      * Returns {@code true} if this field represents an element of
 219      * an enumerated class; returns {@code false} otherwise.
 220      *
 221      * @return {@code true} if and only if this field represents an element of
 222      * an enumerated class.
 223      * @since 1.5
 224      * @jls 8.9.1 Enum Constants
 225      */
 226     public boolean isEnumConstant() {
 227         return (getModifiers() & Modifier.ENUM) != 0;
 228     }
 229 
 230     /**
 231      * Returns {@code true} if this field is a synthetic
 232      * field; returns {@code false} otherwise.
 233      *
 234      * @return true if and only if this field is a synthetic
 235      * field as defined by the Java Language Specification.
 236      * @since 1.5
 237      * @see <a
 238      * href="{@docRoot}/java.base/java/lang/reflect/package-summary.html#LanguageJvmModel">Java
 239      * programming language and JVM modeling in core reflection</a>
 240      */
 241     public boolean isSynthetic() {
 242         return Modifier.isSynthetic(getModifiers());
 243     }
 244 
 245     /**
 246      * Returns a {@code Class} object that identifies the
 247      * declared type for the field represented by this
 248      * {@code Field} object.
 249      *
 250      * @return a {@code Class} object identifying the declared
 251      * type of the field represented by this object
 252      */
 253     public Class<?> getType() {
 254         return type;
 255     }
 256 
 257     /**
 258      * Returns a {@code Type} object that represents the declared type for
 259      * the field represented by this {@code Field} object.
 260      *
 261      * <p>If the declared type of the field is a parameterized type,
 262      * the {@code Type} object returned must accurately reflect the
 263      * actual type arguments used in the source code.
 264      *
 265      * <p>If the type of the underlying field is a type variable or a
 266      * parameterized type, it is created. Otherwise, it is resolved.
 267      *
 268      * @return a {@code Type} object that represents the declared type for
 269      *     the field represented by this {@code Field} object
 270      * @throws GenericSignatureFormatError if the generic field
 271      *     signature does not conform to the format specified in
 272      *     <cite>The Java Virtual Machine Specification</cite>
 273      * @throws TypeNotPresentException if the generic type
 274      *     signature of the underlying field refers to a non-existent
 275      *     class or interface declaration
 276      * @throws MalformedParameterizedTypeException if the generic
 277      *     signature of the underlying field refers to a parameterized type
 278      *     that cannot be instantiated for any reason
 279      * @since 1.5
 280      */
 281     public Type getGenericType() {
 282         if (getGenericSignature() != null)
 283             return getGenericInfo().getGenericType();
 284         else
 285             return getType();
 286     }
 287 
 288 
 289     /**
 290      * Compares this {@code Field} against the specified object.  Returns
 291      * true if the objects are the same.  Two {@code Field} objects are the same if
 292      * they were declared by the same class and have the same name
 293      * and type.
 294      */
 295     public boolean equals(Object obj) {
 296         if (obj instanceof Field other) {
 297             return (getDeclaringClass() == other.getDeclaringClass())
 298                 && (getName() == other.getName())
 299                 && (getType() == other.getType());
 300         }
 301         return false;
 302     }
 303 
 304     /**
 305      * Returns a hashcode for this {@code Field}.  This is computed as the
 306      * exclusive-or of the hashcodes for the underlying field's
 307      * declaring class name and its name.
 308      */
 309     public int hashCode() {
 310         return getDeclaringClass().getName().hashCode() ^ getName().hashCode();
 311     }
 312 
 313     /**
 314      * Returns a string describing this {@code Field}.  The format is
 315      * the access modifiers for the field, if any, followed
 316      * by the field type, followed by a space, followed by
 317      * the fully-qualified name of the class declaring the field,
 318      * followed by a period, followed by the name of the field.
 319      * For example:
 320      * <pre>
 321      *    public static final int java.lang.Thread.MIN_PRIORITY
 322      *    private int java.io.FileDescriptor.fd
 323      * </pre>
 324      *
 325      * <p>The modifiers are placed in canonical order as specified by
 326      * "The Java Language Specification".  This is {@code public},
 327      * {@code protected} or {@code private} first, and then other
 328      * modifiers in the following order: {@code static}, {@code final},
 329      * {@code transient}, {@code volatile}.
 330      *
 331      * @return a string describing this {@code Field}
 332      * @jls 8.3.1 Field Modifiers
 333      */
 334     public String toString() {
 335         int mod = getModifiers();
 336         return (((mod == 0) ? "" : (Modifier.toString(mod) + " "))
 337             + getType().getTypeName() + " "
 338             + getDeclaringClassTypeName() + "."
 339             + getName());
 340     }
 341 
 342     @Override
 343     String toShortString() {
 344         return "field " + getDeclaringClassTypeName() + "." + getName();
 345     }
 346 
 347     String getDeclaringClassTypeName() {
 348         Class<?> c = getDeclaringClass();
 349         if (c.isPrimitiveClass()) {
 350             c = c.asValueType();
 351         }
 352         return c.getTypeName();
 353     }
 354 
 355     /**
 356      * Returns a string describing this {@code Field}, including
 357      * its generic type.  The format is the access modifiers for the
 358      * field, if any, followed by the generic field type, followed by
 359      * a space, followed by the fully-qualified name of the class
 360      * declaring the field, followed by a period, followed by the name
 361      * of the field.
 362      *
 363      * <p>The modifiers are placed in canonical order as specified by
 364      * "The Java Language Specification".  This is {@code public},
 365      * {@code protected} or {@code private} first, and then other
 366      * modifiers in the following order: {@code static}, {@code final},
 367      * {@code transient}, {@code volatile}.
 368      *
 369      * @return a string describing this {@code Field}, including
 370      * its generic type
 371      *
 372      * @since 1.5
 373      * @jls 8.3.1 Field Modifiers
 374      */
 375     public String toGenericString() {
 376         int mod = getModifiers();
 377         Type fieldType = getGenericType();
 378         return (((mod == 0) ? "" : (Modifier.toString(mod) + " "))
 379             + fieldType.getTypeName() + " "
 380             + getDeclaringClassTypeName() + "."
 381             + getName());
 382     }
 383 
 384     /**
 385      * Returns the value of the field represented by this {@code Field}, on
 386      * the specified object. The value is automatically wrapped in an
 387      * object if it has a primitive type.
 388      *
 389      * <p>The underlying field's value is obtained as follows:
 390      *
 391      * <p>If the underlying field is a static field, the {@code obj} argument
 392      * is ignored; it may be null.
 393      *
 394      * <p>Otherwise, the underlying field is an instance field.  If the
 395      * specified {@code obj} argument is null, the method throws a
 396      * {@code NullPointerException}. If the specified object is not an
 397      * instance of the class or interface declaring the underlying
 398      * field, the method throws an {@code IllegalArgumentException}.
 399      *
 400      * <p>If this {@code Field} object is enforcing Java language access control, and
 401      * the underlying field is inaccessible, the method throws an
 402      * {@code IllegalAccessException}.
 403      * If the underlying field is static, the class that declared the
 404      * field is initialized if it has not already been initialized.
 405      *
 406      * <p>Otherwise, the value is retrieved from the underlying instance
 407      * or static field.  If the field has a primitive type, the value
 408      * is wrapped in an object before being returned, otherwise it is
 409      * returned as is.
 410      *
 411      * <p>If the field is hidden in the type of {@code obj},
 412      * the field's value is obtained according to the preceding rules.
 413      *
 414      * @param obj object from which the represented field's value is
 415      * to be extracted
 416      * @return the value of the represented field in object
 417      * {@code obj}; primitive values are wrapped in an appropriate
 418      * object before being returned
 419      *
 420      * @throws    IllegalAccessException    if this {@code Field} object
 421      *              is enforcing Java language access control and the underlying
 422      *              field is inaccessible.
 423      * @throws    IllegalArgumentException  if the specified object is not an
 424      *              instance of the class or interface declaring the underlying
 425      *              field (or a subclass or implementor thereof).
 426      * @throws    NullPointerException      if the specified object is null
 427      *              and the field is an instance field.
 428      * @throws    ExceptionInInitializerError if the initialization provoked
 429      *              by this method fails.
 430      */
 431     @CallerSensitive
 432     @ForceInline // to ensure Reflection.getCallerClass optimization
 433     public Object get(Object obj)
 434         throws IllegalArgumentException, IllegalAccessException
 435     {
 436         if (!override) {
 437             Class<?> caller = Reflection.getCallerClass();
 438             checkAccess(caller, obj);
 439             return getFieldAccessor().get(obj);
 440         } else {
 441             return getOverrideFieldAccessor().get(obj);
 442         }
 443     }
 444 
 445     /**
 446      * Gets the value of a static or instance {@code boolean} field.
 447      *
 448      * @param obj the object to extract the {@code boolean} value
 449      * from
 450      * @return the value of the {@code boolean} field
 451      *
 452      * @throws    IllegalAccessException    if this {@code Field} object
 453      *              is enforcing Java language access control and the underlying
 454      *              field is inaccessible.
 455      * @throws    IllegalArgumentException  if the specified object is not
 456      *              an instance of the class or interface declaring the
 457      *              underlying field (or a subclass or implementor
 458      *              thereof), or if the field value cannot be
 459      *              converted to the type {@code boolean} by a
 460      *              widening conversion.
 461      * @throws    NullPointerException      if the specified object is null
 462      *              and the field is an instance field.
 463      * @throws    ExceptionInInitializerError if the initialization provoked
 464      *              by this method fails.
 465      * @see       Field#get
 466      */
 467     @CallerSensitive
 468     @ForceInline // to ensure Reflection.getCallerClass optimization
 469     public boolean getBoolean(Object obj)
 470         throws IllegalArgumentException, IllegalAccessException
 471     {
 472         if (!override) {
 473             Class<?> caller = Reflection.getCallerClass();
 474             checkAccess(caller, obj);
 475             return getFieldAccessor().getBoolean(obj);
 476         } else {
 477             return getOverrideFieldAccessor().getBoolean(obj);
 478         }
 479     }
 480 
 481     /**
 482      * Gets the value of a static or instance {@code byte} field.
 483      *
 484      * @param obj the object to extract the {@code byte} value
 485      * from
 486      * @return the value of the {@code byte} field
 487      *
 488      * @throws    IllegalAccessException    if this {@code Field} object
 489      *              is enforcing Java language access control and the underlying
 490      *              field is inaccessible.
 491      * @throws    IllegalArgumentException  if the specified object is not
 492      *              an instance of the class or interface declaring the
 493      *              underlying field (or a subclass or implementor
 494      *              thereof), or if the field value cannot be
 495      *              converted to the type {@code byte} by a
 496      *              widening conversion.
 497      * @throws    NullPointerException      if the specified object is null
 498      *              and the field is an instance field.
 499      * @throws    ExceptionInInitializerError if the initialization provoked
 500      *              by this method fails.
 501      * @see       Field#get
 502      */
 503     @CallerSensitive
 504     @ForceInline // to ensure Reflection.getCallerClass optimization
 505     public byte getByte(Object obj)
 506         throws IllegalArgumentException, IllegalAccessException
 507     {
 508         if (!override) {
 509             Class<?> caller = Reflection.getCallerClass();
 510             checkAccess(caller, obj);
 511             return getFieldAccessor().getByte(obj);
 512         } else {
 513             return getOverrideFieldAccessor().getByte(obj);
 514         }
 515     }
 516 
 517     /**
 518      * Gets the value of a static or instance field of type
 519      * {@code char} or of another primitive type convertible to
 520      * type {@code char} via a widening conversion.
 521      *
 522      * @param obj the object to extract the {@code char} value
 523      * from
 524      * @return the value of the field converted to type {@code char}
 525      *
 526      * @throws    IllegalAccessException    if this {@code Field} object
 527      *              is enforcing Java language access control and the underlying
 528      *              field is inaccessible.
 529      * @throws    IllegalArgumentException  if the specified object is not
 530      *              an instance of the class or interface declaring the
 531      *              underlying field (or a subclass or implementor
 532      *              thereof), or if the field value cannot be
 533      *              converted to the type {@code char} by a
 534      *              widening conversion.
 535      * @throws    NullPointerException      if the specified object is null
 536      *              and the field is an instance field.
 537      * @throws    ExceptionInInitializerError if the initialization provoked
 538      *              by this method fails.
 539      * @see Field#get
 540      */
 541     @CallerSensitive
 542     @ForceInline // to ensure Reflection.getCallerClass optimization
 543     public char getChar(Object obj)
 544         throws IllegalArgumentException, IllegalAccessException
 545     {
 546         if (!override) {
 547             Class<?> caller = Reflection.getCallerClass();
 548             checkAccess(caller, obj);
 549             return getFieldAccessor().getChar(obj);
 550         } else {
 551             return getOverrideFieldAccessor().getChar(obj);
 552         }
 553     }
 554 
 555     /**
 556      * Gets the value of a static or instance field of type
 557      * {@code short} or of another primitive type convertible to
 558      * type {@code short} via a widening conversion.
 559      *
 560      * @param obj the object to extract the {@code short} value
 561      * from
 562      * @return the value of the field converted to type {@code short}
 563      *
 564      * @throws    IllegalAccessException    if this {@code Field} object
 565      *              is enforcing Java language access control and the underlying
 566      *              field is inaccessible.
 567      * @throws    IllegalArgumentException  if the specified object is not
 568      *              an instance of the class or interface declaring the
 569      *              underlying field (or a subclass or implementor
 570      *              thereof), or if the field value cannot be
 571      *              converted to the type {@code short} by a
 572      *              widening conversion.
 573      * @throws    NullPointerException      if the specified object is null
 574      *              and the field is an instance field.
 575      * @throws    ExceptionInInitializerError if the initialization provoked
 576      *              by this method fails.
 577      * @see       Field#get
 578      */
 579     @CallerSensitive
 580     @ForceInline // to ensure Reflection.getCallerClass optimization
 581     public short getShort(Object obj)
 582         throws IllegalArgumentException, IllegalAccessException
 583     {
 584         if (!override) {
 585             Class<?> caller = Reflection.getCallerClass();
 586             checkAccess(caller, obj);
 587             return getFieldAccessor().getShort(obj);
 588         } else {
 589             return getOverrideFieldAccessor().getShort(obj);
 590         }
 591     }
 592 
 593     /**
 594      * Gets the value of a static or instance field of type
 595      * {@code int} or of another primitive type convertible to
 596      * type {@code int} via a widening conversion.
 597      *
 598      * @param obj the object to extract the {@code int} value
 599      * from
 600      * @return the value of the field converted to type {@code int}
 601      *
 602      * @throws    IllegalAccessException    if this {@code Field} object
 603      *              is enforcing Java language access control and the underlying
 604      *              field is inaccessible.
 605      * @throws    IllegalArgumentException  if the specified object is not
 606      *              an instance of the class or interface declaring the
 607      *              underlying field (or a subclass or implementor
 608      *              thereof), or if the field value cannot be
 609      *              converted to the type {@code int} by a
 610      *              widening conversion.
 611      * @throws    NullPointerException      if the specified object is null
 612      *              and the field is an instance field.
 613      * @throws    ExceptionInInitializerError if the initialization provoked
 614      *              by this method fails.
 615      * @see       Field#get
 616      */
 617     @CallerSensitive
 618     @ForceInline // to ensure Reflection.getCallerClass optimization
 619     public int getInt(Object obj)
 620         throws IllegalArgumentException, IllegalAccessException
 621     {
 622         if (!override) {
 623             Class<?> caller = Reflection.getCallerClass();
 624             checkAccess(caller, obj);
 625             return getFieldAccessor().getInt(obj);
 626         } else {
 627             return getOverrideFieldAccessor().getInt(obj);
 628         }
 629     }
 630 
 631     /**
 632      * Gets the value of a static or instance field of type
 633      * {@code long} or of another primitive type convertible to
 634      * type {@code long} via a widening conversion.
 635      *
 636      * @param obj the object to extract the {@code long} value
 637      * from
 638      * @return the value of the field converted to type {@code long}
 639      *
 640      * @throws    IllegalAccessException    if this {@code Field} object
 641      *              is enforcing Java language access control and the underlying
 642      *              field is inaccessible.
 643      * @throws    IllegalArgumentException  if the specified object is not
 644      *              an instance of the class or interface declaring the
 645      *              underlying field (or a subclass or implementor
 646      *              thereof), or if the field value cannot be
 647      *              converted to the type {@code long} by a
 648      *              widening conversion.
 649      * @throws    NullPointerException      if the specified object is null
 650      *              and the field is an instance field.
 651      * @throws    ExceptionInInitializerError if the initialization provoked
 652      *              by this method fails.
 653      * @see       Field#get
 654      */
 655     @CallerSensitive
 656     @ForceInline // to ensure Reflection.getCallerClass optimization
 657     public long getLong(Object obj)
 658         throws IllegalArgumentException, IllegalAccessException
 659     {
 660         if (!override) {
 661             Class<?> caller = Reflection.getCallerClass();
 662             checkAccess(caller, obj);
 663             return getFieldAccessor().getLong(obj);
 664         } else {
 665             return getOverrideFieldAccessor().getLong(obj);
 666         }
 667     }
 668 
 669     /**
 670      * Gets the value of a static or instance field of type
 671      * {@code float} or of another primitive type convertible to
 672      * type {@code float} via a widening conversion.
 673      *
 674      * @param obj the object to extract the {@code float} value
 675      * from
 676      * @return the value of the field converted to type {@code float}
 677      *
 678      * @throws    IllegalAccessException    if this {@code Field} object
 679      *              is enforcing Java language access control and the underlying
 680      *              field is inaccessible.
 681      * @throws    IllegalArgumentException  if the specified object is not
 682      *              an instance of the class or interface declaring the
 683      *              underlying field (or a subclass or implementor
 684      *              thereof), or if the field value cannot be
 685      *              converted to the type {@code float} by a
 686      *              widening conversion.
 687      * @throws    NullPointerException      if the specified object is null
 688      *              and the field is an instance field.
 689      * @throws    ExceptionInInitializerError if the initialization provoked
 690      *              by this method fails.
 691      * @see Field#get
 692      */
 693     @CallerSensitive
 694     @ForceInline // to ensure Reflection.getCallerClass optimization
 695     public float getFloat(Object obj)
 696         throws IllegalArgumentException, IllegalAccessException
 697     {
 698         if (!override) {
 699             Class<?> caller = Reflection.getCallerClass();
 700             checkAccess(caller, obj);
 701             return getFieldAccessor().getFloat(obj);
 702         } else {
 703             return getOverrideFieldAccessor().getFloat(obj);
 704         }
 705     }
 706 
 707     /**
 708      * Gets the value of a static or instance field of type
 709      * {@code double} or of another primitive type convertible to
 710      * type {@code double} via a widening conversion.
 711      *
 712      * @param obj the object to extract the {@code double} value
 713      * from
 714      * @return the value of the field converted to type {@code double}
 715      *
 716      * @throws    IllegalAccessException    if this {@code Field} object
 717      *              is enforcing Java language access control and the underlying
 718      *              field is inaccessible.
 719      * @throws    IllegalArgumentException  if the specified object is not
 720      *              an instance of the class or interface declaring the
 721      *              underlying field (or a subclass or implementor
 722      *              thereof), or if the field value cannot be
 723      *              converted to the type {@code double} by a
 724      *              widening conversion.
 725      * @throws    NullPointerException      if the specified object is null
 726      *              and the field is an instance field.
 727      * @throws    ExceptionInInitializerError if the initialization provoked
 728      *              by this method fails.
 729      * @see       Field#get
 730      */
 731     @CallerSensitive
 732     @ForceInline // to ensure Reflection.getCallerClass optimization
 733     public double getDouble(Object obj)
 734         throws IllegalArgumentException, IllegalAccessException
 735     {
 736         if (!override) {
 737             Class<?> caller = Reflection.getCallerClass();
 738             checkAccess(caller, obj);
 739             return getFieldAccessor().getDouble(obj);
 740         } else {
 741             return getOverrideFieldAccessor().getDouble(obj);
 742         }
 743     }
 744 
 745     /**
 746      * Sets the field represented by this {@code Field} object on the
 747      * specified object argument to the specified new value. The new
 748      * value is automatically unwrapped if the underlying field has a
 749      * primitive type.
 750      *
 751      * <p>The operation proceeds as follows:
 752      *
 753      * <p>If the underlying field is static, the {@code obj} argument is
 754      * ignored; it may be null.
 755      *
 756      * <p>Otherwise the underlying field is an instance field.  If the
 757      * specified object argument is null, the method throws a
 758      * {@code NullPointerException}.  If the specified object argument is not
 759      * an instance of the class or interface declaring the underlying
 760      * field, the method throws an {@code IllegalArgumentException}.
 761      *
 762      * <p>If this {@code Field} object is enforcing Java language access control, and
 763      * the underlying field is inaccessible, the method throws an
 764      * {@code IllegalAccessException}.
 765      *
 766      * <p>If the underlying field is final, this {@code Field} object has
 767      * <em>write</em> access if and only if the following conditions are met:
 768      * <ul>
 769      * <li>{@link #setAccessible(boolean) setAccessible(true)} has succeeded for
 770      *     this {@code Field} object;</li>
 771      * <li>the field is non-static; and</li>
 772      * <li>the field's declaring class is not a {@linkplain Class#isHidden()
 773      *     hidden class};</li>
 774      * <li>the field's declaring class is not a {@linkplain Class#isPrimitiveClass()
 775      *     primitive class}; and</li>
 776      * <li>the field's declaring class is not a {@linkplain Class#isRecord()
 777      *     record class}.</li>
 778      * </ul>
 779      * If any of the above checks is not met, this method throws an
 780      * {@code IllegalAccessException}.
 781      *
 782      * <p> Setting a final field in this way
 783      * is meaningful only during deserialization or reconstruction of
 784      * instances of classes with blank final fields, before they are
 785      * made available for access by other parts of a program. Use in
 786      * any other context may have unpredictable effects, including cases
 787      * in which other parts of a program continue to use the original
 788      * value of this field.
 789      *
 790      * <p>If the underlying field is of a primitive type, an unwrapping
 791      * conversion is attempted to convert the new value to a value of
 792      * a primitive type.  If this attempt fails, the method throws an
 793      * {@code IllegalArgumentException}.
 794      *
 795      * <p>If, after possible unwrapping, the new value cannot be
 796      * converted to the type of the underlying field by an identity or
 797      * widening conversion, the method throws an
 798      * {@code IllegalArgumentException}.
 799      *
 800      * <p>If the underlying field is static, the class that declared the
 801      * field is initialized if it has not already been initialized.
 802      *
 803      * <p>The field is set to the possibly unwrapped and widened new value.
 804      *
 805      * <p>If the field is hidden in the type of {@code obj},
 806      * the field's value is set according to the preceding rules.
 807      *
 808      * @param obj the object whose field should be modified
 809      * @param value the new value for the field of {@code obj}
 810      * being modified
 811      *
 812      * @throws    IllegalAccessException    if this {@code Field} object
 813      *              is enforcing Java language access control and the underlying
 814      *              field is inaccessible or final;
 815      *              or if this {@code Field} object has no write access.
 816      * @throws    IllegalArgumentException  if the specified object is not an
 817      *              instance of the class or interface declaring the underlying
 818      *              field (or a subclass or implementor thereof),
 819      *              or if an unwrapping conversion fails.
 820      * @throws    NullPointerException      if the specified object is null
 821      *              and the field is an instance field.
 822      * @throws    ExceptionInInitializerError if the initialization provoked
 823      *              by this method fails.
 824      */
 825     @CallerSensitive
 826     @ForceInline // to ensure Reflection.getCallerClass optimization
 827     public void set(Object obj, Object value)
 828         throws IllegalArgumentException, IllegalAccessException
 829     {
 830         if (!override) {
 831             Class<?> caller = Reflection.getCallerClass();
 832             checkAccess(caller, obj);
 833             getFieldAccessor().set(obj, value);
 834         } else {
 835             getOverrideFieldAccessor().set(obj, value);
 836         }
 837     }
 838 
 839     /**
 840      * Sets the value of a field as a {@code boolean} on the specified object.
 841      * This method is equivalent to
 842      * {@code set(obj, zObj)},
 843      * where {@code zObj} is a {@code Boolean} object and
 844      * {@code zObj.booleanValue() == z}.
 845      *
 846      * @param obj the object whose field should be modified
 847      * @param z   the new value for the field of {@code obj}
 848      * being modified
 849      *
 850      * @throws    IllegalAccessException    if this {@code Field} object
 851      *              is enforcing Java language access control and the underlying
 852      *              field is either inaccessible or final;
 853      *              or if this {@code Field} object has no write access.
 854      * @throws    IllegalArgumentException  if the specified object is not an
 855      *              instance of the class or interface declaring the underlying
 856      *              field (or a subclass or implementor thereof),
 857      *              or if an unwrapping conversion fails.
 858      * @throws    NullPointerException      if the specified object is null
 859      *              and the field is an instance field.
 860      * @throws    ExceptionInInitializerError if the initialization provoked
 861      *              by this method fails.
 862      * @see       Field#set
 863      */
 864     @CallerSensitive
 865     @ForceInline // to ensure Reflection.getCallerClass optimization
 866     public void setBoolean(Object obj, boolean z)
 867         throws IllegalArgumentException, IllegalAccessException
 868     {
 869         if (!override) {
 870             Class<?> caller = Reflection.getCallerClass();
 871             checkAccess(caller, obj);
 872             getFieldAccessor().setBoolean(obj, z);
 873         } else {
 874             getOverrideFieldAccessor().setBoolean(obj, z);
 875         }
 876     }
 877 
 878     /**
 879      * Sets the value of a field as a {@code byte} on the specified object.
 880      * This method is equivalent to
 881      * {@code set(obj, bObj)},
 882      * where {@code bObj} is a {@code Byte} object and
 883      * {@code bObj.byteValue() == b}.
 884      *
 885      * @param obj the object whose field should be modified
 886      * @param b   the new value for the field of {@code obj}
 887      * being modified
 888      *
 889      * @throws    IllegalAccessException    if this {@code Field} object
 890      *              is enforcing Java language access control and the underlying
 891      *              field is either inaccessible or final;
 892      *              or if this {@code Field} object has no write access.
 893      * @throws    IllegalArgumentException  if the specified object is not an
 894      *              instance of the class or interface declaring the underlying
 895      *              field (or a subclass or implementor thereof),
 896      *              or if an unwrapping conversion fails.
 897      * @throws    NullPointerException      if the specified object is null
 898      *              and the field is an instance field.
 899      * @throws    ExceptionInInitializerError if the initialization provoked
 900      *              by this method fails.
 901      * @see       Field#set
 902      */
 903     @CallerSensitive
 904     @ForceInline // to ensure Reflection.getCallerClass optimization
 905     public void setByte(Object obj, byte b)
 906         throws IllegalArgumentException, IllegalAccessException
 907     {
 908         if (!override) {
 909             Class<?> caller = Reflection.getCallerClass();
 910             checkAccess(caller, obj);
 911             getFieldAccessor().setByte(obj, b);
 912         } else {
 913             getOverrideFieldAccessor().setByte(obj, b);
 914         }
 915     }
 916 
 917     /**
 918      * Sets the value of a field as a {@code char} on the specified object.
 919      * This method is equivalent to
 920      * {@code set(obj, cObj)},
 921      * where {@code cObj} is a {@code Character} object and
 922      * {@code cObj.charValue() == c}.
 923      *
 924      * @param obj the object whose field should be modified
 925      * @param c   the new value for the field of {@code obj}
 926      * being modified
 927      *
 928      * @throws    IllegalAccessException    if this {@code Field} object
 929      *              is enforcing Java language access control and the underlying
 930      *              field is either inaccessible or final;
 931      *              or if this {@code Field} object has no write access.
 932      * @throws    IllegalArgumentException  if the specified object is not an
 933      *              instance of the class or interface declaring the underlying
 934      *              field (or a subclass or implementor thereof),
 935      *              or if an unwrapping conversion fails.
 936      * @throws    NullPointerException      if the specified object is null
 937      *              and the field is an instance field.
 938      * @throws    ExceptionInInitializerError if the initialization provoked
 939      *              by this method fails.
 940      * @see       Field#set
 941      */
 942     @CallerSensitive
 943     @ForceInline // to ensure Reflection.getCallerClass optimization
 944     public void setChar(Object obj, char c)
 945         throws IllegalArgumentException, IllegalAccessException
 946     {
 947         if (!override) {
 948             Class<?> caller = Reflection.getCallerClass();
 949             checkAccess(caller, obj);
 950             getFieldAccessor().setChar(obj, c);
 951         } else {
 952             getOverrideFieldAccessor().setChar(obj, c);
 953         }
 954     }
 955 
 956     /**
 957      * Sets the value of a field as a {@code short} on the specified object.
 958      * This method is equivalent to
 959      * {@code set(obj, sObj)},
 960      * where {@code sObj} is a {@code Short} object and
 961      * {@code sObj.shortValue() == s}.
 962      *
 963      * @param obj the object whose field should be modified
 964      * @param s   the new value for the field of {@code obj}
 965      * being modified
 966      *
 967      * @throws    IllegalAccessException    if this {@code Field} object
 968      *              is enforcing Java language access control and the underlying
 969      *              field is either inaccessible or final;
 970      *              or if this {@code Field} object has no write access.
 971      * @throws    IllegalArgumentException  if the specified object is not an
 972      *              instance of the class or interface declaring the underlying
 973      *              field (or a subclass or implementor thereof),
 974      *              or if an unwrapping conversion fails.
 975      * @throws    NullPointerException      if the specified object is null
 976      *              and the field is an instance field.
 977      * @throws    ExceptionInInitializerError if the initialization provoked
 978      *              by this method fails.
 979      * @see       Field#set
 980      */
 981     @CallerSensitive
 982     @ForceInline // to ensure Reflection.getCallerClass optimization
 983     public void setShort(Object obj, short s)
 984         throws IllegalArgumentException, IllegalAccessException
 985     {
 986         if (!override) {
 987             Class<?> caller = Reflection.getCallerClass();
 988             checkAccess(caller, obj);
 989             getFieldAccessor().setShort(obj, s);
 990         } else {
 991             getOverrideFieldAccessor().setShort(obj, s);
 992         }
 993     }
 994 
 995     /**
 996      * Sets the value of a field as an {@code int} on the specified object.
 997      * This method is equivalent to
 998      * {@code set(obj, iObj)},
 999      * where {@code iObj} is an {@code Integer} object and
1000      * {@code iObj.intValue() == i}.
1001      *
1002      * @param obj the object whose field should be modified
1003      * @param i   the new value for the field of {@code obj}
1004      * being modified
1005      *
1006      * @throws    IllegalAccessException    if this {@code Field} object
1007      *              is enforcing Java language access control and the underlying
1008      *              field is either inaccessible or final;
1009      *              or if this {@code Field} object has no write access.
1010      * @throws    IllegalArgumentException  if the specified object is not an
1011      *              instance of the class or interface declaring the underlying
1012      *              field (or a subclass or implementor thereof),
1013      *              or if an unwrapping conversion fails.
1014      * @throws    NullPointerException      if the specified object is null
1015      *              and the field is an instance field.
1016      * @throws    ExceptionInInitializerError if the initialization provoked
1017      *              by this method fails.
1018      * @see       Field#set
1019      */
1020     @CallerSensitive
1021     @ForceInline // to ensure Reflection.getCallerClass optimization
1022     public void setInt(Object obj, int i)
1023         throws IllegalArgumentException, IllegalAccessException
1024     {
1025         if (!override) {
1026             Class<?> caller = Reflection.getCallerClass();
1027             checkAccess(caller, obj);
1028             getFieldAccessor().setInt(obj, i);
1029         } else {
1030             getOverrideFieldAccessor().setInt(obj, i);
1031         }
1032     }
1033 
1034     /**
1035      * Sets the value of a field as a {@code long} on the specified object.
1036      * This method is equivalent to
1037      * {@code set(obj, lObj)},
1038      * where {@code lObj} is a {@code Long} object and
1039      * {@code lObj.longValue() == l}.
1040      *
1041      * @param obj the object whose field should be modified
1042      * @param l   the new value for the field of {@code obj}
1043      * being modified
1044      *
1045      * @throws    IllegalAccessException    if this {@code Field} object
1046      *              is enforcing Java language access control and the underlying
1047      *              field is either inaccessible or final;
1048      *              or if this {@code Field} object has no write access.
1049      * @throws    IllegalArgumentException  if the specified object is not an
1050      *              instance of the class or interface declaring the underlying
1051      *              field (or a subclass or implementor thereof),
1052      *              or if an unwrapping conversion fails.
1053      * @throws    NullPointerException      if the specified object is null
1054      *              and the field is an instance field.
1055      * @throws    ExceptionInInitializerError if the initialization provoked
1056      *              by this method fails.
1057      * @see       Field#set
1058      */
1059     @CallerSensitive
1060     @ForceInline // to ensure Reflection.getCallerClass optimization
1061     public void setLong(Object obj, long l)
1062         throws IllegalArgumentException, IllegalAccessException
1063     {
1064         if (!override) {
1065             Class<?> caller = Reflection.getCallerClass();
1066             checkAccess(caller, obj);
1067             getFieldAccessor().setLong(obj, l);
1068         } else {
1069             getOverrideFieldAccessor().setLong(obj, l);
1070         }
1071     }
1072 
1073     /**
1074      * Sets the value of a field as a {@code float} on the specified object.
1075      * This method is equivalent to
1076      * {@code set(obj, fObj)},
1077      * where {@code fObj} is a {@code Float} object and
1078      * {@code fObj.floatValue() == f}.
1079      *
1080      * @param obj the object whose field should be modified
1081      * @param f   the new value for the field of {@code obj}
1082      * being modified
1083      *
1084      * @throws    IllegalAccessException    if this {@code Field} object
1085      *              is enforcing Java language access control and the underlying
1086      *              field is either inaccessible or final;
1087      *              or if this {@code Field} object has no write access.
1088      * @throws    IllegalArgumentException  if the specified object is not an
1089      *              instance of the class or interface declaring the underlying
1090      *              field (or a subclass or implementor thereof),
1091      *              or if an unwrapping conversion fails.
1092      * @throws    NullPointerException      if the specified object is null
1093      *              and the field is an instance field.
1094      * @throws    ExceptionInInitializerError if the initialization provoked
1095      *              by this method fails.
1096      * @see       Field#set
1097      */
1098     @CallerSensitive
1099     @ForceInline // to ensure Reflection.getCallerClass optimization
1100     public void setFloat(Object obj, float f)
1101         throws IllegalArgumentException, IllegalAccessException
1102     {
1103         if (!override) {
1104             Class<?> caller = Reflection.getCallerClass();
1105             checkAccess(caller, obj);
1106             getFieldAccessor().setFloat(obj, f);
1107         } else {
1108             getOverrideFieldAccessor().setFloat(obj, f);
1109         }
1110     }
1111 
1112     /**
1113      * Sets the value of a field as a {@code double} on the specified object.
1114      * This method is equivalent to
1115      * {@code set(obj, dObj)},
1116      * where {@code dObj} is a {@code Double} object and
1117      * {@code dObj.doubleValue() == d}.
1118      *
1119      * @param obj the object whose field should be modified
1120      * @param d   the new value for the field of {@code obj}
1121      * being modified
1122      *
1123      * @throws    IllegalAccessException    if this {@code Field} object
1124      *              is enforcing Java language access control and the underlying
1125      *              field is either inaccessible or final;
1126      *              or if this {@code Field} object has no write access.
1127      * @throws    IllegalArgumentException  if the specified object is not an
1128      *              instance of the class or interface declaring the underlying
1129      *              field (or a subclass or implementor thereof),
1130      *              or if an unwrapping conversion fails.
1131      * @throws    NullPointerException      if the specified object is null
1132      *              and the field is an instance field.
1133      * @throws    ExceptionInInitializerError if the initialization provoked
1134      *              by this method fails.
1135      * @see       Field#set
1136      */
1137     @CallerSensitive
1138     @ForceInline // to ensure Reflection.getCallerClass optimization
1139     public void setDouble(Object obj, double d)
1140         throws IllegalArgumentException, IllegalAccessException
1141     {
1142         if (!override) {
1143             Class<?> caller = Reflection.getCallerClass();
1144             checkAccess(caller, obj);
1145             getFieldAccessor().setDouble(obj, d);
1146         } else {
1147             getOverrideFieldAccessor().setDouble(obj, d);
1148         }
1149     }
1150 
1151     // check access to field
1152     private void checkAccess(Class<?> caller, Object obj)
1153         throws IllegalAccessException
1154     {
1155         checkAccess(caller, clazz,
1156                     Modifier.isStatic(modifiers) ? null : obj.getClass(),
1157                     modifiers);
1158     }
1159 
1160     // security check is done before calling this method
1161     private FieldAccessor getFieldAccessor() {
1162         FieldAccessor a = fieldAccessor;
1163         return (a != null) ? a : acquireFieldAccessor();
1164     }
1165 
1166     private FieldAccessor getOverrideFieldAccessor() {
1167         FieldAccessor a = overrideFieldAccessor;
1168         return (a != null) ? a : acquireOverrideFieldAccessor();
1169     }
1170 
1171     // NOTE that there is no synchronization used here. It is correct
1172     // (though not efficient) to generate more than one FieldAccessor
1173     // for a given Field. However, avoiding synchronization will
1174     // probably make the implementation more scalable.
1175     private FieldAccessor acquireFieldAccessor() {
1176         // First check to see if one has been created yet, and take it
1177         // if so
1178         Field root = this.root;
1179         FieldAccessor tmp = root == null ? null : root.fieldAccessor;
1180         if (tmp != null) {
1181             fieldAccessor = tmp;
1182         } else {
1183             // Otherwise fabricate one and propagate it up to the root
1184             tmp = reflectionFactory.newFieldAccessor(this, false);
1185             setFieldAccessor(tmp);
1186         }
1187         return tmp;
1188     }
1189 
1190     private FieldAccessor acquireOverrideFieldAccessor() {
1191         // First check to see if one has been created yet, and take it
1192         // if so
1193         Field root = this.root;
1194         FieldAccessor tmp = root == null ? null : root.overrideFieldAccessor;
1195         if (tmp != null) {
1196             overrideFieldAccessor = tmp;
1197         } else {
1198             // Otherwise fabricate one and propagate it up to the root
1199             tmp = reflectionFactory.newFieldAccessor(this, true);
1200             setOverrideFieldAccessor(tmp);
1201         }
1202         return tmp;
1203     }
1204 
1205     // Sets the fieldAccessor for this Field object and
1206     // (recursively) its root
1207     private void setFieldAccessor(FieldAccessor accessor) {
1208         fieldAccessor = accessor;
1209         // Propagate up
1210         Field root = this.root;
1211         if (root != null) {
1212             root.setFieldAccessor(accessor);
1213         }
1214     }
1215 
1216     // Sets the overrideFieldAccessor for this Field object and
1217     // (recursively) its root
1218     private void setOverrideFieldAccessor(FieldAccessor accessor) {
1219         overrideFieldAccessor = accessor;
1220         // Propagate up
1221         Field root = this.root;
1222         if (root != null) {
1223             root.setOverrideFieldAccessor(accessor);
1224         }
1225     }
1226 
1227     @Override
1228     /* package-private */ Field getRoot() {
1229         return root;
1230     }
1231 
1232     /* package-private */ boolean isTrustedFinal() {
1233         return trustedFinal;
1234     }
1235 
1236     /**
1237      * {@inheritDoc}
1238      *
1239      * @throws NullPointerException {@inheritDoc}
1240      * @since 1.5
1241      */
1242     @Override
1243     public <T extends Annotation> T getAnnotation(Class<T> annotationClass) {
1244         Objects.requireNonNull(annotationClass);
1245         return annotationClass.cast(declaredAnnotations().get(annotationClass));
1246     }
1247 
1248     /**
1249      * {@inheritDoc}
1250      *
1251      * @throws NullPointerException {@inheritDoc}
1252      * @since 1.8
1253      */
1254     @Override
1255     public <T extends Annotation> T[] getAnnotationsByType(Class<T> annotationClass) {
1256         Objects.requireNonNull(annotationClass);
1257 
1258         return AnnotationSupport.getDirectlyAndIndirectlyPresent(declaredAnnotations(), annotationClass);
1259     }
1260 
1261     /**
1262      * {@inheritDoc}
1263      */
1264     @Override
1265     public Annotation[] getDeclaredAnnotations()  {
1266         return AnnotationParser.toArray(declaredAnnotations());
1267     }
1268 
1269     private transient volatile Map<Class<? extends Annotation>, Annotation> declaredAnnotations;
1270 
1271     private Map<Class<? extends Annotation>, Annotation> declaredAnnotations() {
1272         Map<Class<? extends Annotation>, Annotation> declAnnos;
1273         if ((declAnnos = declaredAnnotations) == null) {
1274             synchronized (this) {
1275                 if ((declAnnos = declaredAnnotations) == null) {
1276                     Field root = this.root;
1277                     if (root != null) {
1278                         declAnnos = root.declaredAnnotations();
1279                     } else {
1280                         declAnnos = AnnotationParser.parseAnnotations(
1281                                 annotations,
1282                                 SharedSecrets.getJavaLangAccess()
1283                                         .getConstantPool(getDeclaringClass()),
1284                                 getDeclaringClass());
1285                     }
1286                     declaredAnnotations = declAnnos;
1287                 }
1288             }
1289         }
1290         return declAnnos;
1291     }
1292 
1293     private native byte[] getTypeAnnotationBytes0();
1294 
1295     /**
1296      * Returns an AnnotatedType object that represents the use of a type to specify
1297      * the declared type of the field represented by this Field.
1298      * @return an object representing the declared type of the field
1299      * represented by this Field
1300      *
1301      * @since 1.8
1302      */
1303     public AnnotatedType getAnnotatedType() {
1304         return TypeAnnotationParser.buildAnnotatedType(getTypeAnnotationBytes0(),
1305                                                        SharedSecrets.getJavaLangAccess().
1306                                                            getConstantPool(getDeclaringClass()),
1307                                                        this,
1308                                                        getDeclaringClass(),
1309                                                        getGenericType(),
1310                                                        TypeAnnotation.TypeAnnotationTarget.FIELD);
1311 }
1312 }