You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by "George Harley (JIRA)" <ji...@apache.org> on 2006/05/08 18:41:21 UTC

[jira] Commented: (HARMONY-436) [classlib][luni] lang: Harmony should throw exceptions in a way similar to RI's one.

    [ http://issues.apache.org/jira/browse/HARMONY-436?page=comments#action_12378459 ] 

George Harley commented on HARMONY-436:
---------------------------------------

Hi Dmitry, 

Thank you for this patch. I would like to make the following comments about some of them.

As you point out, the RI Javadoc for StringBuffer.append(char[], int, int) does not mention any exception types that may be thrown from the method but the runtime behaviour of the RI is to throw an ArrayIndexOutOfBoundsException. Why do you think we should throw an IndexOutOfBoundsException ?


With regards to the following methods ...

* StringBuffer.getChars(int, int, char[], int)
* StringBuffer.insert(int, char)
* StringBuilder.insert(int, char)

... I think that we have already had the discussion ( a number of times :-) ) on the mailing list that we should attempt to match the type of exception thrown by the RI and not attempt to throw the exception supertype to meet the spec. There are also some words on the Harmony web site to this effect [1]. For each of the described failure scenarios involving these methods the RI throws an ArrayIndexOutOfBoundsException which is an IndexOutOfBoundsException through polymorphism and so satisfies the spec. I think that Harmony too should throw the ArrayIndexOutOfBoundsException too so that we match RI behaviour and satisfy the spec. 

So,  to summarise, you are absolutely correct in raising this issue because the exception throwing behaviour in the described scenarios does look to be wrong. However, my interpretation of the various mailing list discussions and the class library compatibility web page [1] means that I do not agree with all of your fix. What do you think ?

Best regards,
George

[1] http://incubator.apache.org/harmony/subcomponents/classlibrary/compat.html


> [classlib][luni] lang: Harmony should throw exceptions in a way similar to RI's one.
> ------------------------------------------------------------------------------------
>
>          Key: HARMONY-436
>          URL: http://issues.apache.org/jira/browse/HARMONY-436
>      Project: Harmony
>         Type: Bug

>   Components: Classlib
>     Reporter: Dmitry M. Kononov
>     Assignee: George Harley
>     Priority: Minor
>  Attachments: lang.cumulative.diff
>
> 1) java.lang.StringBuilder.insert(int offset, char c):
> Harmony throws StringIndexOutOfBoundsException when offset <0,
> while RI throws ArrayIndexOutOfBoundsException. 
> Specification mentions neither StringIndexOutOfBoundsException
> nor ArrayIndexOutOfBoundsException throwing, but says: 
> "Throws:
> IndexOutOfBoundsException - if the offset is invalid".
> 2) java.lang.StringBuffer.append(char[] str, int offset, int len):
> Harmony throws StringIndexOutOfBoundsException when str is not
> null, offset or/and len <0, while RI throws
> ArrayIndexOutOfBoundsException. Specification mentions neither
> StringIndexOutOfBoundsException nor
> ArrayIndexOutOfBoundsException throwing.
> 3) java.lang.StringBuffer.append(char[] str, int offset, int len):
> Harmony throws StringIndexOutOfBoundsException when str = null,
> offset or/and len <0, while RI throws NullPointerException.
> Specification mentions neither StringIndexOutOfBoundsException
> nor NullPointerException throwing.
> 4) java.lang.StringBuffer.getChars(int srcBegin,int srcEnd,char[] dst, int dstBegin):
> Harmony throws StringIndexOutOfBoundsException when dstBegin <0,
> while RI throws ArrayIndexOutOfBoundsException.
> Specification says:
> "Throws: 
> IndexOutOfBoundsException - if any of the following is true: 
> ...
> dstBegin is negative". 
> So RI does not comply with spec as well as Harmony does not comply with it.
> 5) java.lang.StringBuffer.insert(int offset, char c):
> Harmony throws StringIndexOutOfBoundsException when offset <0,
> while RI throws ArrayIndexOutOfBoundsException.
> Specification says:
> "The offset argument must be greater than or equal to 0 ... 
> Throws: 
> IndexOutOfBoundsException - if the offset is invalid."
> So RI does not comply with spec as well as Harmony does not comply with it.

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
   http://www.atlassian.com/software/jira