JDK-8221937 : JShell: Crash on the instantiation of an anonymous class
  • Type: Bug
  • Component: tools
  • Sub-Component: jshell
  • Affected Version: 11,12
  • Priority: P3
  • Status: Resolved
  • Resolution: Duplicate
  • Submitted: 2019-04-03
  • Updated: 2019-05-23
  • Resolved: 2019-05-23
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 13
13Resolved
Related Reports
Duplicate :  
Description
Here are three pairs of instantiations, each pair involving a normal class and an anonymous subclass. In the third pair, instantiating the anonymous subclass crashes JShell, presumably because instantiating the normal class is forbidden.

|  Welcome to JShell -- Version 12
|  For an introduction type: /help intro

jshell> new Object()
$1 ==> java.lang.Object@457e2f02

jshell> new Object() {}
$2 ==> $0@724af044

jshell> new File("bob")
$3 ==> bob

jshell> new File("bob") {}
$4 ==> bob

jshell> new PrintStream("bob")
|  Exception java.io.FileNotFoundException: bob (Access is denied)
|        at FileOutputStream.open0 (Native Method)
|        at FileOutputStream.open (FileOutputStream.java:292)
|        at FileOutputStream.<init> (FileOutputStream.java:235)
|        at FileOutputStream.<init> (FileOutputStream.java:124)
|        at PrintStream.<init> (PrintStream.java:226)
|        at (#5:1)

jshell> new PrintStream("bob") {}
|  Error:
Exception in thread "main" java.lang.StringIndexOutOfBoundsException: begin 0, end -2, length 25
        at java.base/java.lang.String.checkBoundsBeginEnd(String.java:3410)
        at java.base/java.lang.String.substring(String.java:1883)
        at jdk.jshell/jdk.internal.jshell.tool.JShellTool.displayableDiagnostic(JShellTool.java:3516)
        at jdk.jshell/jdk.internal.jshell.tool.JShellTool.displayDiagnostics(JShellTool.java:3479)
        at jdk.jshell/jdk.internal.jshell.tool.JShellTool.handleEvent(JShellTool.java:3585)
        at jdk.jshell/jdk.internal.jshell.tool.JShellTool.processSource(JShellTool.java:3557)
        at jdk.jshell/jdk.internal.jshell.tool.JShellTool.processSourceCatchingReset(JShellTool.java:1305)
        at jdk.jshell/jdk.internal.jshell.tool.JShellTool.processInput(JShellTool.java:1203)
        at jdk.jshell/jdk.internal.jshell.tool.JShellTool.run(JShellTool.java:1176)
        at jdk.jshell/jdk.internal.jshell.tool.JShellTool.start(JShellTool.java:975)
        at jdk.jshell/jdk.internal.jshell.tool.JShellToolBuilder.start(JShellToolBuilder.java:254)
        at jdk.jshell/jdk.internal.jshell.tool.JShellToolProvider.main(JShellToolProvider.java:120)
Comments
Underlying cause duplicate of JDK-8223688
23-05-2019