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

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

    XMLWordPrintable

    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 jdk12, so the fix should be merged into jdk11u, jdk12u, and head stream (jdk/jdk).

      http://cr.openjdk.java.net/~afarley/8216558/webrev/

        Attachments

          Issue Links

            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: