Bug 572994 - Compiler does not report an error on instantiating nonstatic inner class from static context which breaks JVM
Summary: Compiler does not report an error on instantiating nonstatic inner class from...
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 4.19   Edit
Hardware: PC Linux
: P3 major (vote)
Target Milestone: 4.20 M3   Edit
Assignee: Manoj N Palat CLA
QA Contact:
URL:
Whiteboard:
Keywords: regression
Depends on:
Blocks:
 
Reported: 2021-04-20 03:53 EDT by Marko Čupić CLA
Modified: 2021-05-18 05:46 EDT (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
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.