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

Use the switch expression in JShell and report an error at the end

XMLWordPrintable

    • generic
    • generic

      ADDITIONAL SYSTEM INFORMATION :
      windows 11 / JDK 17.0.1

      A DESCRIPTION OF THE PROBLEM :
      The switch expression in Jshell is finished with " default... ; " After that, you want to wrap the line to add the last " }; " , Now you get an Error "The end of the file was reached when the syntax analysis was performed"

      REGRESSION : Last worked in version 17.0.1

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      jshell> String result;
      result ==> null
      | created variable result : String

      jshell> String language = "English";
      language ==> "English"
      | created variable language : String

      jshell> result = switch (language) {
         ...> case "English" -> "Hello";
         ...> case "Spanish" -> "Hola";
         ...> default -> throw new RuntimeException("Unsupported language");

      Copy the code above and click the enter button directly to reproduce the exception

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Print the results correctly : Hello
      ACTUAL -
      The end of the file was reached when the syntax analysis was performed

      ---------- BEGIN SOURCE ----------
      jshell> String result;
      result ==> null
      | created variable result : String

      jshell> String language = "English";
      language ==> "English"
      | created variable language : String

      jshell> result = switch (language) {
         ...> case "English" -> "Hello";
         ...> case "Spanish" -> "Hola";
         ...> default -> throw new RuntimeException("Unsupported language");

      Copy the code above and click the enter button directly to reproduce the exception
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      There is no solution at this time

      FREQUENCY : always


            adev Anupam Dev
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: