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

jshell tool: Add support for preview features

    Details

    • Type: CSR
    • Status: Closed
    • Priority: P3
    • Resolution: Approved
    • Fix Version/s: 11
    • Component/s: tools
    • Labels:
    • Subcomponent:
    • Compatibility Kind:
      source, binary, behavioral
    • Compatibility Risk:
      minimal
    • Compatibility Risk Description:
      This is a new option of jshell. We do not expect compatibility risk associated with the change given that, if the --enable-preview flag is not enabled, jshell should behave exactly as before this change.
    • Interface Kind:
      add/remove/modify command line option
    • Scope:
      JDK

      Description

      Summary

      Update the jshell tool to support the use of "preview" features.

      Problem

      JEP 12 [1] describes JDK support for "preview" language and VM features.The jshell tool should support this as a documented flag.

      Solution

      JEP 12 [1] describes how the compiler, VM and related toolchain might support preview features. A preview feature is, as per JEP description "a new feature of the Java SE Platform that is fully specified, fully implemented, and yet impermanent". In the jshell tool, support for preview features is enabled via a new command-line option, namely --enable-preview. This option effectively unlocks a new source level in which all preview features defined for a given Java SE release are enabled.

      Specification

      As part of this change, we plan to add a new jshell command-line flag, namely --enable-preview.

      If the --enable-preview flag is present, jshell will pass the --enable-preview and -source N (or equivalent) options to javac (via the compiler API) when compiling any snippets, where N is the current language version. And pass on the --enable-preview option on to the JVM for snippet execution. As always, errors and warnings from the compiler and JVM are forwarded to the user. See CSRs for preview in javac and the JVM: JDK-8200312 and JDK-8200440.

      If the --enable-preview flag is not present, jshell should continue to behave normally - e.g. as if preview features did not exist. As a result, any reference to preview features, either direct (e.g. directly in entered snippets) or indirect (e.g. through dependency on external classfiles) should result in an error. To help the user, jshell where possible (via the compiler) will signal that a preview feature was found but no corresponding --enable-preview flag was supplied.

      This change does not alter any of the public JShell API or SPI: jdk.jshell, jdk.jshell.spi, jdk.jshell.execution, or jdk.jshell.tool. Though jdk.jshell.tool.JavaShellToolBuilder.run(String... arguments) will successfully take the new option (the options accepted are not specified in this method/interface/package).


      [1] http://openjdk.java.net/jeps/12

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                rfield Robert Field
                Reporter:
                mtrudeau Michel Trudeau
                Reviewed By:
                Jonathan Gibbons
              • Votes:
                0 Vote for this issue
                Watchers:
                3 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: