Bug 9884

Summary: gcj compiles code that uses non-static inner classes from static context
Product: gcc Reporter: mjrauhal
Component: javaAssignee: Not yet assigned to anyone <unassigned>
Status: RESOLVED FIXED    
Severity: normal CC: gcc-bugs, java-prs
Priority: P3 Keywords: accepts-invalid
Version: 3.2   
Target Milestone: 4.3.0   
Host: Target:
Build: Known to work:
Known to fail: Last reconfirmed: 2005-09-30 13:33:06
Bug Depends on: 28067    
Bug Blocks: 13607, 18131, 18728    

Description mjrauhal 2003-02-28 00:06:00 UTC
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();
    }
}
Comment 1 mjrauhal 2003-02-28 00:06:00 UTC
Fix:
Give an error message when that kind of thing is attempted.
Comment 2 Andrew Pinski 2003-05-25 20:55:05 UTC
Confirmed on mainline (20030525).
Comment 3 Andrew Pinski 2004-01-07 20:10:35 UTC
Related to bug 12459.
Comment 4 Tom Tromey 2007-01-09 20:45:14 UTC
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.