The code below is invalid, but GCJ compiles it.
The resulting bytecode fails JVM verification;
the generated native executable prints a random number.

$ gcj -v
Using built-in specs.
Reading specs from /usr/local/lib/gcc/i686-pc-linux-gnu/4.0.0/../../../libgcj.
spec
rename spec lib to liborig
Target: i686-pc-linux-gnu
Configured with: ../gcc-4.0.0/configure 
Thread model: posix
gcc version 4.0.0

$ gcj Test.java --main=Main 

//////////////////////////////////////////////
/// Test.java

class Foo
{
    int N = 10;
}

class Main
{
    void printN()
    {
        System.out.println("N = " + Foo.N); // SHOULD BE AN ERROR
    }
    
    public static void main(String[] args)
    {
        Main main = new Main();
        main.printN();
    }
}

-- 
           Summary: accept-invalid: allows access to members as if they were
                    static
           Product: gcc
           Version: 4.0.0
            Status: UNCONFIRMED
          Severity: minor
          Priority: P2
         Component: java
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: i_mezhirov at yahoo dot com
                CC: gcc-bugs at gcc dot gnu dot org,java-prs at gcc dot gnu
                    dot org


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=22496

Reply via email to