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

com.sun.jdi.ObjectReference::setValue spec should prohibit any final field modification

    XMLWordPrintable

Details

    • CSR
    • Resolution: Approved
    • P4
    • 20
    • core-svc
    • None
    • minimal
    • Hide
      The JDK implementation has never allowed changing the value of instance final fields, so there is no behavior change.

      IntelliJ maintains their own fork of JDI but they don't allow final fields to be changed.

      The JDI implementation in the Eclipse JDT project (used by Eclipse and VS Code) does allow final instance fields to be changed with this method. The VS Code debugger does not allow users to change final fields so ObjectReference.setValue is never called for a final field. The Eclipse IDE are reported to be on board with the change.
      Show
      The JDK implementation has never allowed changing the value of instance final fields, so there is no behavior change. IntelliJ maintains their own fork of JDI but they don't allow final fields to be changed. The JDI implementation in the Eclipse JDT project (used by Eclipse and VS Code) does allow final instance fields to be changed with this method. The VS Code debugger does not allow users to change final fields so ObjectReference.setValue is never called for a final field. The Eclipse IDE are reported to be on board with the change.
    • Java API
    • JDK

    Description

      Summary

      Change com.sun.jdi.ObjectReference.setValue to specify that it cannot be used to change final instance fields, and align it with long standing implementation behavior.

      Problem

      ObjectReference.setValue spec says:

      Sets the value of a given instance or static field in this object. The Field must be
      valid for this ObjectReference; that is, it must be from the mirrored object's class
      or a superclass of that class. If static, the field must not be final.

      The JDK's JDI implementation has never allowed a final field (static or instance) be changed. The current behavior, and spec vs. implementation difference, goes back to 1999.

      Solution

      Changes the description ObjectReference.setValue to specify that the method cannot be used to change final fields.

      Change the description of the IllegalArgumentException to include the condition that the field is final.

      Specification

      old:

      /**
       * Sets the value of a given instance or static field in this object.
       * The {@link Field} must be valid for this ObjectReference; that is,
       * it must be from the mirrored object's class or a superclass of that class.
       * If static, the field must not be final.
       * <p>
       ...
       * @throws java.lang.IllegalArgumentException if the field is not valid for
       * this object's class.
       ...
       */
      void setValue(Field field, Value value)

      new:

      /**
       * Sets the value of a given instance or static field in this object.
       * The {@link Field} must be valid for this ObjectReference; that is,
       * it must be from the mirrored object's class or a superclass of that class.
       * The field must not be final.
       * <p>
       ...
       * @throws java.lang.IllegalArgumentException if the field is not valid for
       * this object's class or the field is final.
       ...
       */
      void setValue(Field field, Value value)

      Attachments

        Issue Links

          Activity

            People

              amenkov Alex Menkov
              amenkov Alex Menkov
              Chris Plummer
              Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: