Mandated/implicit parameters
Alex Buckley
alex.buckley at oracle.com
Tue May 24 15:52:33 UTC 2022
On 5/23/2022 11:27 PM, Hannes Greule wrote:
> I came across an oddity when using the Parameter#isImplicit()[1] method.
> According to its documentation, it returns true if the parameter is implicitly
> declared in source code. ...
> However, it seems like the information is only embedded when compiling
> with the -parameters flag.
>
> From my understanding of the given section in the JLS, the mandated flag
> should *always* be emitted. Is this a bug, or am I missing something?
In principle, the isImplicit() status of a parameter at run time should
not depend on whether -parameters was given at compile time.
Unfortunately, the class file bit that records "implicitly declared",
for use by isImplicit(), is located in the MethodParameters attribute
(JVMS 4.7.24) that is only emitted when -parameters is given.
It would be legitimate to emit MethodParameters without -parameters, so
as to record `final` and "implicitly declared" but not the parameter
name, but at some cost to implementation complexity in java.lang.reflect.
> Looking into it a bit deeper, it also seems like the parameters of a compact
> constructor for records are never marked as mandated, even when compiling with
> the -parameters flag (but the MethodParameters attribute is always written
> or record constructors).
That is weird, and sounds like a javac bug.
Alex
More information about the compiler-dev
mailing list