You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by "Dmitry M. Kononov (JIRA)" <ji...@apache.org> on 2006/05/03 14:07:50 UTC

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

[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
    Priority: Minor


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


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

Posted by "George Harley (JIRA)" <ji...@apache.org>.
    [ http://issues.apache.org/jira/browse/HARMONY-436?page=comments#action_12378955 ] 

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

Hi Dmitry, 

Thanks for your response. I'm not sure that I feel happy using details of the RI internals (i.e. the stack trace information) as the basis for this discussion. In my heart I feel that we should do as the RI does for all of the cases mentioned in this issue. Because we agreed on the list a while ago that we would discuss such matters on a case by case basis I would like to move this discussion on to the dev list. 

When I get a few moments I will write an append to the dev list summarising our discussion here, probably copying a few paragraphs, and ask for the community view. That way we can *all* work this out and firm up our guidelines on compatibility at the same time. 

Best regards, 
George

> [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


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

Posted by "Nathan Beyer (JIRA)" <ji...@apache.org>.
    [ http://issues.apache.org/jira/browse/HARMONY-436?page=comments#action_12378544 ] 

Nathan Beyer commented on HARMONY-436:
--------------------------------------

Most of the items pointed out for StringBuilder have TODO and FIXME comments in the test case that discuss these [1]. There are a number of places that the specification doesn't say it throw NPEs, but the assumption is that it will and all of the exceptions were matched based on testing the RI. I wrote much of the StringBuilder code, and in cases where the spec wasn't clear or the RI was contradictory, I tried to make the behavior consistent with how similar StringBuffer and String APIs worked.

As an aside to this, in cases where the RI spec isn't documented completely, if Harmony code implements it, then it should be documented in Harmony javadoc.

As for the actual patch, I disagree with most of it. Here are some specifics:
* Changing SIOOBE to IOOBE for StringBuilder#insert(int,char) is contradictory to all of the other StringBuilder#insert methods, which throw SIOOBE. The code abides by the specification. Also, if you look at StringBuffer's insert methods, this same documentation inconsistency exists there too.
* In the StringBuffer change of SIOOBE to IOOBE, the last change drops the index value from being passed to the exception.

What's the real value of these changes? The code already meets the specifications and the compatability guidelines. The explicit null checks are okay, but if we're going to do this for StringBuffer, then we should do this throughout the class.

-Nathan

[1] http://svn.apache.org/viewcvs.cgi/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/tests/java/lang/StringBuilderTest.java?view=markup

> [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


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

Posted by "George Harley (JIRA)" <ji...@apache.org>.
     [ http://issues.apache.org/jira/browse/HARMONY-436?page=all ]
     
George Harley resolved HARMONY-436:
-----------------------------------

    Resolution: Fixed

Hi Dmitry, 

Modified version of your patch committed in revision 406614. As discussed on the dev list the agreed project approach to exception throwing compatibility is to throw the same runtime class (or a subclass of) as the RI. I have updated your proposed changes accordingly. Please could you verify that you are happy with what I have done.  

With regards to the unit test changes, I did not add in your StringBufferTest::test_insert$CII() method as it was not actually testing any insert(..) method of StringBuffer. It's implementation appeared to be a copy of one of your other new test methods, StringBufferTest::test_append$CII_2(). Perhaps you are planning other enhancements in this area and the current patch inadvertantly included some work in progress ?

Many thanks for highlighting this incompatibility issue and for your enhancements. 

Best regards, 
George

> [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


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

Posted by "George Harley (JIRA)" <ji...@apache.org>.
     [ http://issues.apache.org/jira/browse/HARMONY-436?page=all ]

George Harley reassigned HARMONY-436:
-------------------------------------

    Assign To: George Harley

> [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


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

Posted by "George Harley (JIRA)" <ji...@apache.org>.
    [ http://issues.apache.org/jira/browse/HARMONY-436?page=comments#action_12402287 ] 

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

Issue discussed on dev mailing list [1]. Consensus is to match runtime class (or subtype of that runtime class) of exception thrown by RI. I will proceed with a modified form of Dmitry's original patch. 

Best regards, 
George

[1] http://mail-archives.apache.org/mod_mbox/incubator-harmony-dev/200605.mbox/%3c44622BCE.2050109@googlemail.com%3e

> [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


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

Posted by "Dmitry M. Kononov (JIRA)" <ji...@apache.org>.
     [ http://issues.apache.org/jira/browse/HARMONY-436?page=all ]

Dmitry M. Kononov updated HARMONY-436:
--------------------------------------

    Attachment: lang.cumulative.diff

patch: a fix and unit tests

> [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
>     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


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

Posted by "George Harley (JIRA)" <ji...@apache.org>.
    [ 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


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

Posted by "George Harley (JIRA)" <ji...@apache.org>.
    [ http://issues.apache.org/jira/browse/HARMONY-436?page=comments#action_12378590 ] 

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

Hi Nathan, 

The RI Javadoc for StringBuilder#insert(int, char) is somewhat different than for the other versions of insert(..). You're right that almost all of the others are spec'd to throw a SIOOBE but insert(int, char) actually specifies an IOOBE. The behaviour of the RI is to throw an AIOOBE. Of course, AIOOBE and SIOOBE are both types of IOOBE so, in a way, they are both right but the fact remains that currently Harmony is throwing a different runtime type of IOOBE than that of the RI.

Here is what the compatibility guideleines [1] says on exception throwing ...

"The Harmony class libary code aims to be fully compatible with the Reference Implementation (RI) of the Java Specification by matching the exception characteristics of each method... Harmony class library code should throw exceptions of the same type as the RI, other than in cases 
where the RI throws non-public types whereupon Harmony will throw an exception with the same public supertype."

In summary, these methods are exhibiting exception throwing behaviour contrary to the existing class library compatibility guidelines. That's why I welcome Dmitry opening the issue but not all of the solution.

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


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

Posted by "George Harley (JIRA)" <ji...@apache.org>.
     [ http://issues.apache.org/jira/browse/HARMONY-436?page=all ]
     
George Harley closed HARMONY-436:
---------------------------------


Verified by Dmitry. 

> [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


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

Posted by "Dmitry M. Kononov (JIRA)" <ji...@apache.org>.
    [ http://issues.apache.org/jira/browse/HARMONY-436?page=comments#action_12378895 ] 

Dmitry M. Kononov commented on HARMONY-436:
-------------------------------------------

Hi George,

Thank you for pointing this out. I will explain my thoughts about these issues a little.

StringBuffer.append(char[], int, int)

The spec is not as clear in this case as it might be. You are correct it does not mention about any exception in the description of this method. However, it reads

"The overall effect is exactly as if the arguments were converted to a string by the method String.valueOf(char[],int,int) and the characters of that string were then appended to this character sequence."

That is, it shows implicitly how this method should behave. The spec of the mentioned String.valueOf(char[],int,int) method says that it throws the IndexOutOfBoundsException.
This is why I think we need to throw an exception from this method. Why this exception is IndexOutOfBoundsException instead of ArrayIndexOutOfBoundsException please read below.

All these issues except #3 have the same reason to change StringIndexOutOfBoundsException with IndexOutOfBoundsException.
RI throws ArrayIndexOutOfBoundsException indirectly from the System.arraycopy() method. That is, this exception class is defined by the certain implementation that uses the System.arraycopy() method.

Here is a stack trace which is typical for all the issues.
--
.java.lang.ArrayIndexOutOfBoundsException
	at java.lang.System.arraycopy(Native Method)
	at java.lang.AbstractStringBuilder.insert(Unknown Source)
	at java.lang.StringBuffer.insert(Unknown Source)
	at StringBufferTest.test_insert_int_char(StringBufferTest.java:12)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
	at java.lang.reflect.Method.invoke(Unknown Source)
	at junit.framework.TestCase.runTest(TestCase.java:154)
	at junit.framework.TestCase.runBare(TestCase.java:127)
	at junit.framework.TestResult$1.protect(TestResult.java:106)
	at junit.framework.TestResult.runProtected(TestResult.java:124)
	at junit.framework.TestResult.run(TestResult.java:109)
	at junit.framework.TestCase.run(TestCase.java:118)
	at junit.framework.TestSuite.runTest(TestSuite.java:208)
	at junit.framework.TestSuite.run(TestSuite.java:203)
	at junit.textui.TestRunner.doRun(TestRunner.java:116)
	at junit.textui.TestRunner.start(TestRunner.java:172)
	at junit.textui.TestRunner.main(TestRunner.java:138)
--

I thought we can not throw ArrayIndexOutOfBoundsException, since we have another implementation, where we check the given parameters and throw an exception explicitly.

For example, let's look at the following method.

public synchronized StringBuffer insert(int index, char ch) {
	if (0 <= index && index <= count) {
		move(1, index);
		value[index] = ch;
		count++;
		return this;
	}
	throw new StringIndexOutOfBoundsException(index);
}

The spec gives us the unambiguous instruction to throw IndexOutOfBoundsException. ArrayIndexOutOfBoundsException will look oddity here, won't it?

The next question is why we throw StringIndexOutOfBoundsException in spite of the spec directions? I guess, the reason is to make things better than the spec does. Actually, there are a lot of reasons, since the java documentation is often unclear and contradictory.

Anyway, I see your point of view (I see mine either. :). I agree with your objections and I am ready to change the patch appropriately.

Do you think we should fix issue #3 only?

Thanks.

> [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


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

Posted by "Dmitry M. Kononov (JIRA)" <ji...@apache.org>.
    [ http://issues.apache.org/jira/browse/HARMONY-436?page=comments#action_12402301 ] 

Dmitry M. Kononov commented on HARMONY-436:
-------------------------------------------

Hi George,

I have verified the changes; everything works well.

> Perhaps you are planning other enhancements in this area and the current patch inadvertantly included some work in progress ?

No, it is just my fault, sorry.

Thank you for great job!


> [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