RFR: JDK-8207224: Javac compiles source code despite illegal use of unchecked conversions
Vicente Romero
vicente.romero at oracle.com
Mon Dec 3 23:32:33 UTC 2018
Hi,
On 12/3/18 4:13 PM, Maurizio Cimadamore wrote:
>
> Looks good - btw, if the compatibility cost proves to be too much we
> could consider putting the new behavior behind the source switch (as
> we did with override/hide string clash checking for some time).
>
I have modified the patch adding a guard to execute the new test only if
source is >= 12, please take a look at the new iteration [1], I have
also modified the CSR [2] accordingly
> Cheers
> Maurizio
>
Thanks,
Vicente
[1] http://cr.openjdk.java.net/~vromero/8207224/webrev.01/
[2] https://bugs.openjdk.java.net/browse/JDK-8214729
> On 03/12/2018 21:01, Vicente Romero wrote:
>> Hi,
>>
>> Please review the related CSR [1]
>>
>> Thanks,
>> Vicente
>>
>> [1] https://bugs.openjdk.java.net/browse/JDK-8214729
>>
>> On 12/1/18 2:46 PM, Vicente Romero wrote:
>>> Please review fix for [1] at [2]. Javac is accepting this program as
>>> valid:
>>>
>>> class ReturnTypeSubstitutableTest {
>>> abstract class AbstractDemo<Request extends AbstractResult,
>>> Response extends AbstractResult> {
>>> protected abstract Response test(Request request);
>>> }
>>>
>>> abstract interface AbstractResult {}
>>>
>>> abstract interface SimpleResult extends AbstractResult {}
>>>
>>> class Result1 implements SimpleResult {}
>>>
>>> class OtherResult implements AbstractResult {}
>>>
>>> public class SimpleDemo<Request extends AbstractResult, Response
>>> extends AbstractResult> extends AbstractDemo<Request, Response> {
>>> @Override
>>> protected SimpleResult test(AbstractResult request) {
>>> <----------- this method is accepted as a good override for
>>> AbstractDemo::test
>>> return null;
>>> }
>>> }
>>> }
>>>
>>> From Dan's evaluation at the bug entry [1]:
>>>
>>> Per JLS 8.4.8.3, the first method must be return-type-substitutable
>>> for the second. This can be satisfied in 3 ways (JLS 8.4.5):
>>> - SimpleResult is a subtype of Response (no)
>>> - SimpleResult can be converted to a subtype of Response by
>>> unchecked conversion (no)
>>> - The methods have different signatures (yep) and SimpleResult =
>>> erasure(Response) (no)
>>>
>>> No case applies, so an error should occur. This fix syncs javac with
>>> the spec.
>>>
>>> Thanks,
>>> Vicente
>>>
>>> [1] https://bugs.openjdk.java.net/browse/JDK-8207224
>>> [2] http://cr.openjdk.java.net/~vromero/8207224/webrev.00/
>>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.openjdk.java.net/pipermail/compiler-dev/attachments/20181203/bdc77dc4/attachment-0001.html>
More information about the compiler-dev
mailing list