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

(codegen) constant folding broken for conditional operator

XMLWordPrintable

    • b04
    • generic
    • solaris_8

      As expression of the form:

          private static final String str1 = (flag ? "STRING" : null);

      is incorrectly evaluated to be "STRING" even when flag is false.

      The attached program demonstrates this. It works on JDK 1.4.2 (and
      earlier) and fails on JDK 1.5.0-rc. This is definitely a javac bug,
      because compiling this program on 1.4.2 and running it on 1.5.0-rc
      works fine. Compiling it on 1.5.0 (with -source 1.4 and -target 1.4)
      fails when run on either 1.5.0-rc or 1.4.2.

      When run on 1.5.0, the following error occurs:

      javac bug.java
      java bug

      flag = false
      str1 = REGRESSION!!!
      str2 = null
      str3 = OK


      The expected output (as demonstrated on 1.4.2 and by inspection) is:

      flag = false
      str1 = null
      str2 = null
      str3 = OK

            ahe Peter Ahe
            kcr Kevin Rushforth
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: