Mandated/implicit parameters

Hannes Greule hannesgreule at outlook.de
Tue May 24 06:27:53 UTC 2022


Hi,
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. The JLS 13.1 point 12[2] says "A construct emitted by
a Java compiler must be marked as *mandated* if it corresponds to a formal
parameter declared implicitly in source code" with a list of such parameters.
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?

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).

I collected some code and outputs here[3] to show the differences between
compiling with and without the -parameters flag for cases that shouldn't
be different from my understanding.

If those two observations are bugs, I'd like to try contributing fixes for
them (I already spent a fair amount of time on it). As I did not contribute
to the JDK before, I'd probably need some assistance. I got two experimental
fixes for each of the problems here[4][5].

Greetings
Hannes

[1] https://docs.oracle.com/en/java/javase/18/docs/api/java.base/java/lang/reflect/Parameter.html#isImplicit()
[2] https://docs.oracle.com/javase/specs/jls/se18/html/jls-13.html#jls-13.1
[3] https://gist.github.com/SirYwell/33995f369608634f183419362ef3c828
[4] https://github.com/SirYwell/jdk/commit/5b71f4f144267757c645a41897142a395640af91
[5] https://github.com/SirYwell/jdk/commit/d06395bceb4b84afdb046db451f1e0b15da9f5a7


More information about the compiler-dev mailing list