JShell: Incorrect error when using a case constant

XMLWordPrintable

    • Type: Bug
    • Resolution: Unresolved
    • Priority: P4
    • 27
    • Affects Version/s: 24, 25, 26, 27
    • Component/s: tools
    • None

      According to the JLS 15.29, a simple name that refers to a constant variable is a constant expression, and thus can appear as a case constant.

      This is handled correctly by javac:
      ```
      > % cat ConstantExpressionBug.java
      public void main() {
          final byte constant = 42;
          Byte b = 42;
          switch(b) { case constant: IO.println("match");}
      }
      > % java ConstantExpressionBug.java
      match
      ```
      whereas jshell reports an error:

      ```
      > % jshell
      | Welcome to JShell -- Version 25
      | For an introduction type: /help intro

      jshell> final byte constant = 42;
         ...> Byte b = 42;
         ...> switch(b) { case constant: IO.println("match");}
      constant ==> 42
      b ==> 42
      | Error:
      | constant expression required
      | switch(b) { case constant: IO.println("match");}
      | ^------^

      jshell>
      ```

            Assignee:
            Angelos Bimpoudis
            Reporter:
            Gavin Bierman
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: