This is the mail archive of the
gcc-prs@gcc.gnu.org
mailing list for the GCC project.
java/9884: gcj compiles code that uses non-static inner classes from static context
- From: mjrauhal at cc dot helsinki dot fi
- To: gcc-gnats at gcc dot gnu dot org
- Date: 28 Feb 2003 00:03:08 -0000
- Subject: java/9884: gcj compiles code that uses non-static inner classes from static context
- Reply-to: mjrauhal at cc dot helsinki dot fi
>Number: 9884
>Category: java
>Synopsis: gcj compiles code that uses non-static inner classes from static context
>Confidential: no
>Severity: non-critical
>Priority: medium
>Responsible: unassigned
>State: open
>Class: accepts-illegal
>Submitter-Id: net
>Arrival-Date: Fri Feb 28 00:06:00 UTC 2003
>Closed-Date:
>Last-Modified:
>Originator: Mikko Rauhala
>Release: 3.2.3
>Organization:
>Environment:
Debian GNU/Linux (unstable), recently upgraded (gcj-3.2
package version 3.2.3-0pre2).
>Description:
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
>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.
>Release-Note:
>Audit-Trail:
>Unformatted: