RFR: 8292275: javac does not emit SYNTHETIC and MANDATED flags for parameters by default

Joe Darcy darcy at openjdk.org
Fri Aug 12 22:41:30 UTC 2022


On Fri, 12 Aug 2022 19:54:59 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.

src/jdk.compiler/share/classes/com/sun/tools/javac/parser/JavacParser.java line 4023:

> 4021:                         tmpParams.add(F.at(param)
> 4022:                                 // we will get flags plus annotations from the record component
> 4023:                                 .VarDef(F.Modifiers(Flags.PARAMETER | Flags.GENERATED_MEMBER | Flags.MANDATED | param.mods.flags & Flags.VARARGS,

Should the use of MANDATED be conditional on the target class file version?

test/langtools/tools/javac/RequiredParameterFlags/ImplicitParameters.java line 52:

> 50: import toolbox.ToolBox;
> 51: 
> 52: public class ImplicitParameters extends TestRunner {

In addition to this test, an annotation processing-based test could also be attempted here.

-------------

PR: https://git.openjdk.org/jdk/pull/9862



More information about the build-dev mailing list