FULL PRODUCT VERSION :
C:\>javac -version
javac 1.8.0_144
ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows [Version 6.1.7601]
A DESCRIPTION OF THE PROBLEM :
Attached source code fails to compile. The problem seems that type inference fails for complex enough type signatures.
The 'badfoo4' and 'foo4' methods are functionally the same, but the source does not compile until I comment out 'badfoo4'. That the 'foo3' method compiles shows that it's not the 'identity' method that (alone) causes the compilation error.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Compile the attached source code using javac Javacbug.java. (no classpath necessary).
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Should compile.
ACTUAL -
I get a compilation error.
ERROR MESSAGES/STACK TRACES THAT OCCUR :
Javacbug.java:34: error: method bar4 in class Javacbug cannot be applied to given types;
return bar4(p4, identity(), identity(), identity(), identity());
^
required: P4<A#1,B#1,C#1,D#1>,Function<A#1,U<E>>,Function<B#1,U<F>>,Function<C#1,U<G>>,Function<D#1,U<H>>
found: P4<U<A#2>,U<B#2>,U<C#2>,U<D#2>>,Function<Object,Object>,Function<Object,Object>,Function<Object,Object>,Function<Object,Object>
reason: inferred type does not conform to equality constraint(s)
inferred: Object
equality constraints(s): U<Object>
where A#1,B#1,C#1,D#1,E,F,G,H,A#2,B#2,C#2,D#2 are type-variables:
A#1 extends Object declared in method <A#1,B#1,C#1,D#1,E,F,G,H>bar4(P4<A#1,B#1,C#1,D#1>,Function<A#1,U<E>>,Function<B#1,U<F>>,Function<C#1,U<G>>,Function<D#1,U<H>>)
B#1 extends Object declared in method <A#1,B#1,C#1,D#1,E,F,G,H>bar4(P4<A#1,B#1,C#1,D#1>,Function<A#1,U<E>>,Function<B#1,U<F>>,Function<C#1,U<G>>,Function<D#1,U<H>>)
C#1 extends Object declared in method <A#1,B#1,C#1,D#1,E,F,G,H>bar4(P4<A#1,B#1,C#1,D#1>,Function<A#1,U<E>>,Function<B#1,U<F>>,Function<C#1,U<G>>,Function<D#1,U<H>>)
D#1 extends Object declared in method <A#1,B#1,C#1,D#1,E,F,G,H>bar4(P4<A#1,B#1,C#1,D#1>,Function<A#1,U<E>>,Function<B#1,U<F>>,Function<C#1,U<G>>,Function<D#1,U<H>>)
E extends Object declared in method <A#1,B#1,C#1,D#1,E,F,G,H>bar4(P4<A#1,B#1,C#1,D#1>,Function<A#1,U<E>>,Function<B#1,U<F>>,Function<C#1,U<G>>,Function<D#1,U<H>>)
F extends Object declared in method <A#1,B#1,C#1,D#1,E,F,G,H>bar4(P4<A#1,B#1,C#1,D#1>,Function<A#1,U<E>>,Function<B#1,U<F>>,Function<C#1,U<G>>,Function<D#1,U<H>>)
G extends Object declared in method <A#1,B#1,C#1,D#1,E,F,G,H>bar4(P4<A#1,B#1,C#1,D#1>,Function<A#1,U<E>>,Function<B#1,U<F>>,Function<C#1,U<G>>,Function<D#1,U<H>>)
H extends Object declared in method <A#1,B#1,C#1,D#1,E,F,G,H>bar4(P4<A#1,B#1,C#1,D#1>,Function<A#1,U<E>>,Function<B#1,U<F>>,Function<C#1,U<G>>,Function<D#1,U<H>>)
A#2 extends Object declared in method <A#2,B#2,C#2,D#2>badfoo4(P4<U<A#2>,U<B#2>,U<C#2>,U<D#2>>)
B#2 extends Object declared in method <A#2,B#2,C#2,D#2>badfoo4(P4<U<A#2>,U<B#2>,U<C#2>,U<D#2>>)
C#2 extends Object declared in method <A#2,B#2,C#2,D#2>badfoo4(P4<U<A#2>,U<B#2>,U<C#2>,U<D#2>>)
D#2 extends Object declared in method <A#2,B#2,C#2,D#2>badfoo4(P4<U<A#2>,U<B#2>,U<C#2>,U<D#2>>)
1 error
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import java.util.function.Function;
public final class Javacbug {
public static final class P3<A, B, C> {
}
public static final class P4<A, B, C, D> {
}
public static final class U<A> {
}
// This one compiles
public static <A, B, C> void foo3(P3<U<A>, U<B>, U<C>> p3) {
bar3(p3, identity(), identity(), identity());
}
// This one compiles
public static <A, B, C, D> void foo4(P4<U<A>, U<B>, U<C>, U<D>> p4) {
bar4(p4, identity(), identity(), identity(), (U<D> arg4) -> arg4);
}
// This one does not compile
public static <A, B, C, D> void badfoo4(P4<U<A>, U<B>, U<C>, U<D>> p4) {
bar4(p4, identity(), identity(), identity(), identity());
}
public static <A, B, C, E, F, G> void bar3(P3<A, B, C> p4, Function<A, U<E>> f1, Function<B, U<F>> f2, Function<C, U<G>> f3) {
}
public static <A, B, C, D, E, F, G, H> void bar4(P4<A, B, C, D> p4, Function<A, U<E>> f1, Function<B, U<F>> f2, Function<C, U<G>> f3, Function<D, U<H>> f4) {
}
public static <A> Function<A, A> identity() {
return arg -> arg;
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
See method 'foo4'.
C:\>javac -version
javac 1.8.0_144
ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows [Version 6.1.7601]
A DESCRIPTION OF THE PROBLEM :
Attached source code fails to compile. The problem seems that type inference fails for complex enough type signatures.
The 'badfoo4' and 'foo4' methods are functionally the same, but the source does not compile until I comment out 'badfoo4'. That the 'foo3' method compiles shows that it's not the 'identity' method that (alone) causes the compilation error.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Compile the attached source code using javac Javacbug.java. (no classpath necessary).
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Should compile.
ACTUAL -
I get a compilation error.
ERROR MESSAGES/STACK TRACES THAT OCCUR :
Javacbug.java:34: error: method bar4 in class Javacbug cannot be applied to given types;
return bar4(p4, identity(), identity(), identity(), identity());
^
required: P4<A#1,B#1,C#1,D#1>,Function<A#1,U<E>>,Function<B#1,U<F>>,Function<C#1,U<G>>,Function<D#1,U<H>>
found: P4<U<A#2>,U<B#2>,U<C#2>,U<D#2>>,Function<Object,Object>,Function<Object,Object>,Function<Object,Object>,Function<Object,Object>
reason: inferred type does not conform to equality constraint(s)
inferred: Object
equality constraints(s): U<Object>
where A#1,B#1,C#1,D#1,E,F,G,H,A#2,B#2,C#2,D#2 are type-variables:
A#1 extends Object declared in method <A#1,B#1,C#1,D#1,E,F,G,H>bar4(P4<A#1,B#1,C#1,D#1>,Function<A#1,U<E>>,Function<B#1,U<F>>,Function<C#1,U<G>>,Function<D#1,U<H>>)
B#1 extends Object declared in method <A#1,B#1,C#1,D#1,E,F,G,H>bar4(P4<A#1,B#1,C#1,D#1>,Function<A#1,U<E>>,Function<B#1,U<F>>,Function<C#1,U<G>>,Function<D#1,U<H>>)
C#1 extends Object declared in method <A#1,B#1,C#1,D#1,E,F,G,H>bar4(P4<A#1,B#1,C#1,D#1>,Function<A#1,U<E>>,Function<B#1,U<F>>,Function<C#1,U<G>>,Function<D#1,U<H>>)
D#1 extends Object declared in method <A#1,B#1,C#1,D#1,E,F,G,H>bar4(P4<A#1,B#1,C#1,D#1>,Function<A#1,U<E>>,Function<B#1,U<F>>,Function<C#1,U<G>>,Function<D#1,U<H>>)
E extends Object declared in method <A#1,B#1,C#1,D#1,E,F,G,H>bar4(P4<A#1,B#1,C#1,D#1>,Function<A#1,U<E>>,Function<B#1,U<F>>,Function<C#1,U<G>>,Function<D#1,U<H>>)
F extends Object declared in method <A#1,B#1,C#1,D#1,E,F,G,H>bar4(P4<A#1,B#1,C#1,D#1>,Function<A#1,U<E>>,Function<B#1,U<F>>,Function<C#1,U<G>>,Function<D#1,U<H>>)
G extends Object declared in method <A#1,B#1,C#1,D#1,E,F,G,H>bar4(P4<A#1,B#1,C#1,D#1>,Function<A#1,U<E>>,Function<B#1,U<F>>,Function<C#1,U<G>>,Function<D#1,U<H>>)
H extends Object declared in method <A#1,B#1,C#1,D#1,E,F,G,H>bar4(P4<A#1,B#1,C#1,D#1>,Function<A#1,U<E>>,Function<B#1,U<F>>,Function<C#1,U<G>>,Function<D#1,U<H>>)
A#2 extends Object declared in method <A#2,B#2,C#2,D#2>badfoo4(P4<U<A#2>,U<B#2>,U<C#2>,U<D#2>>)
B#2 extends Object declared in method <A#2,B#2,C#2,D#2>badfoo4(P4<U<A#2>,U<B#2>,U<C#2>,U<D#2>>)
C#2 extends Object declared in method <A#2,B#2,C#2,D#2>badfoo4(P4<U<A#2>,U<B#2>,U<C#2>,U<D#2>>)
D#2 extends Object declared in method <A#2,B#2,C#2,D#2>badfoo4(P4<U<A#2>,U<B#2>,U<C#2>,U<D#2>>)
1 error
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import java.util.function.Function;
public final class Javacbug {
public static final class P3<A, B, C> {
}
public static final class P4<A, B, C, D> {
}
public static final class U<A> {
}
// This one compiles
public static <A, B, C> void foo3(P3<U<A>, U<B>, U<C>> p3) {
bar3(p3, identity(), identity(), identity());
}
// This one compiles
public static <A, B, C, D> void foo4(P4<U<A>, U<B>, U<C>, U<D>> p4) {
bar4(p4, identity(), identity(), identity(), (U<D> arg4) -> arg4);
}
// This one does not compile
public static <A, B, C, D> void badfoo4(P4<U<A>, U<B>, U<C>, U<D>> p4) {
bar4(p4, identity(), identity(), identity(), identity());
}
public static <A, B, C, E, F, G> void bar3(P3<A, B, C> p4, Function<A, U<E>> f1, Function<B, U<F>> f2, Function<C, U<G>> f3) {
}
public static <A, B, C, D, E, F, G, H> void bar4(P4<A, B, C, D> p4, Function<A, U<E>> f1, Function<B, U<F>> f2, Function<C, U<G>> f3, Function<D, U<H>> f4) {
}
public static <A> Function<A, A> identity() {
return arg -> arg;
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
See method 'foo4'.
- duplicates
-
JDK-8187546 java.lang.IllegalStateException: endPosTable already set at com.sun.tools.javac.util.DiagnosticSource.setEndPosTable(DiagnosticSource.java:136)
- Closed