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

Conditional expression mistakenly treated as standalone

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • P4
    • 17
    • 8u101, 9, 10
    • tools
    • None
    • b20

    Description

      This test produces 3 unexpected type errors:

          static class Outer {
              class Inner<T> implements Runnable { public void run() {} }
          }

          void test(Outer outer) {
              Outer.Inner<String> inner1 = outer.new Inner<>(); // ok
              Outer.Inner<String> inner2 = test ? outer.new Inner<>() : null; // error
              Outer.Inner<String> inner3 = test ? null: outer.new Inner<>(); // error
              Outer.Inner<String> inner4 = test ? outer.new Inner<String>() : outer.new Inner<>(); // error
          }
          
      The conditional expressions are treated as standalone, despite appearing in an assignment context. So the diamond instance creation always infers Inner<Object>, not Inner<String>.

      Some initial testing seems to trace the issue to a false positive coming from Attr.isBooleanOrNumeric.

      Attachments

        Issue Links

          Activity

            People

              gli Guoxiong Li
              dlsmith Dan Smith
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: