Bug 20312 - No warning on bad method
Summary: No warning on bad method
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: java (show other bugs)
Version: 3.3.4
: P2 normal
Target Milestone: 4.3.0
Assignee: Not yet assigned to anyone
URL:
Keywords: accepts-invalid, patch
Depends on:
Blocks:
 
Reported: 2005-03-04 08:18 UTC by David Welton
Modified: 2007-01-30 01:53 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work: 4.3.0
Known to fail: 4.1.0
Last reconfirmed: 2005-03-04 15:04:44


Attachments
Patch to not check inappropriate methods. (919 bytes, patch)
2005-04-21 09:39 UTC, Per Bothner
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description David Welton 2005-03-04 08:18:58 UTC
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
Comment 1 Andrew Pinski 2005-03-04 15:04:43 UTC
Confirmed, reduced self contained testcase:
class t
{
  public String toString()  throws java.io.IOException
  {return "";}
}
Comment 2 Ranjit Mathew 2005-03-10 13:30:44 UTC
A patch is here:

  http://gcc.gnu.org/ml/java-patches/2005-q1/msg00710.html
Comment 3 GCC Commits 2005-03-10 18:40:36 UTC
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

Comment 4 Andrew Pinski 2005-03-10 23:35:36 UTC
Fixed in 4.1.0 and above.
Comment 5 Per Bothner 2005-04-21 09:05:14 UTC
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.
Comment 6 Per Bothner 2005-04-21 09:39:09 UTC
Created attachment 8697 [details]
Patch to not check inappropriate methods.

A tentative patch to the problem I mentioned.
Comment 7 David Daney 2007-01-30 01:53:46 UTC
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)