<html>
<head>
<meta content="text/html; charset=windows-1252"
http-equiv="Content-Type">
</head>
<body bgcolor="#FFFFFF" text="#000000">
As the owner of the compiler-dev list, I'm forwarding this email
that was bounced here from the
<a class="moz-txt-link-abbreviated" href="mailto:jls-jvms-spec-comments@openjdk.java.net">jls-jvms-spec-comments@openjdk.java.net</a> list.<br>
<br>
-- Jon<br>
<br>
<div class="moz-cite-prefix">On 06/22/2016 04:54 PM,
<a class="moz-txt-link-abbreviated" href="mailto:compiler-dev-owner@openjdk.java.net">compiler-dev-owner@openjdk.java.net</a> wrote:<br>
</div>
<blockquote
cite="mid:mailman.16899.1466639648.23828.compiler-dev@openjdk.java.net"
type="cite">
<table class="header-part1" width="100%" border="0"
cellpadding="0" cellspacing="0">
<tbody>
<tr>
<td>
<div class="headerdisplayname" style="display:inline;">Subject:
</div>
inner class reading uninitialized value from outer class</td>
</tr>
<tr>
<td>
<div class="headerdisplayname" style="display:inline;">From:
</div>
Xen <a class="moz-txt-link-rfc2396E" href="mailto:list@xenhideout.nl"><list@xenhideout.nl></a></td>
</tr>
<tr>
<td>
<div class="headerdisplayname" style="display:inline;">Date:
</div>
06/05/2016 07:10 AM</td>
</tr>
</tbody>
</table>
<table class="header-part2" width="100%" border="0"
cellpadding="0" cellspacing="0">
<tbody>
<tr>
<td>
<div class="headerdisplayname" style="display:inline;">To:
</div>
<a class="moz-txt-link-abbreviated" href="mailto:jls-jvms-spec-comments@openjdk.java.net">jls-jvms-spec-comments@openjdk.java.net</a></td>
</tr>
</tbody>
</table>
<br>
<div class="moz-text-flowed" style="font-family: -moz-fixed;
font-size: 12px;" lang="x-western">I am not sure if this is the
proper list to discuss a thing like this.
<br>
<br>
The only alternative I have really found thus far is
compiler-dev.
<br>
<br>
<br>
I created an inner class that reads a value from the outer
class:
<br>
<br>
<br>
class Outer {
<br>
final int value;
<br>
<br>
Outer() {
<br>
value = 1;
<br>
}
<br>
<br>
class Inner {
<br>
int mine = Outer.this.value;
<br>
}
<br>
}
<br>
<br>
Now an instance of inner is created before the constructor of
outer is called.
<br>
<br>
The OpenJDK 8 compiler gives no error, but the value that is
getting read is 0; even though it has not been initialized (no
oddity here) but it is getting read even though it is not
initialized; and there is no compiler warning saying so:
<br>
<br>
class Outer {
<br>
Inner haha = new Inner(); // gets initialized to 0, not to 1
<br>
<br>
...
<br>
}
<br>
<br>
However if we put the creation into the constructor of outer, it
gets the proper value. So there are 2 init stages: before the
constructor is called, and after. You can call both inner class
pre-init and constructor (both instanced) before the outer class
constructor has been called.
<br>
<br>
Nothing odd here, but it does read a final value that has not
been initialized yet. Maybe this should simply be a compiler
error. I don't know what the spec says about this. It will just
compile fine on openjdk 8 (I got a package error trying to
install 9 on my system, hence I am using 8 for (this) now).
<br>
<br>
Basically I wonder if the spec allows this, or whether this is a
compiler error.
</div>
</blockquote>
<br>
</body>
</html>