From 5ff5797abed4aa68b22d96a95551e8ee197221b8 Mon Sep 17 00:00:00 2001 From: liach Date: Wed, 30 Oct 2024 04:59:26 -0500 Subject: [PATCH] Missed field --- .../classes/java/lang/reflect/Field.java | 34 +++++++------------ 1 file changed, 13 insertions(+), 21 deletions(-) diff --git a/src/java.base/share/classes/java/lang/reflect/Field.java b/src/java.base/share/classes/java/lang/reflect/Field.java index b2fcef8ddeb26..5d0fe76a99a08 100644 --- a/src/java.base/share/classes/java/lang/reflect/Field.java +++ b/src/java.base/share/classes/java/lang/reflect/Field.java @@ -76,22 +76,18 @@ class Field extends AccessibleObject implements Member { 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; - // Cached field accessor created without override - @Stable - private FieldAccessor fieldAccessor; - // Cached field accessor created with override - @Stable - private FieldAccessor overrideFieldAccessor; - // For sharing of FieldAccessors. This branching structure is - // currently only two levels deep (i.e., one root Field and - // potentially many Field objects pointing to it.) - // - // If this branching structure would ever contain cycles, deadlocks can - // occur in annotation code. - private Field root; + + /** + * Fields are mutable due to {@link AccessibleObject#setAccessible(boolean)}. + * Thus, we return a new copy of a root each time a field is returned. + * Some lazily initialized immutable states can be stored on root and shared to the copies. + */ + private Field root; + private transient volatile FieldRepository genericInfo; + private @Stable FieldAccessor fieldAccessor; // access control enabled + private @Stable FieldAccessor overrideFieldAccessor; // access control suppressed + // End shared states // Generics infrastructure @@ -107,22 +103,18 @@ private GenericsFactory getFactory() { // Accessor for generic info repository private FieldRepository getGenericInfo() { var genericInfo = this.genericInfo; - // lazily initialize repository if necessary if (genericInfo == null) { var root = this.root; if (root != null) { genericInfo = root.getGenericInfo(); } else { - // create and cache generic info repository - genericInfo = FieldRepository.make(getGenericSignature(), - getFactory()); + genericInfo = FieldRepository.make(getGenericSignature(), getFactory()); } this.genericInfo = genericInfo; } - return genericInfo; //return cached repository + return genericInfo; } - /** * Package-private constructor */