< prev index next >

src/java.base/share/classes/java/lang/invoke/MethodHandles.java

Print this page
@@ -3443,10 +3443,15 @@
                  if (field.isTrustedFinalField()) {
                      String msg = field.isStatic() ? "static final field has no write access"
                                                    : "final field has no write access";
                      throw field.makeAccessException(msg, this);
                  }
+                 // strictly-initialized finals not trusted finals at this time
+                 if (field.isStrictInit()) {
+                     throw field.makeAccessException("strictly-initialized final field has no write access", this);
+                 }
+ 
                  // check if write access to final field allowed
                  if (!field.isStatic() && isAccessible) {
                      SharedSecrets.getJavaLangReflectAccess().checkAllowedToUnreflectFinalSetter(lookupClass, f);
                  }
              }

@@ -3959,11 +3964,11 @@
                      throw getField.makeAccessException("caller class must be a subclass below the method", lookupClass());
                  }
                  refc = lookupClass();
              }
              return VarHandles.makeFieldHandle(getField, refc,
-                                               this.allowedModes == TRUSTED && !getField.isTrustedFinalField());
+                                               this.allowedModes == TRUSTED);
          }
          /** Check access and get the requested constructor. */
          private MethodHandle getDirectConstructor(Class<?> refc, MemberName ctor) throws IllegalAccessException {
              return getDirectConstructorCommon(refc, ctor);
          }
< prev index next >