JDK8: Compile error introduced with backport JDK-8258780 for https://bugs.openjdk.java.net/browse/JDK-8078024
Wessel van Norel
wessel.van.norel at delgurth.com
Mon Jul 12 23:43:37 UTC 2021
L.S.
Something is bugging me for some time already and I think I’ve found enough information to proceed, at least assuming that I’ve found the correct place to send this e-mail to and ask a question.
https://bugs.openjdk.java.net/browse/JDK-8078024 has been backported with https://bugs.openjdk.java.net/browse/JDK-8258780. The statement in the release notes says:
This fix has source compatibility impact, right now code that wasn't being accepted is now being accepted by the javac compiler. Currently there are no reports of any other kind of incompatibility.
This might be true on java 9+, but unfortunately on java 8 it has introduced a false negative. At least, the test case I’ve “compiled" compiles on java 9 - 16, and on java 8u282, but not on java 8u292.
I’ve tried to bring the test-case back to a minimum. See attached file.
Without a “List" the code also fails to compile on java 8u282 (so before the backport of JDK-8258780).
And if I remove the ".map(ref -> (BugTrigger<? extends SuperOrExtends>) ref)"
modern (9+) compilers also do not accept the code: "reason: no instance(s) of type variable(s) exist so that capture of ? extends SuperOrExtends conforms to capture of ? extends SuperOrExtends”
Which is technically not true, if I understood the "? extends" vs the "? super" correctly. In case you have an object of type SuperOrExtends both "? super SuperOrExtends” and “? extends SuperOrExtends” are valid for the object. You should not want this, because why would you work with generics if all you provide is the exact type, but that’s a different story.
The java 8 u 292 compile error on this code is (with “proof” that it works on other versions):
$ javac -version && javac SuperOrExtends.java
javac 16.0.1
$ javac -version && javac SuperOrExtends.java
javac 9.0.7.1
$ javac -version && javac SuperOrExtends.java
javac 1.8.0_282
$ javac -version && javac SuperOrExtends.java
javac 1.8.0_292
SuperOrExtends.java:11: error: method updateValues in class SuperOrExtends cannot be applied to given types;
.forEach(ref -> updateValues(param1.trigger(ref), Collections.singletonList(ref)));
^
required: BugTrigger<A>,List<BugTrigger<? super A>>
found: BugTrigger<CAP#1>,List<BugTrigger<CAP#1>>
reason: inference variable T has incompatible bounds
equality constraints: BugTrigger<? super A>
lower bounds: BugTrigger<CAP#1>
where A,T are type-variables:
A extends SuperOrExtends declared in method <A>updateValues(BugTrigger<A>,List<BugTrigger<? super A>>)
T extends Object declared in method <T>singletonList(T)
where CAP#1 is a fresh type-variable:
CAP#1 extends SuperOrExtends from capture of ? extends SuperOrExtends
1 error
Seeing this error the problem lies in:
https://hg.openjdk.java.net/jdk8u/jdk8u-dev/langtools/rev/cd6eb36db1bb#l1.32
Unfortunately fixing it will most likely not be trivial, seeing that the problem resides in code that was not introduced in this patch, and seeing that changing the code a bit can also cause modern and older compilers to fail. But before I investigate further how to fix this I want to ask a question:
What steps, besides the code fix, would I need to take to get a possible fix into jdk8u-dev? Since this is not a bug in any of the upstream versions, only in this version I thought this mailing-list would be the appropriate channel to provide a fix.
I thank you for your time.
Kind regards,
Wessel van Norel
More information about the jdk8u-dev
mailing list