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 isJDK-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.
"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
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.
- relates to
-
JDK-8280798 com.sun.jdi.ObjectReference::setValue spec should prohibit any final field modification
-
- Resolved
-