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

javac allows improper qualified name in switch case label

XMLWordPrintable

    • kestrel
    • generic, sparc
    • generic, solaris_2.5.1



      Name: tb29552 Date: 08/27/99


      /*

       A bug was reported against Metamata Audit because it rejected a
       case label as non-constant and javac did not. Checking the JLS,
       it appears that Audit is correct and javac should, in fact,
       reject it.

       Here is the program:

      */
      import java.awt.event.MouseEvent;
      public class CaseTest {
          public void processMouseEvent (MouseEvent event) {
              switch (event.getID ()) {
              case MouseEvent.MOUSE_PRESSED: // OK
                  break;
              case event.MOUSE_RELEASED: // Not constant by JLS 15.27
                  break;
              }
          }
      }
      /*

       JLS ?14.9, the grammar defines SwitchLabel as either "case
       ConstantExpression :" or "default :". The text says "These
       labels are said to be associated with the switch statement, as
       are the values of the constant expressions (?15.27) in the case
       labels."

       In JLS ?15.27, a ConstantExpression is defined as one of 13
       choices, only the last of which can be a qualified name:
       "Qualified names of the form TypeName.Identifier that refer to
       final variables whose initializers are constant expressions"

      */

      (Review ID: 94481)
      ======================================================================

            wmaddoxsunw William Maddox (Inactive)
            tbell Tim Bell
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: