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

VM support for sealed classes

    XMLWordPrintable

    Details

    • Subcomponent:
    • Compatibility Kind:
      behavioral
    • Compatibility Risk:
      minimal
    • Compatibility Risk Description:
      Hide
      The addition of the feature does not by itself bring a compatibility risk.

      Sealed classes are a preview feature in Java SE 15. It is possible that incompatible changes will be made to sealed classes in a later Java SE release, before they become final and permanent. It is also possible that sealed classes will be removed in a later Java SE release, without ever having become final and permanent.
      Show
      The addition of the feature does not by itself bring a compatibility risk. Sealed classes are a preview feature in Java SE 15. It is possible that incompatible changes will be made to sealed classes in a later Java SE release, before they become final and permanent. It is also possible that sealed classes will be removed in a later Java SE release, without ever having become final and permanent.
    • Interface Kind:
      Class file construct
    • Scope:
      SE

      Description

      Summary

      Introduce a PermittedSubclasses attribute in the class file format, so that the JVM can implement the sub-classing semantics of sealed classes.

      Problem

      Sealed classes (JEP 360) are a preview feature of Java SE 15. The JVM will need to enforce the sub-classing semantics of sealed classes.

      Solution

      A PermittedSubclasses attribute will be defined in the ClassFile format, containing information about which classes can extend or implement the class or interface containing the attribute. The JVM will use the attribute's contents to ensure that only those classes and interfaces named in the PermittedSubclasses attribute can extend or implement that class. Additionally, the extending (or implementing) class must have the same class loader and be in the same module as its sealed super class.

      The format of the PermittedSubclasses attribute is checked even if no classes or interfaces are loaded that extend or implement the class. The checking is done at class load time, and is similar to format checking of attributes such as NestMembers. For example, the JVM checks that the attribute's constant pool indexes are valid and that the PermittedSubclasses attribute occurs at most once per-class.

      Note that the PermittedSubclasses attribute could potentially be useful in other ways, for example, in determining if a class or interface is a sealed class.

      Specification

      Java Virtual Machine Spec changes for the PermittedSubclasses attribute are attached. Please note that JVM Spec section 5.3 is still under review by the expert group, and may change.

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              hseigel Harold Seigel
              Reporter:
              vromero Vicente Arturo Romero Zaldivar
              Reviewed By:
              Vicente Arturo Romero Zaldivar
              Votes:
              0 Vote for this issue
              Watchers:
              7 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: