Bug 9884 - gcj compiles code that uses non-static inner classes from static context
Summary: gcj compiles code that uses non-static inner classes from static context
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: java (show other bugs)
Version: 3.2
: P3 normal
Target Milestone: 4.3.0
Assignee: Not yet assigned to anyone
URL:
Keywords: accepts-invalid
Depends on: 28067
Blocks: 13607 18131 18728
  Show dependency treegraph
 
Reported: 2003-02-28 00:06 UTC by mjrauhal
Modified: 2007-01-09 20:45 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2005-09-30 13:33:06


Attachments

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