-
Bug
-
Resolution: Duplicate
-
P4
-
None
-
6
-
x86
-
linux
FULL PRODUCT VERSION :
java 1.6.0_01
javac 1.6.0_01
ADDITIONAL OS VERSION INFORMATION :
Linux apollo 2.6.21.5-apollo #2
A DESCRIPTION OF THE PROBLEM :
If I declare a final (non-static) member inside a class and I do not initialize it, I still can access it inside the constructor just before initializing it. (It has null value.)
private final String member;
<constructor>() {
if (this.member != null)
this.member = "non-null";
else
this.member = "null";
}
After creation member has the value "null"...
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
I would expect to receive a compiler error...
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
class Bug
{
public Bug() {
if (this.member != null)
this.member = "non-null";
else
this.member = "null";
}
private final String member;
public static void main(String[] arg) {
System.out.println(new Bug().member);
}
}
---------- END SOURCE ----------
java 1.6.0_01
javac 1.6.0_01
ADDITIONAL OS VERSION INFORMATION :
Linux apollo 2.6.21.5-apollo #2
A DESCRIPTION OF THE PROBLEM :
If I declare a final (non-static) member inside a class and I do not initialize it, I still can access it inside the constructor just before initializing it. (It has null value.)
private final String member;
<constructor>() {
if (this.member != null)
this.member = "non-null";
else
this.member = "null";
}
After creation member has the value "null"...
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
I would expect to receive a compiler error...
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
class Bug
{
public Bug() {
if (this.member != null)
this.member = "non-null";
else
this.member = "null";
}
private final String member;
public static void main(String[] arg) {
System.out.println(new Bug().member);
}
}
---------- END SOURCE ----------
- duplicates
-
JDK-8039026 Definitely unassigned field can be accessed
- Closed