issue with fix for JDK-8064464

Liam Miller-Cushon cushon at google.com
Wed Nov 26 00:46:13 UTC 2014


Hi Maurizio,

Thanks for investigating. For what it's worth, the amount of code affected
by this change appears to be very small.

On Mon, Nov 24, 2014 at 2:01 PM, Maurizio Cimadamore <
maurizio.cimadamore at oracle.com> wrote:

>  Hi Liam,
> the JLS defines an operand of a conditional expression to be
> numeric/boolean in case it is a method call with the following wording:
>
> "A method invocation expression (§15.12) for which the chosen most
> specific method (§15.12.2.5) has return type boolean or Boolean.
> *Note that, for a generic method, this is the type **before**
> instantiating the method's type arguments.*"
>
> (oddly, the statement in bold only appears in the section on boolean
> conditionals, and not in the one about numeric conditionals, but I believe
> that's a mistake - i.e. the same statement should be present on both).
>
> This seems to suggest that your example should not compile, as the
> uninstantiated method return type would be T, which is not a numeric type.
>
> However, this seems like a case where the analysis could be improved a bit
> - as far as I recall, this rule is mostly there to prevent excessive
> speculative type-checking during classification of the conditional
> expression; so it seems like taking into account explicit type parameters
> could be doable (although maybe tricky to specify). I'll leave this with
> Dan for further evaluation.
>
> Thanks
> Maurizio
>
>
>
> On 24/11/14 19:37, Liam Miller-Cushon wrote:
>
> The fix for JDK-8064464 [1] [2] prevents the following code from compiling
> (it works fine with 8u25 and 7u67). Is this deliberate?
>
>  abstract class Test {
>   abstract <T> T e();
>   abstract int f();
>   void m(boolean flag) {
>     String.valueOf(flag ? f() : this.<Integer>e());
>   }
> }
>
>  $ javac Test.java
>  Test.java:5: error: reference to valueOf is ambiguous
>     String.valueOf(flag ? f() : this.<Integer>e());
>           ^
>   both method valueOf(Object) in String and method valueOf(int) in String
> match
>
>  [1] https://bugs.openjdk.java.net/browse/JDK-8064464
> [2] http://hg.openjdk.java.net/jdk9/dev/langtools/rev/601e08b62ba8
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.openjdk.java.net/pipermail/compiler-dev/attachments/20141125/e9fec716/attachment.html>


More information about the compiler-dev mailing list