Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8292467

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

XMLWordPrintable

    • Icon: CSR CSR
    • Resolution: Approved
    • Icon: P4 P4
    • 21
    • tools
    • None
    • behavioral
    • low
    • some class file processors could detect additional, and unexpected, information in some cases. When inspected by Reflection API for all Java versions since 8, these executables will produce different, but correct, parameter information with correct flags.
    • Other

      Summary

      Javac is not marking method parameters as synthetic or mandated by default, when applicable, as mandated by the JLS in section 13.1. The compiler should be synchronized with the spec.

      Problem

      Javac is marking method parameters as synthetic or mandated only if the -parameters option is passed. The JLS states that a Java compiler should mark all method parameters as synthetic or mandated when applicable.

      Solution

      The proposed fix is to mark all method parameters as synthetic or mandated when applicable by emitting the MethodParameters attribute in the class file. This applies to all release / target versions since 8, when the MethodParameters attribute was added.

      Specification

      The related specification section is JLS 18 § 13.1, in particular:

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

            liach Chen Liang
            webbuggrp Webbug Group
            Vicente Arturo Romero Zaldivar
            Votes:
            1 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: