[concurrency-interest] Exception throw but not speficied in the method contract of its interface

Hanson Char hanson_char@yahoo.com
Sun, 10 Oct 2004 19:13:18 -0700 (PDT)


--0-1274512958-1097460798=:45844
Content-Type: text/plain; charset=us-ascii

>...the supertype explicitly allows for an
>exception to be thrown, it just doesn't specify exactly what kind.
 
Doesn't the contract in such case imply a kind of Runtime (ie unchecked) exception  to be thrown ?

H

David Holmes <dholmes@dltech.com.au> wrote:
> Jean Morissette writes:
>
> the method add(Object) of class AbstractQueue can throw an
> IllegalStateException that is not specified in the contract of its
> interface Collection. Is-it normal?

If you look at the specification for Collection.add it states:

"If a collection refuses to add a particular element for any reason other
than that it already contains the element, it must throw an exception
(rather than returning false). "

And this is exactly what AbstractQueue does - and what AbstractQueue
documents that it does.

While unchecked exceptions can always be thrown by an implementation, that
doesn't give an implementation the right to throw any unchecked exception
under any circumstance - proper subtyping requires adherence to the contract
of the supertype. But in this case the supertype explicitly allows for an
exception to be thrown, it just doesn't specify exactly what kind.

David Holmes

_______________________________________________
Concurrency-interest mailing list
Concurrency-interest@altair.cs.oswego.edu
http://altair.cs.oswego.edu/mailman/listinfo/concurrency-interest

		
---------------------------------
Do you Yahoo!?
vote.yahoo.com - Register online to vote today!
--0-1274512958-1097460798=:45844
Content-Type: text/html; charset=us-ascii

<DIV>&gt;...the supertype explicitly allows for an</DIV>
<DIV>&gt;exception to be thrown, it just doesn't specify exactly what kind.</DIV>
<DIV>&nbsp;</DIV>
<DIV>Doesn't the contract in such case imply a kind of Runtime (ie unchecked) exception&nbsp; to be thrown ?<BR></DIV>
<DIV>H<BR><BR><B><I>David Holmes &lt;dholmes@dltech.com.au&gt;</I></B> wrote:</DIV>
<BLOCKQUOTE class=replbq style="PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #1010ff 2px solid">&gt; Jean Morissette writes:<BR>&gt;<BR>&gt; the method add(Object) of class AbstractQueue can throw an<BR>&gt; IllegalStateException that is not specified in the contract of its<BR>&gt; interface Collection. Is-it normal?<BR><BR>If you look at the specification for Collection.add it states:<BR><BR>"If a collection refuses to add a particular element for any reason other<BR>than that it already contains the element, it must throw an exception<BR>(rather than returning false). "<BR><BR>And this is exactly what AbstractQueue does - and what AbstractQueue<BR>documents that it does.<BR><BR>While unchecked exceptions can always be thrown by an implementation, that<BR>doesn't give an implementation the right to throw any unchecked exception<BR>under any circumstance - proper subtyping requires adherence to the contract<BR>of the supertype. But in this case the supertype explicitly allows
 for an<BR>exception to be thrown, it just doesn't specify exactly what kind.<BR><BR>David Holmes<BR><BR>_______________________________________________<BR>Concurrency-interest mailing list<BR>Concurrency-interest@altair.cs.oswego.edu<BR>http://altair.cs.oswego.edu/mailman/listinfo/concurrency-interest<BR></BLOCKQUOTE><p>
		<hr size=1>Do you Yahoo!?<br><a
href="http://vote.yahoo.com">vote.yahoo.com</a> - Register online to vote today!
--0-1274512958-1097460798=:45844--