question about JDK-8063054 (incorrect raw type warnings for method references)

Liam Miller-Cushon cushon at
Thu Feb 16 02:33:01 UTC 2017

I've seen JDK-8063054 [1] crop up a few times, and did some investigation
that I thought I'd share in case it's useful.

To summarize the bug, javac emits spurious rawtypes warnings for some
method references:

class Test {
  void test(Box<? extends Box<Number>> b) {
    Number n = b.<Number>map(Box::get).get();
  interface Func<S,T> { T apply(S arg); }
  interface Box<T> {
    T get();
    <R> Box<R> map(Func<T,R> f);
javac -fullversion -Xlint:rawtypes
javac full version "9-ea+156" warning: [rawtypes] found raw type: Box
      Number n = b.<Number>map(Box::get).get();

I think the cause is related to the fix for JDK-8012685 [2]. Logic was
added to skip rawtype warnings on method references if the qualifier can be
inferred. This is done by testing if the inferred type is parameterized:

In the example above, the inferred type of Box is `capture of ? extends
Test.Box<java.lang.Number>`. It isn't raw, but it also isn't trivially
parameterized, so it fails the check in Attr and still results in a
rawtypes warning.

I think the fix might be as simple as replacing
`!desc.getParameterTypes().head.isParameterized()` with something that
handles capture variables.


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

More information about the compiler-dev mailing list