CSR :
|
Summary ------- Emit the MethodParameters attribute in cases where parameter flags are required by the JLS. Problem ------- In Chapter 13.1, the JLS mentions cases in which a compiler must mark parameters as synthetic or mandated. In the classfile format, this information is stored in the MethodParameters attribute. Javac, however, only emits it when compiling with the -parameters flag. The change in the JLS was done with Java 8, but javac did not emit the information ever by default. The behavior can be observed by tooling (javap, tools reading class files) or by using the Parameter#isImplicit() and Parameter#isSynthetic() methods. Solution -------- The fix is to emit the MethodParameters attribute in the cases mentioned in the JLS. If the -parameters flag is not provided, only parameter flags are emitted. Specification ------------- If the -parameters flag is used, the behavior does not change. If the flag is not used, the compiler emits the attribute in cases mentioned in the JLS § 13.1, namely: 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).