JDK-8299680 : System.console() shouldn't return null in jshell
  • Type: CSR
  • Component: tools
  • Sub-Component: jshell
  • Priority: P4
  • Status: Draft
  • Resolution: Unresolved
  • Fix Versions: 21
  • Submitted: 2023-01-05
  • Updated: 2023-01-06
Related Reports
CSR :  
Description
Summary
-------

An enhancement to the JShell API to support use of `System.console()` inside the snippets is proposed.

Problem
-------

Currently, when a JShell snippet uses `System.console()`, the returned value is `null`.

Solution
--------

The JShell API is enhanced to allow to specify a console wrapper for the snippet execution. Then, when a snippet runs, `System.console()` may return a non-null value, and invoking methods on this value will rely the data to the specified console wrapper and back.

Not all JShell backends and configurations will support `System.console()`. Specifically, JShell will only support `System.console()` when it will use a remote agent, and the remote agent will support the console. This is the default when running JShell on the command line.

Specification
-------------

The proposed API changes are attached as specdiff.00.zip and are also available for convenience here:
http://cr.openjdk.java.net/~jlahoda/8296454/specdiff.00/overview-summary.html