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

Regression in generic method unchecked calls

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P3
    • Resolution: Fixed
    • Affects Version/s: 9
    • Fix Version/s: 9
    • Component/s: tools
    • Subcomponent:
    • Resolved In Build:
      b157
    • Verification:
      Verified

      Backports

        Description

        This code stopped compiling after the fix for JDK-8078093:

        import java.util.ArrayList;
        import java.util.Collection;

        public class Foo {
            static <T> T foo(Class<T> c, Collection<? super T> baz) {
        return null;
            }

            static void bar(String c) {

            }

            @SuppressWarnings("unchecked")
            public static void main(String[] args) {
        // this works
        bar(foo(String.class, new ArrayList<String>()));

        // this works with a warning
        String s = foo(String.class, new ArrayList());
        bar(s);

        // this causes an error on JDK9
        bar(foo(String.class, new ArrayList()));
            }
        }

        Moreover, the error issued is weird-looking:

        Foo.java:23: error: method bar in class Foo cannot be applied to given types;
                        bar(foo(String.class, new ArrayList()));
                        ^
          required: String
          found: String
          reason: argument mismatch; Object cannot be converted to String
        1 error

          Attachments

            Issue Links

              Activity

                People

                • Assignee:
                  mcimadamore Maurizio Cimadamore
                  Reporter:
                  mcimadamore Maurizio Cimadamore
                • Votes:
                  0 Vote for this issue
                  Watchers:
                  3 Start watching this issue

                  Dates

                  • Created:
                    Updated:
                    Resolved: