RFR: 8292275: javac does not emit SYNTHETIC and MANDATED flags for parameters by default [v6]
Chen Liang
liach at openjdk.org
Wed Mar 15 18:47:35 UTC 2023
On Mon, 9 Jan 2023 07:34:41 GMT, Hannes Greule <duke at openjdk.org> wrote:
>> With this change, javac emits the MethodParameters attribute in cases where the JLS requires the information about synthetic and mandated parameters to be stored (see issue).
>> Parameter names are *not* emitted unless the `-parameter` flag is set.
>>
>> The relevant changes are in `ClassWriter`, where we go through the params to see if we need the attribute if the `-parameter` flag is not set (if it is set, both names and flags will be emitted).
>> For records, the mandated flag wasn't set at all, this is solved by the one line fix in `JavacParser`.
>>
>> The changes to `CreateSymbols` and `ClassReader` are needed as they weren't able to deal with missing names in the attribute.
>> I also had to update some tests as they got a new constant pool entry.
>>
>> Only the mandated flag is covered by tests at the moment, as the occurrences are well-specified in the JLS.
>> Please let me know if you want tests for specific appearances of synthetic parameters.
>
> Hannes Greule has updated the pull request with a new target base due to a merge or a rebase. The incremental webrev excludes the unrelated changes brought in by the merge/rebase. The pull request contains 21 additional commits since the last revision:
>
> - Update copyright year
> - Merge remote-tracking branch 'upstream/master' into fix/enforce-methodparam_attr-if-mandated
> - address comments
> - cleanup
> - add annotation processing test
> - fix line breaks
> - add access flag based test
> - remove spaces from empty lines in text block
> - add bug number to test
> - copyright
> - ... and 11 more: https://git.openjdk.org/jdk/compare/aed3ea90...43780935
Just checking on this. the CSR [has a response](https://bugs.openjdk.org/browse/JDK-8292467?focusedCommentId=14562384&page=com.atlassian.jira.plugin.system.issuetabpanels%3Acomment-tabpanel#comment-14562384):
> Please refine the discussion in "Solution" to explicitly state which --release/-target versions are intended to be impacted by the change. Presumably, at a minimum the synthetic and mandated information would only be written to class file formats where those bits are defined.
>
> A more conservative form of this change would be to only change the behavior for --release/-target 21. However, given the low expected impact of making the change, I'd expect it would be fine to make the change in behavior for all class file versions where that information is supported.
Our current implementation applies the change of behavior to all `--release/-target` versions. And as far as I see, `MethodParameters` attribute has been properly supported by the Reflection API to filter out synthetic and mandated parameters since 1c54a00f752a54a7a68b09d3df5d3a6081f4fcc8 (Java 8, when `MethodParameters` is introduced). So I suggest to move along by specifying that this change applies to all release/target versions, which will fix the reflection issue on all versions.
It ultimately depends on @SirYwell to decide what to do here. I can help you update the CSR's Solution Section as you desire, as I am eager to see this bug fixed on javac's end as well.
-------------
PR: https://git.openjdk.org/jdk/pull/9862
More information about the compiler-dev
mailing list