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

boolean constant expressions and definite assignment rules

    Details

    • Subcomponent:
    • Resolved In Build:
      beta
    • CPU:
      sparc
    • OS:
      solaris_7

      Description



      Name: laC46010 Date: 01/14/2000



      Javac (JDK1.3.0R) does not take into account boolean constant
      expressions which use boolean logical operators '|', '&' or '^'.
      The test below uses the constant boolean expression whose value
      is "true" as the conditional expression of 'if' statement and
      tries to use the variable that has no definitely assigned value
      in the 'else' branch. JLS (16.1.1) says, that

          "V is definitely assigned after any constant expression
                  whose value is true when false."

      Therefore every variable in the else branch is definitely assigned.
      But javac incorrectly reports that variable might not have been
      initialized. This error arises in all versions of JDK.

      See reduced JCK test source and logs below:

      --------------------------------------------------dasg00703.java
      public class dasg00703 {
          public static void main(String args[]) {
      boolean b;
      if (true | false) ;
      else
      if (b) ; // case '|'
      if (true & true) ;
      else
      if (b) ; // case '&'
      if (true ^ false) ;
      else
      if (b) ; // case '^'
          }
      }
      ----------------------------------------------------------------
      Results of compilation:

      $ java -version
      java version "1.3.0"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0-R)
      Java HotSpot(TM) Client VM (build 1.3-R, interpreted mode)
      $ javac -d . dasg00703.java
      dasg00703.java:6: variable b might not have been initialized
                  if (b) ; // case '|'
                      ^
      dasg00703.java:9: variable b might not have been initialized
                  if (b) ; // case '&'
                      ^
      dasg00703.java:12: variable b might not have been initialized
                  if (b) ; // case '^'
                      ^
      3 errors
      $
      ----------------------------------------------------------------

      ======================================================================

        Attachments

          Activity

            People

            • Assignee:
              wmaddoxsunw William Maddox (Inactive)
              Reporter:
              leosunw Leo Leo (Inactive)
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:
                Imported:
                Indexed: