about bug: 8020216: Compile time error isn't shown when final class variable is not assigned
Vicente-Arturo Romero-Zaldivar
vicente.romero at oracle.com
Thu Aug 8 03:37:41 PDT 2013
Hi John,
Thanks for your answer. I agree with you.
Vicente
On 08/08/13 03:05, John Rose wrote:
> On Aug 1, 2013, at 10:57 AM, Vicente-Arturo Romero-Zaldivar
> <vicente.romero at oracle.com <mailto:vicente.romero at oracle.com>> wrote:
>
>> Is this what we want?
>
> No.
>
> For blank-final instance variables, the definite assignment is only
> required at *normal* completion of the constructor. Abnormal
> completion (such as the throw in your example) *must* be allowed to
> happen when blank-finals are still unassigned. Otherwise this code
> would fail:
>
> class HasBlankF {
> final int hc;
> HasBlankF(Object x) {
> hc = x.hashCode();
> }
> }
>
> It would fail because there is a potential throw that works like this:
>
> class HasBlankF {
> final int hc;
> HasBlankF(Object x) {
> if (x == null) throw new NullPointerException();
> hc = x.hashCode();
> }
> }
>
> I added a comment to this effect on the bug report.
>
> The same point applies for abnormal completion of <clinit> methods
> (static initializers). Blank finals which are statics must be
> definitely assigned at normal termination of the last static
> initializer. If a static initializer terminates abnormally, the class
> is not available to its users, and some of its blank finals may
> validly remain forever uninitialized.
>
> — John
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.openjdk.java.net/pipermail/compiler-dev/attachments/20130808/4659dd22/attachment.html
More information about the compiler-dev
mailing list