Bug 15501 - GCJ incorrectly implements Section 15.9.5.1, "Anonymous Constructors"
Summary: GCJ incorrectly implements Section 15.9.5.1, "Anonymous Constructors"
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: java (show other bugs)
Version: 3.4.0
: P2 normal
Target Milestone: 4.3.0
Assignee: Not yet assigned to anyone
URL:
Keywords: rejects-valid
Depends on: 28067
Blocks:
  Show dependency treegraph
 
Reported: 2004-05-17 19:41 UTC by Vadim Nasardinov
Modified: 2007-01-09 20:46 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail: 4.0.0 3.4.0 3.3.3
Last reconfirmed: 2004-12-09 00:38:49


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Vadim Nasardinov 2004-05-17 19:41:05 UTC
GCJ seems to incorrectly implement the following section of the Java
Language Specification:

15.9.5.1 Anonymous Constructors
http://java.sun.com/docs/books/jls/second_edition/html/expressions.doc.html#253002

  "In all cases, the throws clause of an anonymous constructor must
  list all the checked exceptions thrown by the explicit superclass
  constructor invocation statement contained within the anonymous
  constructor, and all checked exceptions thrown by any instance
  initializers or instance variable initializers of the anonymous
  class."

Note that the offending file Test.java compiles fine with Sun's javac.

Here's what I get with GCJ:

$ cat Test.java 
import java.io.IOException;

public class Test {

    public Test() throws IOException {
        throw new IOException("could be any checked exception");
    }

    public void doStuff() {}

    public void blowUp() throws Exception {
        new Test() {}.doStuff();
    }
}
$ gcj -v -save-temps -C Test.java 
Reading specs from /usr/lib/gcc-lib/i386-redhat-linux/3.3.3/specs
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man \
--infodir=/usr/share/info --enable-shared --enable-threads=posix \
--disable-checking --disable-libunwind-exceptions --with-system-zlib \
--enable-__cxa_atexit --host=i386-redhat-linux
Thread model: posix
gcc version 3.3.3 20040412 (Red Hat Linux 3.3.3-7)
 /usr/lib/gcc-lib/i386-redhat-linux/3.3.3/jc1 Test.java -quiet \
 -dumpbase Test.java -auxbase-strip NONE -g1 -version -fsyntax-only \
 -femit-class-files -o Test

GNU Java version 3.3.3 20040412 (Red Hat Linux 3.3.3-7) (i386-redhat-linux)
        compiled by GNU C version 3.3.3 20040412 (Red Hat Linux 3.3.3-7).
GGC heuristics: --param ggc-min-expand=98 --param ggc-min-heapsize=129024
Class path starts here:
    ./
    /usr/share/java/libgcj-3.3.3.jar/ (system) (zip)
Test.java: In class `Test$1':
Test.java: In constructor `(Test)':
Test.java:14: error: Exception `java.io.IOException' must be caught, \
or it must be declared in the `throws' clause of `Test$1'.

   }
   ^
1 error
$ ls -l
total 12
-rw-rw-r--    1 vadim    vadim           0 May 17 15:31 Test
-rw-rw-r--    1 vadim    vadim         244 May 17 15:31 Test$1.class
-rw-rw-r--    1 vadim    vadim         503 May 17 15:31 Test.class
-rw-rw-r--    1 vadim    vadim         276 May 17 13:09 Test.java
$ gcj34 -v -save-temps -C Test.java 
Reading specs from /usr/lib/gcc/i386-redhat-linux/3.4.0/specs
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man \
--infodir=/usr/share/info --enable-shared --enable-threads=posix \
--disable-checking --with-system-zlib --enable-__cxa_atexit \
--disable-libunwind-exceptions --enable-languages=c,c++,objc,java,f77 \
--host=i386-redhat-linux

Thread model: posix
gcc version 3.4.0 (Red Hat Linux 3.4.0-1)
 /usr/libexec/gcc/i386-redhat-linux/3.4.0/jc1 Test.java -quiet \
 -dumpbase Test.java -auxbase-strip NONE -g1 -version -fsyntax-only \
 -femit-class-files -o Test

GNU Java version 3.4.0 (Red Hat Linux 3.4.0-1) (i386-redhat-linux)
        compiled by GNU C version 3.4.0 (Red Hat Linux 3.4.0-1).
GGC heuristics: --param ggc-min-expand=98 --param ggc-min-heapsize=129024
Class path starts here:
    ./
    /usr/share/java/libgcj-3.4.0.jar/ (system) (zip)
Test.java: In class `Test$1':
Test.java: In constructor `(Test)':

Test.java:14: error: Exception `java.io.IOException' must be caught, \
or it must be declared in the `throws' clause of `Test$1'.
   }
   ^
1 error
$ ls -l
total 12
-rw-rw-r--    1 vadim    vadim           0 May 17 15:31 Test
-rw-rw-r--    1 vadim    vadim         244 May 17 15:31 Test$1.class
-rw-rw-r--    1 vadim    vadim         503 May 17 15:31 Test.class
-rw-rw-r--    1 vadim    vadim         276 May 17 13:09 Test.java
Comment 1 Andrew Pinski 2004-05-17 19:48:34 UTC
Confirmed
Comment 2 Bryce McKinlay 2004-06-27 00:43:33 UTC
Moving to java category, this is a compiler bug.
Comment 3 Tom Tromey 2007-01-09 20:46:07 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.