Bug 572994

Summary: Compiler does not report an error on instantiating nonstatic inner class from static context which breaks JVM
Product: [Eclipse Project] JDT Reporter: Marko Čupić <Marko.Cupic>
Component: CoreAssignee: Manoj N Palat <manoj.palat>
Status: VERIFIED FIXED QA Contact:
Severity: major    
Priority: P3 CC: jarthana, manoj.palat, sravankumarl
Version: 4.19Keywords: regression
Target Milestone: 4.20 M3   
Hardware: PC   
OS: Linux   
See Also: https://git.eclipse.org/r/c/jdt/eclipse.jdt.core/+/179871
https://git.eclipse.org/c/jdt/eclipse.jdt.core.git/commit/?id=d21d83fa5b10b0212b45e0894a4a64a2dd28e947
https://git.eclipse.org/r/c/jdt/eclipse.jdt.core/+/179922
Whiteboard:

Description Marko Čupić CLA 2021-04-20 03:53:28 EDT
The following:

public class Demo {

	public class Singleton {
		private static Singleton pinstance = new Singleton();
		public static Singleton instance() {
			return pinstance;
		}
		public String message() {
			return "Hello world!";
		}
	}
	
	public static void main(String[] args) {
		System.out.println(Singleton.instance().message());
	}
}

compiles fine in eclipse but JVM chrashes when the program is run:

Exception in thread "main" java.lang.VerifyError: Bad local variable type
Exception Details:
  Location:
    Demo$Singleton.<clinit>()V @4: aload_1
  Reason:
    Type top (current frame, locals[1]) is not assignable to reference type
  Current Frame:
    bci: @4
    flags: { }
    locals: { }
    stack: { uninitialized 0, uninitialized 0 }
  Bytecode:
    0000000: bb00 0159 2bb7 000c b300 10b1          

	at Demo.main(Demo.java:15)

Oracle's compiler (javac) run from command line correctly reports an error:

Demo.java:5: error: non-static variable this cannot be referenced from a static context
		private static Singleton pinstance = new Singleton();

OS is Linux 5.8.0-50-generic #56~20.04.1-Ubuntu SMP Mon Apr 12 21:46:35 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux
Comment 1 Manoj N Palat CLA 2021-04-22 12:06:04 EDT
keeping in the radar for 4.20
Comment 2 Manoj N Palat CLA 2021-04-23 02:19:24 EDT
This works in 4.19, so its a regression in 4.20 - marking so.
Comment 3 Eclipse Genie CLA 2021-04-27 08:56:16 EDT
New Gerrit change created: https://git.eclipse.org/r/c/jdt/eclipse.jdt.core/+/179871
Comment 5 Eclipse Genie CLA 2021-04-28 10:39:57 EDT
New Gerrit change created: https://git.eclipse.org/r/c/jdt/eclipse.jdt.core/+/179922
Comment 6 Jay Arthanareeswaran CLA 2021-05-18 05:46:17 EDT
Verified for 4.20 M3 using build I20210517-0600.