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

(codegen) constant folding broken for conditional operator

    Details

    • Subcomponent:
    • Resolved In Build:
      b04
    • CPU:
      generic
    • OS:
      solaris_8

      Description

      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

        Attachments

          Activity

            People

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

              Dates

              • Created:
                Updated:
                Resolved:
                Imported:
                Indexed: