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

jshell tool: Add support for preview features



    • Type: CSR
    • Status: Closed
    • Priority: P3
    • Resolution: Approved
    • Fix Version/s: 11
    • Component/s: tools
    • Labels:
    • Subcomponent:
    • Compatibility Kind:
      source, binary, behavioral
    • Compatibility Risk:
    • 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:



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


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


      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.


      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


          Issue Links



              rfield Robert Field
              mtrudeau Michel Trudeau
              Reviewed By:
              Jonathan Gibbons
              0 Vote for this issue
              3 Start watching this issue