This is the mail archive of the java-prs@gcc.gnu.org mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug libgcj/15501] New: GCJ incorrectly implements Section 15.9.5.1, "Anonymous Constructors"


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

-- 
           Summary: GCJ incorrectly implements Section 15.9.5.1, "Anonymous
                    Constructors"
           Product: gcc
           Version: 3.4.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: libgcj
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: vadimn at redhat 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=15501


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]