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

Lookup.unreflectSetter(Field) fails to throw IllegalAccessException for static final field

    Details

    • Type: Bug
    • Status: Open
    • Priority: P4
    • Resolution: Unresolved
    • Affects Version/s: 11
    • Fix Version/s: None
    • Component/s: core-libs
    • Labels:
      None
    • Environment:

      All platforms tested have seen this, including Windows, Linux, and MacOS.

      Description

      A setter MethodHandle for a final field seems counter intuitive, as final fields should not be able to be changed (whether they are accessible or not).

      However, this operation is currently allowed if you call f.setAccessible(true) before calling Lookup.unreflectSetter(Field), resulting in a valid MethodHandle being returned. Also, the MethodHandle can be utilized to set the value of the reflected final field.

      A testcase will be attached to this bug in short order, as well as the proposed fix.

      This issue is seen on jdk11, and the fix should be merged into jdk11 and head stream (jdk/jdk).

      Jdk12 too, if possible, though I'm told this might be locked down for the upcoming release.

        Attachments

          Activity

            People

            • Assignee:
              afarley Adam Farley
              Reporter:
              afarley Adam Farley
            • Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

              • Created:
                Updated: