JDK-8273039 : JShell crashes when naming variable or method "abstract" or "strictfp"
  • Type: Bug
  • Component: tools
  • Sub-Component: jshell
  • Affected Version: 16,17,18
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2021-08-26
  • Updated: 2021-11-25
  • Resolved: 2021-11-19
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 18
18 b25Fixed
Related Reports
Relates :  
Description
ADDITIONAL SYSTEM INFORMATION :
Tested with the JShells of the following JDK versions on Windows 10 Pro 20H2 (build 19042.1165):
working in OpenJDK 64-Bit Server VM AdoptOpenJDK (build 15.0.2+7, mixed mode, sharing)
crashing in OpenJDK 64-Bit Server VM Temurin-16.0.2+7 (build 16.0.2+7, mixed mode, sharing)
crashing in OpenJDK 64-Bit Server VM (build 17+35-2724, mixed mode, sharing)
crashing in OpenJDK 64-Bit Server VM (build 18-ea+11-557, mixed mode, sharing)

A DESCRIPTION OF THE PROBLEM :
In the JShell when naming a variable or method "abstract" or "strictfp", the JShell crashes with an InternalError. This happens since JDK 16 and also in latest JDK 17 and JDK 18. In JDK 9 until JDK 15 a normal error message is shown that "abstract" is nonsense in this place.
Bug was possibly introduced by implementation of https://bugs.java.com/bugdatabase/view_bug.do?bug_id=8247456

REGRESSION : Last worked in version 15

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Open /path/to/jdk/bin/jshell.exe
jshell> int abstract = 1;
or
jshell> int strictfp = 1;

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
JDK 15:
jshell> int abstract = 1;
|  Error:
|  '.class' expected
|  int abstract = 1;
|      ^
|  Error:
|  class, interface, or enum expected
|  int abstract = 1;
|      ^-------^
|  Error:
|  unexpected type
|    required: value
|    found:    class
|  int abstract = 1;
|  ^--^
ACTUAL -
JShell crashes with the following StackTrace (JDK 18, line numbers differ in other versions):
Exception in thread "main" java.lang.InternalError: Exception during analyze - java.lang.AssertionError
        at jdk.jshell/jdk.jshell.TaskFactory$AnalyzeTask.analyze(TaskFactory.java:393)
        at jdk.jshell/jdk.jshell.TaskFactory$AnalyzeTask.<init>(TaskFactory.java:384)
        at jdk.jshell/jdk.jshell.TaskFactory.lambda$analyze$1(TaskFactory.java:177)
        at jdk.jshell/jdk.jshell.TaskFactory.lambda$runTask$4(TaskFactory.java:212)
        at jdk.compiler/com.sun.tools.javac.api.JavacTaskPool.getTask(JavacTaskPool.java:193)
        at jdk.jshell/jdk.jshell.TaskFactory.runTask(TaskFactory.java:205)
        at jdk.jshell/jdk.jshell.TaskFactory.analyze(TaskFactory.java:174)
        at jdk.jshell/jdk.jshell.TaskFactory.analyze(TaskFactory.java:160)
        at jdk.jshell/jdk.jshell.TaskFactory.analyze(TaskFactory.java:149)
        at jdk.jshell/jdk.jshell.ExpressionToTypeInfo.expressionInfo(ExpressionToTypeInfo.java:239)
        at jdk.jshell/jdk.jshell.Eval.processExpression(Eval.java:604)
        at jdk.jshell/jdk.jshell.Eval.lambda$sourceToSnippets$1(Eval.java:220)
        at jdk.jshell/jdk.jshell.TaskFactory.lambda$parse$6(TaskFactory.java:254)
        at jdk.jshell/jdk.jshell.TaskFactory.lambda$runTask$4(TaskFactory.java:212)
        at jdk.compiler/com.sun.tools.javac.api.JavacTaskPool.getTask(JavacTaskPool.java:193)
        at jdk.jshell/jdk.jshell.TaskFactory.runTask(TaskFactory.java:205)
        at jdk.jshell/jdk.jshell.TaskFactory.parse(TaskFactory.java:139)
        at jdk.jshell/jdk.jshell.TaskFactory.parse(TaskFactory.java:239)
        at jdk.jshell/jdk.jshell.Eval.sourceToSnippets(Eval.java:194)
        at jdk.jshell/jdk.jshell.Eval.eval(Eval.java:130)
        at jdk.jshell/jdk.jshell.JShell.eval(JShell.java:493)
        at jdk.jshell/jdk.internal.jshell.tool.JShellTool.processSource(JShellTool.java:3618)
        at jdk.jshell/jdk.internal.jshell.tool.JShellTool.processSourceCatchingReset(JShellTool.java:1342)
        at jdk.jshell/jdk.internal.jshell.tool.JShellTool.processInput(JShellTool.java:1240)
        at jdk.jshell/jdk.internal.jshell.tool.JShellTool.run(JShellTool.java:1211)
        at jdk.jshell/jdk.internal.jshell.tool.JShellTool.start(JShellTool.java:995)
        at jdk.jshell/jdk.internal.jshell.tool.JShellToolBuilder.start(JShellToolBuilder.java:261)
        at jdk.jshell/jdk.internal.jshell.tool.JShellToolProvider.main(JShellToolProvider.java:120)
Caused by: java.lang.IllegalStateException: java.lang.AssertionError
        at jdk.compiler/com.sun.tools.javac.api.JavacTaskImpl.analyze(JavacTaskImpl.java:383)
        at jdk.jshell/jdk.jshell.TaskFactory$AnalyzeTask.analyze(TaskFactory.java:390)
        ... 27 more
Caused by: java.lang.AssertionError
        at jdk.compiler/com.sun.tools.javac.comp.Attr.visitTree(Attr.java:5128)
        at jdk.compiler/com.sun.tools.javac.tree.JCTree$Visitor.visitModifiers(JCTree.java:3462)
        at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCModifiers.accept(JCTree.java:2937)
        at jdk.compiler/com.sun.tools.javac.comp.Attr.attribTree(Attr.java:674)
        at jdk.compiler/com.sun.tools.javac.comp.Attr.visitErroneous(Attr.java:5120)
        at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCErroneous.accept(JCTree.java:3256)
        at jdk.compiler/com.sun.tools.javac.comp.Attr.attribTree(Attr.java:674)
        at jdk.compiler/com.sun.tools.javac.comp.Attr.attribExpr(Attr.java:727)
        at jdk.compiler/com.sun.tools.javac.comp.Attr.visitExec(Attr.java:2272)
        at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCExpressionStatement.accept(JCTree.java:1584)
        at jdk.compiler/com.sun.tools.javac.comp.Attr.attribTree(Attr.java:674)
        at jdk.compiler/com.sun.tools.javac.comp.Attr.attribStat(Attr.java:748)
        at jdk.compiler/com.sun.tools.javac.comp.Attr.attribStats(Attr.java:767)
        at jdk.compiler/com.sun.tools.javac.comp.Attr.visitBlock(Attr.java:1445)
        at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCBlock.accept(JCTree.java:1091)
        at jdk.compiler/com.sun.tools.javac.comp.Attr.attribTree(Attr.java:674)
        at jdk.compiler/com.sun.tools.javac.comp.Attr.attribStat(Attr.java:748)
        at jdk.compiler/com.sun.tools.javac.comp.Attr.visitMethodDef(Attr.java:1235)
        at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCMethodDecl.accept(JCTree.java:921)
        at jdk.compiler/com.sun.tools.javac.comp.Attr.attribTree(Attr.java:674)
        at jdk.compiler/com.sun.tools.javac.comp.Attr.attribStat(Attr.java:748)
        at jdk.compiler/com.sun.tools.javac.comp.Attr.attribClassBody(Attr.java:5479)
        at jdk.compiler/com.sun.tools.javac.comp.Attr.attribClass(Attr.java:5370)
        at jdk.compiler/com.sun.tools.javac.comp.Attr.attribClass(Attr.java:5201)
        at jdk.compiler/com.sun.tools.javac.comp.Attr.attrib(Attr.java:5146)
        at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.attribute(JavaCompiler.java:1317)
        at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.attribute(JavaCompiler.java:1290)
        at jdk.compiler/com.sun.tools.javac.api.JavacTaskImpl.analyze(JavacTaskImpl.java:404)
        at jdk.compiler/com.sun.tools.javac.api.JavacTaskImpl.lambda$analyze$1(JavacTaskImpl.java:379)
        at jdk.compiler/com.sun.tools.javac.api.JavacTaskImpl.invocationHelper(JavacTaskImpl.java:152)
        at jdk.compiler/com.sun.tools.javac.api.JavacTaskImpl.analyze(JavacTaskImpl.java:379)
        ... 28 more

---------- BEGIN SOURCE ----------
Shortest code in JShell:
int abstract<RETURN>
---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
Don't write invalid Java code.
"abstract" and "strictfp" give this result. Other keywords and modifiers "work" as expected (as they are giving a normal error message).

FREQUENCY : always



Comments
Changeset: 2f20b0d8 Author: Jan Lahoda <jlahoda@openjdk.org> Date: 2021-11-19 07:49:58 +0000 URL: https://git.openjdk.java.net/jdk/commit/2f20b0d8daca6bdc53b4b9e1837c428930d34236
19-11-2021

The issue is reproducible. While using "strictfp" and "abstract" as variable name, jshell crashes with: Exception in thread "main" java.lang.InternalError: Exception during analyze - java.lang.AssertionError The cause of the exception be may due to the changes introduced by https://bugs.openjdk.java.net/browse/JDK-8247456.
26-08-2021

The issue is reproducible with JDK 16 onwards. JDK 15: Pass JDK 16: Fail with exception JDK 17: Fail with exception JDK 18: Fail with exception
26-08-2021