[BUG] Missing error? blank final may not have been initialized
Alex Buckley
alex.buckley at oracle.com
Tue Apr 8 00:06:29 UTC 2014
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.
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