Java 9 ea154 javac compiler error - legit or bug?

Vitaly Davidovich vitalyd at
Wed Feb 8 19:23:48 UTC 2017

Hi all,

Given the following code:

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) {


    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());

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

javac 9-ea (build 9-ea+154) fails with this interesting error (on the last
line in main, as the comments there indicate): error: method bar in class Foo cannot be applied to given
                bar(foo(String.class, new ArrayList()));
  required: String
  found: String
  reason: argument mismatch; Object cannot be converted to String
1 error

Java 8 compiles fine, and the other 2 lines compile in the same java 9
build as well.

Is this a javac bug or legit? It seems like a compiler error.  At a
minimum, the diagnostic output "required String, found String" is confusing.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the compiler-dev mailing list