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

Regression in generic method unchecked calls

    XMLWordPrintable

Details

    • b157
    • 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

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

                Dates

                  Created:
                  Updated:
                  Resolved: