JDK-8177116 : Release Note: Compilers accept modification of final fields outside initializer methods
  • Type: Sub-task
  • Component: hotspot
  • Sub-Component: compiler
  • Affected Version: 7u171,8u152,9
  • Priority: P4
  • Status: Closed
  • Resolution: Delivered
  • Submitted: 2017-03-20
  • Updated: 2019-09-13
  • Resolved: 2017-03-21
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 7 JDK 8 JDK 9
7u171Resolved 8u152Resolved 9Resolved
Description
According to the Java VM Specification, final fields can be modified by the  `putfield` byte code instruction only if the instruction appears  in the instance initializer method `<init>` of the field's declaring class. Similar, static final fields can be modified by a `putstatic` instruction only if the instruction appears in the class initializer method `<clinit>` of the field's declaring class. With the JDK 9 release, the HotSpot VM fully enforces the previously mentioned restrictions, but only for class files with version number >= 53. For class files with version numbers < 53,  restrictions are only partially enforced (as it is done by releases preceding JDK 9). That is, for class files with version number < 53, final fields can be modified in any method of the class declaring the field (not only class/instance initializers).
Comments
Looks good!
21-03-2017

Hi Tobias, thank you for the feedback, I added special formatting (also for byte code instructions mentioned in the text). Zoltan
21-03-2017

Hi Zoltan, this looks good to me! Maybe put <init> and <clinit> in ` for different formatting in the generated text. Thanks, Tobias
21-03-2017