JDK-8201220 : jshell tool: Add support for preview features
  • Type: CSR
  • Component: tools
  • Sub-Component: jshell
  • Priority: P3
  • Status: Closed
  • Resolution: Approved
  • Fix Versions: 11
  • Submitted: 2018-04-05
  • Updated: 2018-04-09
  • Resolved: 2018-04-09
Related Reports
CSR :  
Relates :  
Relates :  
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


Comments
Moving to Approved.
09-04-2018

Joe, in that entered snippets are executed immediately in the current JVM, the target and release flags aren't appropriate. A source flag could theoretically be added but it is somewhat counter to the concept of JShell, there has never been a request for it, and it could be achieved with the -C flag. As described in the updated Description, the source and release flags will be implicitly passed to javac.
07-04-2018

Moving to Provisional.
06-04-2018