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

The JDWP spec and implementation need to be cleaned up w.r.t. the setting of class and instance final fields

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: P4 P4
    • None
    • 25
    • core-svc
    • None

      The JDWP spec says the following for ClassType.SetValues:

      "Access control is not enforced; for example, the values of private fields can be set. Final fields cannot be set."

      There are a few issues with this:

      1. The implementation does not currently enforce the ban on setting final fields. It simply calls out to JNI, which currently allows setting final fields.

      2. Future versions of JNI will call FatalError() if run with -Xcheck:jni and an attempt to set a final field (static or instance) is made.

      3. It is not consistent with ObjectReference.SetValues(), which has no verbiage that excludes the setting of final fields. However, it will also suffer the JNI FatalError() in the future when JNI is updated.

      Fortunately the only real client of JDWP is JDI, and it currently has checks that prevent the setting of final fields for both classes and instances, so debuggers that use an updated JDI should not run into JNI FatalError.

      Related to this CR is JDK-8280798, which was fix 2-3 years ago. It resolved a JDI spec issue. The spec allowed setting of instance final fields but not static final fields, although the implementation didn't allow either. The spec was brought in line with the implementation to prohibit the setting of both instance and static final fields. It is worth reading the CR and PR for more context. In particular the discussions around debuggers that don't use JDI from OpenJDK.

      The proper course of action here is probably to tighten up the JDWP spec to disallow the setting of any final field, which will bring it in line with the JDI spec, and fix the JDWP implementation to disallow the setting of any final field. However, at the moment this is not considered a high priority issue given that JDI already has the checks.

            Unassigned Unassigned
            cjplummer Chris Plummer
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: