Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8268859

jshell throws exception while parsing illegal "case true"

    XMLWordPrintable

    Details

    • Subcomponent:
    • Introduced In Build:
      b26
    • Introduced In Version:
      17
    • Resolved In Build:
      b31
    • CPU:
      generic
    • OS:
      generic

      Backports

        Description

        A DESCRIPTION OF THE PROBLEM :
        Using an illegal "case true" source code in JShell throws an Exception, while Javac does not.

        STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
        ➜ Downloads jshell --enable-preview /tmp/Foo.java
        Exception in thread "main" java.lang.InternalError: Exception during analyze - java.lang.AssertionError: Unexpected tree: true with kind: BOOLEAN_LITERAL within: true with kind: BOOLEAN_LITERAL
                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.Eval.compileAndLoad(Eval.java:1010)
                at jdk.jshell/jdk.jshell.Eval.declare(Eval.java:890)
                at jdk.jshell/jdk.jshell.Eval.eval(Eval.java:137)
                at jdk.jshell/jdk.jshell.JShell.eval(JShell.java:493)
                

        EXPECTED VERSUS ACTUAL BEHAVIOR :
        EXPECTED -
        /tmp/Foo.java:5: error: unexpected type
                                case true t -> 1;
                                     ^
          required: class
          found: value
        /tmp/Foo.java:6: error: unexpected type
                                case false f -> 2;
                                     ^
          required: class
          found: value


        ---------- BEGIN SOURCE ----------
        public class Foo {
            public static void main(String[] args) {
                boolean value = true;
                var result = switch(value){
                    case true t -> 1;
                    case false f -> 2;
                };
            }
        }
        ---------- END SOURCE ----------

        FREQUENCY : often


          Attachments

            Issue Links

              Activity

                People

                Assignee:
                jlahoda Jan Lahoda
                Reporter:
                webbuggrp Webbug Group
                Votes:
                0 Vote for this issue
                Watchers:
                3 Start watching this issue

                  Dates

                  Created:
                  Updated:
                  Resolved: