[nestmates] JDK-8235602: Re-examine if a hidden class should trust final non static fields

Paul Sandoz paul.sandoz at oracle.com
Thu Jan 30 19:12:29 UTC 2020


> On Jan 30, 2020, at 10:33 AM, Mandy Chung <mandy.chung at oracle.com> wrote:
> 
> Hi Paul,
> 
> I tweak Field::set a little to define "write access" which will be
> mentioned from Field::setXXX @throws (I missed to change @throw in
> the previous patch).
> 
> 
> diff --git a/src/java.base/share/classes/java/lang/reflect/Field.java b/src/java.base/share/classes/java/lang/reflect/Field.java
> --- a/src/java.base/share/classes/java/lang/reflect/Field.java
> +++ b/src/java.base/share/classes/java/lang/reflect/Field.java
> @@ -721,10 +721,19 @@
>       * the underlying field is inaccessible, the method throws an
>       * {@code IllegalAccessException}.
>       *
> -     * <p>If the underlying field is final, the method throws an
> -     * {@code IllegalAccessException} unless {@code setAccessible(true)}
> -     * has succeeded for this {@code Field} object
> -     * and the field is non-static. Setting a final field in this way
> +     * <p>If the underlying field is final, this {@code Field} object has
> +     * <em>write</em> access if and only if the following conditions are met:
> +     * <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#isHiddenClass() hidden}
> +     *     class.</li>
> +     * </ul>
> +     * If any of the above checks is {@code false}, this method throws an
> +     * {@code IllegalAccessException}.
> +     *
Minor proposed tweak (keeping consistent with prior text):

  If any of the above conditions are not met, the method throws ….

Paul.
> +     * <p> Setting a final field in this way
>       * is meaningful only during deserialization or reconstruction of
>       * instances of classes with blank final fields, before they are
>       * made available for access by other parts of a program. Use in
> @@ -756,7 +765,8 @@
>       *
>       * @throws    IllegalAccessException    if this {@code Field} object
>       *              is enforcing Java language access control and the underlying
> -     *              field is either inaccessible or final.
> +     *              field is inaccessible or final;
> +     *              or if this {@code Field} object has no write access.
> 
> 
> The above change to @throws IAE also applies to other Field::setXXX methods.
> 
> Mandy



More information about the valhalla-dev mailing list