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

local records shouldn't capture any non-static state from any enclosing type

    XMLWordPrintable

    Details

    • Type: CSR
    • Status: Closed
    • Priority: P3
    • Resolution: Approved
    • Fix Version/s: 14
    • Component/s: tools
    • Labels:
    • Subcomponent:
    • Compatibility Risk:
      minimal
    • Compatibility Risk Description:
      Hide
      Records are a preview feature in Java SE 14. It is possible that incompatible changes will be made to records in a later Java SE release, before they become final and permanent, but chances are low as records are ultimately Java classes so they shouldn't be introducing any new disruptive feature that could pose a compatibility risk. It is also possible that records will be removed in a later Java SE release, without ever having become final and permanent. Given that records have just been released there shouldn't be too much user code affected by this change
      Show
      Records are a preview feature in Java SE 14. It is possible that incompatible changes will be made to records in a later Java SE release, before they become final and permanent, but chances are low as records are ultimately Java classes so they shouldn't be introducing any new disruptive feature that could pose a compatibility risk. It is also possible that records will be removed in a later Java SE release, without ever having become final and permanent. Given that records have just been released there shouldn't be too much user code affected by this change

      Description

      Summary

      Local records shouldn't capture any non-static state from theirs enclosing type. Both the spec and the implementation should be updated to enforce this.

      Problem

      Local records should not be allowed to capture any non-static state from any enclosing type

      Solution

      Fix the mentioned issue in the spec and the implementation

      Specification

      The following extra condition has been added to the definition of a local record [14.3]:

      It is a compile-time error if a local record contains a usage of a variable declared in the enclosing block.

      Following comments, the definition of a local record now reads as follows (The final sentence is new):

      A local record is a record type declaration (8.10) that is not a member of a class. A local record is implicitly static. A local record is not a local class.

      Example 14.3-1 has been clarified that it deals with local classes only.

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              vromero Vicente Arturo Romero Zaldivar
              Reporter:
              vromero Vicente Arturo Romero Zaldivar
              Reviewed By:
              Maurizio Cimadamore
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: