Java 8 compiler bug?
Oliver Gierke
ogierke at pivotal.io
Tue Nov 15 23:46:02 UTC 2016
Hi all,
I just ran in this code compiling fine with a JDK 8 if I define a compilation source and target of 1.6, but not if I define both values of 1.8.
public class Ambiguity {
public void foo(CriteriaBuilder builder) {
Expression<Object> objectExpression = null;
Expression<Collection<Object>> collectionOfObjectExpression = null;
builder.isNotMember(objectExpression, collectionOfObjectExpression);
// ^^^^^^^^^^^ - ambiguous
}
}
CriteriaBuilder and all other types come from JPA. The method in question has two overloads:
<E, C extends Collection<E>> Predicate isNotMember(Expression<E> elem, Expression<C> collection);
<E, C extends Collection<E>> Predicate isNotMember(E elem, Expression<C> collection);
I fail to understand why the second method is even considered as that create a contradiction between the bound values of E (Expression<…>) and C (Collection<Object>).
I've prepared an example here [0]. Steps to reproduce:
1. Unzip
2. Run mvn clean compile -> fails
3. Change java.version property in pom.xml to 1.6
4. Run mvn clean compile -> succeeds
$ java -version
java version "1.8.0_112"
Java(TM) SE Runtime Environment (build 1.8.0_112-b16)
Java HotSpot(TM) 64-Bit Server VM (build 25.112-b16, mixed mode)
Is that a known issue, something I oversee or should I create a ticket for that?
Cheers,
Ollie
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 841 bytes
Desc: Message signed with OpenPGP using GPGMail
URL: <http://mail.openjdk.java.net/pipermail/compiler-dev/attachments/20161116/c33293a8/signature-0001.asc>
More information about the compiler-dev
mailing list