JDK-8223688 : JShell: crash on the instantiation of raw anonymous class
  • Type: Bug
  • Component: tools
  • Sub-Component: jshell
  • Affected Version: 11,12,13
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2019-05-10
  • Updated: 2020-12-11
  • Resolved: 2019-06-01
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 11 JDK 13 JDK 14
11.0.11-oracleFixed 13 b24Fixed 14Fixed
Related Reports
Duplicate :  
Description
ADDITIONAL SYSTEM INFORMATION :
$ jshell --version
jshell 11.0.2
$ java --version
openjdk 11.0.2 2019-01-15
OpenJDK Runtime Environment 18.9 (build 11.0.2+9)
OpenJDK 64-Bit Server VM 18.9 (build 11.0.2+9, mixed mode)
$javac --version
javac 11.0.2
$ uname -a
Darwin <REDACTED> 18.5.0 Darwin Kernel Version 18.5.0: Mon Mar 11 20:40:32 PDT 2019; root:xnu-4903.251.3~3/RELEASE_X86_64 x86_64

A DESCRIPTION OF THE PROBLEM :
JShell crashes when the user tries to instantiate a generic anonymous class without using type parameters if the type parameter is a formal parameter of the chosen constructor. This bug is reminiscent of JDK-8221937 but presents a new failure case.

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
$ jshell
|  Welcome to JShell -- Version 11.0.2
|  For an introduction type: /help intro

jshell> abstract class A {}
|  created class A

jshell> new A() {}
$2 ==> $0@7f9a81e8

jshell> abstract class A<T> {}
|  modified class A

jshell> new A() {}
$4 ==> $1@735b5592

jshell> abstract class A<T> { A(T t){} }
|  replaced class A

jshell> new A<String>("") {}
$6 ==> $2@d2cc05a

jshell> new A("") {}
|  Warning:
Exception in thread "main" java.lang.StringIndexOutOfBoundsException: begin 0, end -2, length 12
	at java.base/java.lang.String.checkBoundsBeginEnd(String.java:3319)
	at java.base/java.lang.String.substring(String.java:1874)
	at jdk.jshell/jdk.internal.jshell.tool.JShellTool.displayableDiagnostic(JShellTool.java:3509)
	at jdk.jshell/jdk.internal.jshell.tool.JShellTool.displayDiagnostics(JShellTool.java:3472)
	at jdk.jshell/jdk.internal.jshell.tool.JShellTool.handleEvent(JShellTool.java:3578)
	at jdk.jshell/jdk.internal.jshell.tool.JShellTool.processSource(JShellTool.java:3550)
	at jdk.jshell/jdk.internal.jshell.tool.JShellTool.processSourceCatchingReset(JShellTool.java:1301)
	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)

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Creation and instantiation of an anonymous subclass of A

OR

A warning explaining that this is an unchecked calls (e.g. warning: [unchecked] unchecked call to A(T) as a member of the raw type A)
ACTUAL -
JShell crashes

---------- BEGIN SOURCE ----------
See above. Note that failure persists even if class A is not abstract.
---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
None known

FREQUENCY : always



Comments
Fix Request (11u) This fixes a jshell regression in 11u. Patch applies to 11u cleanly after JDK-8211694, new test fails without the patch, passes with it. Additional tier{1,2} and jdk/jshell tests pass.
04-08-2020

Out for review -- RFR 8223688: JShell: crash on the instantiation of raw anonymous class Please review: Bug: https://bugs.openjdk.java.net/browse/JDK-8223688 Webrev: http://cr.openjdk.java.net/~rfield/8223688.webrev01/ Thanks, Robert
21-05-2019

Simple steps to reproduce the issue == -sh-4.1$ /scratch/fairoz/JAVA/jdk11/jdk-11-ea+01/bin/jshell | Welcome to JShell -- Version 11 | For an introduction type: /help intro jshell> abstract class A<T> { A(T t){} } | created class A jshell> new A("") {} | Warning: Exception in thread "main" java.lang.StringIndexOutOfBoundsException: begin 0, end -2, length 13 == This is a regression starting from 11 ea b01. 10.0.2 - Pass 11 ea b01 - Fail <= regression started from here 11 GA - Fail 12 Ga - Fail 13 ea b19 - Fail This issue is most likely caused by JDK-8191842
10-05-2019

This issue is reproducible in 13 ea b19 also == -sh-4.1$ /scratch/fairoz/JAVA/jdk13/jdk-13-ea+19/bin/jshell | Welcome to JShell -- Version 13-ea | For an introduction type: /help intro jshell> abstract class A {} | created class A jshell> new A() {} $2 ==> $0@7daf6ecc jshell> abstract class A<T> {} | modified class A jshell> new A() {} $4 ==> $1@31221be2 jshell> abstract class A<T> { A(T t){} } | replaced class A jshell> new A<String>("") {} $6 ==> $2@5910e440 jshell> new A("") {} | Warning: Exception in thread "main" java.lang.StringIndexOutOfBoundsException: begin 0, end -2, length 12 at java.base/java.lang.String.checkBoundsBeginEnd(String.java:3422) at java.base/java.lang.String.substring(String.java:1908) 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)
10-05-2019