Details
-
Sub-task
-
Resolution: Delivered
-
P4
-
21
Description
Prior to JDK 21, the `javac` compiler did not always mark method parameters as `synthetic` or `mandated` when applicable. Starting with JDK 21, the `javac` compiler emits the `MethodParameters` attribute in the class file when applicable. This attribute stores information on whether or not parameters are `synthetic` or `mandated`. This change applies to all release and target versions supported by `javac` since all currently supported releases and targets have the `MethodParameters` attribute defined.
This change is justified by JLS § 13.1, in particular:
A binary representation for a class or interface must also contain all of the following:
[...]
11. A construct emitted by a Java compiler must be marked as synthetic if it does not
correspond to a construct declared explicitly or implicitly in source code, unless
the emitted construct is a class initialization method (JVMS §2.9).
12. A construct emitted by a Java compiler must be marked as mandated if it corresponds
to a formal parameter declared implicitly in source code (§8.8.1, §8.8.9, §8.9.3,
§15.9.5.1).
This change is justified by JLS § 13.1, in particular:
A binary representation for a class or interface must also contain all of the following:
[...]
11. A construct emitted by a Java compiler must be marked as synthetic if it does not
correspond to a construct declared explicitly or implicitly in source code, unless
the emitted construct is a class initialization method (JVMS §2.9).
12. A construct emitted by a Java compiler must be marked as mandated if it corresponds
to a formal parameter declared implicitly in source code (§8.8.1, §8.8.9, §8.9.3,
§15.9.5.1).