A bug in the Java 8 compiler.

Maurizio Cimadamore maurizio.cimadamore at oracle.com
Wed May 25 11:12:35 UTC 2016



On 25/05/16 11:55, Remi Forax wrote:
> Optional<Mapper> is a rare type i.e. a mix between a parameterized type and a raw type, declaring opt as a, Optional<Mapper<?>> instead should solve your issue.
>
> FWIW, I'm no sure it's not a regression of jdk 9 instead of a bug in jdk8 (trying to do inference with a rare type).
Hi
By rare type the spec usually means a qualified type which has some raw 
portions - i.e. given the hierarchy:

class Outer<X> {
    class Inner<Y> { }
}

This is a rare type:

Outer.Inner<String>

Rare types are disallowed since JDK 5.

I don't think Optional<Mapper> falls in this category; that's just a 
regular parameterized type where the type parameter happens to be a raw 
type. I don't see any reason as to why the compiler should disallow that 
and infer 'm' in the lambda as a raw Mapper.

I believe the problem seen by Andrej is caused by the fact that JDK 8 
and early JDK 9 used to propagate unchecked-ness in a wrong way - the 
body of the lambda here is calling:

getDetails("A", m)

where 'm' is raw - this means an unchecked warning is probably generated 
here. When that happens in 8, the implementation erroneously propagates 
the uncheckedness outwards, which results in the enclosing method type 
to be erased too - leading up to this error.

We do not plan to backport such fixes because, as discussed in these 
threads [1], the compatibility impact is not negligible.

Maurizio

[1] - 
http://mail.openjdk.java.net/pipermail/compiler-dev/2016-January/009947.html





More information about the compiler-dev mailing list