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

javac should reject class files with bad EnclosingMethod attributes

    Details

    • Type: CSR
    • Status: Closed
    • Priority: P4
    • Resolution: Approved
    • Fix Version/s: 13
    • Component/s: tools
    • Labels:
      None
    • Subcomponent:
    • Compatibility Kind:
      behavioral
    • Compatibility Risk:
      minimal
    • Compatibility Risk Description:
      Hide
      Only `class` files that represent anonymous or local classes have the `EnclosingMethod` attribute, and it is not possible to refer to these classes from other source files. Also, these classes are not usually visible through the `javax.lang.model` API. Therefore, the impact of rejecting `class` files with bad `EnclosingMethod` attributes should be very limited.
      Show
      Only `class` files that represent anonymous or local classes have the `EnclosingMethod` attribute, and it is not possible to refer to these classes from other source files. Also, these classes are not usually visible through the `javax.lang.model` API. Therefore, the impact of rejecting `class` files with bad `EnclosingMethod` attributes should be very limited.
    • Interface Kind:
      Other

      Description

      Summary

      javac will reject class files with bad EnclosingMethod attributes.

      Problem

      A class file may have an EnclosingMethod attribute that is syntactically well-formed (according to the JVM's class file format checking) but semantically ill-formed (according to the rules of the Java language). This may cause a Java compiler to crash. A notable instance of this problem is when EnclosingMethod specifies an enclosing class that could not have enclosed the current class in Java source code. That is, in a class file for a local/anonymous class A, EnclosingMethod specifies that the enclosing class is C, but the binary name of C is not a prefix of the binary name of A.

      Solution

      The EnclosingMethod attribute is defined by JVMS 4.7.7 to record the class (and method) that enclosed the source declaration of the current class, which was local/anonymous. The rules in JLS 13.1 indicate that a local/anonymous class has a binary name which is an extension of the binary name of its enclosing class. Accordingly, if the EnclosingMethod attribute is present in the current class file, then its class_index item should specify a binary name for the enclosing class which is a prefix of the binary name of the current class. If class_index does not follow this pattern, then the attribute is not semantically well-formed, and Java compilers should reject the class file.

      Specification

      javac will check if the binary name specified by class_index in EnclosingMethod is a prefix of the binary name of the class file that contains EnclosingMethod. If not, then javac will refuse to load the class file.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                jlahoda Jan Lahoda
                Reporter:
                webbuggrp Webbug Group
                Reviewed By:
                Alex Buckley
              • Votes:
                0 Vote for this issue
                Watchers:
                1 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: