question about JDK-8063054 (incorrect raw type warnings for method references)
Liam Miller-Cushon
cushon at google.com
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 Test.java
javac full version "9-ea+156"
Test.java:3: 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:
http://hg.openjdk.java.net/jdk9/dev/langtools/annotate/33d1937af1a3/src/share/classes/com/sun/tools/javac/comp/Attr.java#l2738
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.
Thanks,
Liam
[1] https://bugs.openjdk.java.net/browse/JDK-8063054
[2] https://bugs.openjdk.java.net/browse/JDK-8012685
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.openjdk.java.net/pipermail/compiler-dev/attachments/20170215/54c17589/attachment-0001.html>
More information about the compiler-dev
mailing list