Hi, in the Hecl programming language, I do this: public String toString() throws HeclException { Vector v = ListThing.get(new Thing(new HashThing(val))); ListThing newthing = new ListThing(v); return newthing.toString(); } Apparently, that should generate a warning or throw an error, because toString isn't supposed to throw an exception... "regular" java says this: ./com/dedasys/hecl/HashThing.java:140: toString() in com.dedasys.hecl.HashThing cannot override toString() in java.lang.Object; overridden method does not throw com.dedasys.hecl.HeclException public String toString() throws HeclException { ^ Thanks, Dave
Confirmed, reduced self contained testcase: class t { public String toString() throws java.io.IOException {return "";} }
A patch is here: http://gcc.gnu.org/ml/java-patches/2005-q1/msg00710.html
Subject: Bug 20312 CVSROOT: /cvs/gcc Module name: gcc Changes by: rmathew@gcc.gnu.org 2005-03-10 18:40:28 Modified files: gcc/java : ChangeLog parse.y Log message: PR java/20312 * parse.y (checks_throws_clauses): Check exceptions list even when the base class does not come from a source file being compiled. (java_complete_lhs): Remove unused variable 'wfl'. Patches: http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/java/ChangeLog.diff?cvsroot=gcc&r1=1.1570&r2=1.1571 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/java/parse.y.diff?cvsroot=gcc&r1=1.529&r2=1.530
Fixed in 4.1.0 and above.
This patch can cause an ICE when the super-class is byte-compiled. If a byte-compiled method M in a super-class throws exception X, we try to emit an erroneous error message that M can't throw X (because we don't analyze the bytecode). Worse, because M doesn't have DECL_FUNCTION_WFL set, we get an ICE in parse_error_context. The problem is check_interface_throws_clauses, which seems to be doing way too much work ... it should be not be checking that "The exception must be a subclass of an exception thrown" in super-classes.
Created attachment 8697 [details] Patch to not check inappropriate methods. A tentative patch to the problem I mentioned.
In 4.3.0 this is correctly flagged as an error. With the testcase in comment #1 we get: $ gcj -o t --main=t t.java t.java:3: error: Exception IOException is not compatible with throws clause in Object.toString() public String toString() throws java.io.IOException ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 1 problem (1 error)