JDK-6583592 : Read access to uninitialized final member is allowed before initialization.
  • Type: Bug
  • Component: tools
  • Sub-Component: javac
  • Affected Version: 6
  • Priority: P4
  • Status: Resolved
  • Resolution: Duplicate
  • OS: linux
  • CPU: x86
  • Submitted: 2007-07-20
  • Updated: 2015-10-27
  • Resolved: 2015-10-27
Related Reports
Duplicate :  
Description
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 ----------

Comments
See https://bugs.openjdk.java.net/browse/JDK-8039026 and https://bugs.openjdk.java.net/browse/JDK-7004835
27-10-2015