[BUG] Missing error? blank final may not have been initialized
Jan Lahoda
jan.lahoda at oracle.com
Tue Apr 8 16:37:19 UTC 2014
On 04/08/2014 02:06 AM, Alex Buckley wrote:
> The question for compiler-dev is not whether the DU/DA analysis within
> anonymous classes is reasonable, but whether there's been a regression
> in javac. I know Paul and Jan are working on DU/DA analysis at the
> moment, maybe they could comment.
I don't think there is a regression in javac - I was able to compile the
provided code with "1.4.2_07" javac. Intuitively, considering the
methods declared in the anonymous innerclass to be outside of the
expression that contains the new instance expression itself seems
reasonable to me. Note that if the access is moved to the initializer of
the anonymous class, it is flagged as an error (which makes sense to me).
Jan
>
> Alex
>
> On 4/7/2014 3:50 PM, Raffaele Sgarro wrote:
>> Hi Alex,
>>
>> In fact, the lambda behavior is correct to me. Why do you think it would
>> be unreasonable for the anonymous?
>>
>>
>> 2014-04-08 0:09 GMT+02:00 Alex Buckley <alex.buckley at oracle.com
>> <mailto:alex.buckley at oracle.com>>:
>>
>> I don't believe javac has ever given an error in this case. It would
>> be unreasonable to require 'data' to be definitely assigned before
>> the body of the anonymous class. OTOH, names in the body of a lambda
>> expression are specified as if they appear outside the lambda
>> expression, where 'data' would be definitely unassigned, so an error
>> is due there.
>>
>> Alex
>>
>>
>> On 4/7/2014 10:02 AM, Raffaele Sgarro wrote:
>>
>> §16 states:
>>
>> For every access of a local variable or blank final field x, x
>> must be
>> definitely assigned before the access, or a compile-time error
>> occurs.
>>
>> Consider the following code:
>>
>> class Ideone{
>>
>> public interface Provider{ String get(); }
>>
>> public static class Outer{
>>
>> private final String data;
>> private final String token;
>> private final Provider secretProvider= new
>> Provider() {
>>
>> public String get() {
>> return data;
>> }
>> };
>>
>> public Outer() {
>> token= secretProvider.get();
>> data= "FOOBAR";
>>
>> }
>>
>> public String getToken() {
>> return token;
>> }
>>
>> }
>>
>> public static void main(String[] args) throws
>> java.lang.Exception {
>> Outer outer= new Outer();
>>
>> System.out.println(outer.__getToken()); //
>> Prints null
>> }
>> }
>>
>> Note that if I used a lambda expression, instead, javac would
>> have
>> complained.
>>
>>
More information about the compiler-dev
mailing list