RFR: JDK-8207224: Javac compiles source code despite illegal use of unchecked conversions

Vicente Romero vicente.romero at oracle.com
Mon Dec 3 21:01:59 UTC 2018


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/55974c8e/attachment.html>


More information about the compiler-dev mailing list