< prev index next >

src/java.base/share/classes/java/lang/reflect/Field.java

Print this page
*** 71,11 ***
      // This is guaranteed to be interned by the VM in the 1.4
      // reflection implementation
      private final String              name;
      private final Class<?>            type;
      private final int                 modifiers;
!     private final boolean             trustedFinal;
      // Generics and annotations support
      private final transient String    signature;
      // generic info repository; lazily initialized
      private transient volatile FieldRepository genericInfo;
      private final byte[]              annotations;
--- 71,11 ---
      // This is guaranteed to be interned by the VM in the 1.4
      // reflection implementation
      private final String              name;
      private final Class<?>            type;
      private final int                 modifiers;
!     private final int                 flags;
      // Generics and annotations support
      private final transient String    signature;
      // generic info repository; lazily initialized
      private transient volatile FieldRepository genericInfo;
      private final byte[]              annotations;

*** 124,20 ***
      @SuppressWarnings("deprecation")
      Field(Class<?> declaringClass,
            String name,
            Class<?> type,
            int modifiers,
!           boolean trustedFinal,
            int slot,
            String signature,
            byte[] annotations)
      {
          this.clazz = declaringClass;
          this.name = name;
          this.type = type;
          this.modifiers = modifiers;
!         this.trustedFinal = trustedFinal;
          this.slot = slot;
          this.signature = signature;
          this.annotations = annotations;
      }
  
--- 124,20 ---
      @SuppressWarnings("deprecation")
      Field(Class<?> declaringClass,
            String name,
            Class<?> type,
            int modifiers,
!           int flags,
            int slot,
            String signature,
            byte[] annotations)
      {
          this.clazz = declaringClass;
          this.name = name;
          this.type = type;
          this.modifiers = modifiers;
!         this.flags = flags;
          this.slot = slot;
          this.signature = signature;
          this.annotations = annotations;
      }
  

*** 155,11 ***
          // objects be fabricated for each reflective call on Class
          // objects.)
          if (this.root != null)
              throw new IllegalArgumentException("Can not copy a non-root Field");
  
!         Field res = new Field(clazz, name, type, modifiers, trustedFinal, slot, signature, annotations);
          res.root = this;
          // Might as well eagerly propagate this if already present
          res.fieldAccessor = fieldAccessor;
          res.overrideFieldAccessor = overrideFieldAccessor;
  
--- 155,11 ---
          // objects be fabricated for each reflective call on Class
          // objects.)
          if (this.root != null)
              throw new IllegalArgumentException("Can not copy a non-root Field");
  
!         Field res = new Field(clazz, name, type, modifiers, flags, slot, signature, annotations);
          res.root = this;
          // Might as well eagerly propagate this if already present
          res.fieldAccessor = fieldAccessor;
          res.overrideFieldAccessor = overrideFieldAccessor;
  

*** 214,17 ***
      }
  
      /**
       * {@return an unmodifiable set of the {@linkplain AccessFlag
       * access flags} for this field, possibly empty}
       * @see #getModifiers()
       * @jvms 4.5 Fields
       * @since 20
       */
      @Override
      public Set<AccessFlag> accessFlags() {
!         return AccessFlag.maskToAccessFlags(getModifiers(), AccessFlag.Location.FIELD);
      }
  
      /**
       * Returns {@code true} if this field represents an element of
       * an enumerated class; returns {@code false} otherwise.
--- 214,21 ---
      }
  
      /**
       * {@return an unmodifiable set of the {@linkplain AccessFlag
       * access flags} for this field, possibly empty}
+      * The {@code AccessFlags} may depend on the class file format version of the class.
+      *
       * @see #getModifiers()
       * @jvms 4.5 Fields
       * @since 20
       */
      @Override
      public Set<AccessFlag> accessFlags() {
!         int major = SharedSecrets.getJavaLangAccess().classFileFormatVersion(getDeclaringClass()) & 0xffff;
+         var cffv = ClassFileFormatVersion.fromMajor(major);
+         return AccessFlag.maskToAccessFlags(getModifiers(), AccessFlag.Location.FIELD, cffv);
      }
  
      /**
       * Returns {@code true} if this field represents an element of
       * an enumerated class; returns {@code false} otherwise.

*** 771,11 ***
       * <ul>
       * <li>{@link #setAccessible(boolean) setAccessible(true)} has succeeded for
       *     this {@code Field} object;</li>
       * <li>the field is non-static; and</li>
       * <li>the field's declaring class is not a {@linkplain Class#isHidden()
!      *     hidden class}; and</li>
       * <li>the field's declaring class is not a {@linkplain Class#isRecord()
       *     record class}.</li>
       * </ul>
       * If any of the above checks is not met, this method throws an
       * {@code IllegalAccessException}.
--- 775,13 ---
       * <ul>
       * <li>{@link #setAccessible(boolean) setAccessible(true)} has succeeded for
       *     this {@code Field} object;</li>
       * <li>the field is non-static; and</li>
       * <li>the field's declaring class is not a {@linkplain Class#isHidden()
!      *     hidden class};</li>
+      * <li>the field's declaring class is not a {@linkplain Class#isValue()
+      *     value class}; and</li>
       * <li>the field's declaring class is not a {@linkplain Class#isRecord()
       *     record class}.</li>
       * </ul>
       * If any of the above checks is not met, this method throws an
       * {@code IllegalAccessException}.

*** 1228,12 ***
      @Override
      /* package-private */ Field getRoot() {
          return root;
      }
  
      /* package-private */ boolean isTrustedFinal() {
!         return trustedFinal;
      }
  
      /**
       * {@inheritDoc}
       *
--- 1234,19 ---
      @Override
      /* package-private */ Field getRoot() {
          return root;
      }
  
+     private static final int TRUST_FINAL     = 0x0010;
+     private static final int NULL_RESTRICTED = 0x0020;
+ 
      /* package-private */ boolean isTrustedFinal() {
!         return (flags & TRUST_FINAL) == TRUST_FINAL;
+     }
+ 
+     /* package-private */ boolean isNullRestricted() {
+         return (flags & NULL_RESTRICTED) == NULL_RESTRICTED;
      }
  
      /**
       * {@inheritDoc}
       *
< prev index next >