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

Definite assignment check for boolean conditional operator

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P4 P4
    • None
    • 1.3.0
    • tools
    • sparc
    • solaris_2.5.1



      Name: krT82822 Date: 11/04/99


      The compilation of the following program fails:

      class Test {
        boolean m(boolean x, boolean y) {
          boolean z;
          if ( x ? (z = y) : false ) return z;
          // Variable z may not have been initialized
          return x;
        }
      }

      According to the rules for definite assignment in Chapter 16 of the Java
      Language Specification, however, the variable z is

        "definitely assigned after `x ? (z = y) : false' when true".

      Reason:
      1) z is definitely assigned after `z = y' when true (16.1.13)
      2) z is definitely assigned after `false' when true (16.1.1)
      3) z is definitely assigned after `x ? (z = y) : false' when true (16.1.11).
      4) z is definitely assigned before `return z' (16.2.6)

      Therefore I believe that the compiler should accept the second version
      of the program, too.

      The following equivalent program compiles without error:

      class Test {
        boolean m(boolean x, boolean y) {
          boolean z;
          if ( x && (z = y) ) return z;
          return x;
        }
      }
      (Review ID: 97383)
      ======================================================================

            wmaddoxsunw William Maddox (Inactive)
            kryansunw Kevin Ryan (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: