Push 23 August 1bb5b46bb326 fixes one bug, but introduces another

Maurizio Cimadamore maurizio.cimadamore at oracle.com
Tue Aug 24 01:24:48 PDT 2010


On 24/08/10 09:07, Howard Lovatt wrote:
> Hi Maurizio,
>
>        il.forEach( #( i ) {
>          if ( i<  3 ) { throw new Exception(); }
>          return i * i;
>        } ); // Need to catch the checked exception!
>
> Now needs a try block (as it should), but
>
>      il.forEach( #( i ) { return 2 * i; } ); // No exception, no try block
>
>   Also needs one and it shouldn't!
>    
Strictly speaking, this is not a bug - it is a limitation of the current 
inference scheme that has been noticed elsewhere in this forum; 
unfortunately, when the body of the lambda expression has resolution 
(e.g. operator/method) depending on the type of the parameter to be 
inferred, javac cannot infer the thrown types from the lambda body; as 
such, thrown types are inferred from the target type - in this case, the 
target types throws E, whose bound is Exception - since no constraint is 
found (from the lambda), E is simply instantiated to Exception.

However I understand that this is something that needs to be improved - 
it is showing up now because of  the bug I fixed in the compiler (the 
compiler was assuming that no exception where thrown when inference gave 
up - which is potentially unsafe).

Maurizio
> I for one really appreciate all your hard work on this.
>
>    -- Howard.
>
>    



More information about the lambda-dev mailing list