Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8310145

Remove final modifier from VarHandle::isAccessModeSupported

XMLWordPrintable

    • Icon: CSR CSR
    • Resolution: Approved
    • Icon: P3 P3
    • 21, 22
    • core-libs
    • None
    • source, binary
    • minimal
    • This method is declared in a sealed class that doesn't have any non-sealed subclass that users can extend, so it has no risk of clashing.
    • Java API
    • SE

      Summary

      Remove the final modifier from the method VarHandle::isAccessModeSupported to allow the implementation subclass to override and provide an alternative implementation.

      Problem

      VarHandle::isAccessModeSupported anticipates a VarHandle's VarForm to have implementation member names, which doesn't necessarily exist for non-direct VarHandle implementations. Thus IndirectVarHandle::isAccessModeSupported throws NullPointerException on its invocation.

      Solution

      Make VarHandle::isAccessModeSupported non-final to allow subclasses to override and provide a subclass-specific implementation.

      Specification

      @@ -2120,7 +2118,7 @@ public abstract sealed class VarHandle implements Constable
            * @return {@code true} if the given access mode is supported, otherwise
            * {@code false}.
            */
      -    public final boolean isAccessModeSupported(AccessMode accessMode) {
      +    public boolean isAccessModeSupported(AccessMode accessMode) {
               return vform.getMemberNameOrNull(accessMode.ordinal()) != null;
           }

            liach Chen Liang
            liach Chen Liang
            Mandy Chung (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: