JDK-8146062 : No compilation error when trying to compile nested inner classes
  • Type: Bug
  • Component: tools
  • Sub-Component: javac
  • Affected Version: 8u45
  • Priority: P4
  • Status: Resolved
  • Resolution: Not an Issue
  • OS: windows_8
  • CPU: x86
  • Submitted: 2015-12-10
  • Updated: 2016-05-26
  • Resolved: 2016-05-26
Related Reports
Relates :  
Description
FULL PRODUCT VERSION :
java version "1.8.0_45"
Java(TM) SE Runtime Environment (build 1.8.0_45-b15)
Java HotSpot(TM) 64-Bit Server VM (build 25.45-b02, mixed mode)

ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows [vers��o 6.3.9600]
Windows 8.1 64bits pt-br

EXTRA RELEVANT SYSTEM CONFIGURATION :
Hardware: Intel Core i5-2410M 2.3 GHz

A DESCRIPTION OF THE PROBLEM :
The following program presents no compilation error when compiling in Oracle JDK but it must not be compilable.

Program

	public class A {
		public class B extends A {
			public class C extends B {}
		}
	}


STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Save above program into a file called A.java and try to execute javac compiler.

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Compilation error: No enclosing instance of type A is available due to some intermediate constructor invocation
ACTUAL -
No compilation errors.

REPRODUCIBILITY :
This bug can be reproduced always.


Comments
Eclipse is complaining about the 'super' call in the default constructor of C. This can be made clear by writing out the default constructors: class A { public A() { super(); } class B extends A { public B() { super(); } class C extends B { public C() { super(); } // <--- error occurs here } } } The error suggests there is no available enclosing instance, when in fact there are multiple candidates: both 'B.this' and 'A.this' will work. The search for the right enclosing instance is a bit unclear (see JDK-8157994), but it should succeed. So: this is a bug in Eclipse, not javac.
26-05-2016

I don't see any circularity with this example; in fact something like the following: class A { class B extends A { class C extends B { void m() { System.out.println("Hello!"); } } } public static void main(String[] args) { A a = new A(); B b = a.new B(); B.C c = b.new C(); c.m(); } } does indeed work. Perhaps the confusion here is that member classes B and C have both an enclosing instance of type A and a superclass A - but note that the super object and the enclosing object are not the same object.
04-01-2016

Eclipse reports it as compiler error "No enclosing instance of type A is available due to some intermediate constructor invocation", where as javac compiler compiles properly. Verified in the below versions 7uxx - Fail (All the versions of 7) 8uxx - Fail (All versions of 8) 9 ea build 95 - Fail 9 ea build 96 - Fail Forwarding for dev teams review.
23-12-2015