gcj accepts code that uses non-static inner classes from static context. This is AFAIK illegal in Java, and Sun's compiler rejects it with the message: InnerClassBug.java:11: non-static variable this cannot be referenced from a static context InnerClass theObjectThatShouldNotBe = new InnerClass(); ^ 1 error Release: 3.2.3 Environment: Debian GNU/Linux (unstable), recently upgraded (gcj-3.2 package version 3.2.3-0pre2). How-To-Repeat: Compile the following snippet of code and run it (command: "gcj-wrapper-3.2 InnerClassBug.java && gij-3.2 InnerClassBug"): public class InnerClassBug { class InnerClass { InnerClass() { } void sayHi() { System.out.println("Hi, I'm the Object that Should Not Be."); } } public static void main(String args[]) { InnerClass theObjectThatShouldNotBe = new InnerClass(); theObjectThatShouldNotBe.sayHi(); } }
Fix: Give an error message when that kind of thing is attempted.
Confirmed on mainline (20030525).
Related to bug 12459.
All gcj front end bugs have been fixed by the gcj-eclipse branch merge. I'm mass-closing the affected PRs. If you believe one of these was closed in error, please reopen it with a note explaining why. Thanks.