Hi,

Does following exception check code work?

       if (index < 0 || index >= limit || limit < 0 || limit > seq.length)
{
           throw new IndexOutOfBoundsException();
       }

The above code also throws NullPointerException if seq is null, and the
order of exception seems the same as the patch.

Does it make sense? Please correct me if I miss something. :)

Thanks!


On 8/2/06, Denis Kishenko <[EMAIL PROTECTED]> wrote:

Hi all

We have strange exceptions behavior of RI implementation of
Character.codePointAt.method.

Spec 1.5 says
public static int codePointAt(char[] a, int index, int limit)
Throws:
  NullPointerException - if a is null.
  IndexOutOfBoundsException - if the index argument is negative or
not less than the limit argument, or if the limit argument is negative
or greater than the length of the char array.

Practicallty we have

RI
Character.codePointAt(null, 6, 4) - IndexOutOfBoundsException
Character.codePointAt(null, 4, 6) - NPE
Character.codePointAt(null, 0, 0) - IndexOutOfBoundsException

Harmony
Character.codePointAt(null, 6, 4) - NPE
Character.codePointAt(null, 4, 6) - NPE
Character.codePointAt(null, 0, 0) - NPE

Should we follow RI to repeat behavior of exceptions?

2006/8/2, Nathan Beyer (JIRA) <[EMAIL PROTECTED]>:
>    [
http://issues.apache.org/jira/browse/HARMONY-1033?page=comments#action_12425114]
>
> Nathan Beyer commented on HARMONY-1033:
> ---------------------------------------
>
> This seems like an extreme edge case. The code implements the
specification and Harmony's results aren't surprising. I suggest bringing
this up on the mailing list for additional feedback, as I'm not inclined to
move forward with this change. The resulting code seems very awkward.
>
> > [classlib][lang]compatibility: expected IndexOutOfBoundsException
for  Character.codePointAt
> >
--------------------------------------------------------------------------------------------
> >
> >                 Key: HARMONY-1033
> >                 URL: http://issues.apache.org/jira/browse/HARMONY-1033
> >             Project: Harmony
> >          Issue Type: Bug
> >          Components: Classlib
> >            Reporter: Denis Kishenko
> >         Assigned To: Nathan Beyer
> >         Attachments: Character.patch, CharacterTest.patch
> >
> >
> > Specs 1.5
> > Methods throws
> >   NullPointerException - if a is null.
> >   IndexOutOfBoundsException - if offset or count is negative, or if
offset + count is larger than the length of the given array.
> > If first argument is null RI throws NPE only in the second test, it's
strange, but we have to follow.
> > public class bug9276 {
> >     public static void main (String[] args) {
> >       try {
> >               Character.codePointAt(null, 6, 4);
> >               System.err.println("failed 1");
> >       } catch (IndexOutOfBoundsException e) {
> >               System.err.println("passed 1");
> >             e.printStackTrace();
> >       } catch (Exception e) {
> >               System.err.println("failed 1");
> >             e.printStackTrace();
> >       }
> >       try {
> >               Character.codePointAt(null, 4, 6);
> >               System.err.println("failed 2");
> >       } catch (NullPointerException e) {
> >               System.err.println("passed 2");
> >             e.printStackTrace();
> >       } catch (Exception e) {
> >               System.err.println("failed 2");
> >             e.printStackTrace();
> >       }
> >       try {
> >               Character.codePointAt(null, 0, 0);
> >               System.err.println("failed 3");
> >       } catch (IndexOutOfBoundsException e) {
> >               System.err.println("passed 3");
> >             e.printStackTrace();
> >       } catch (Exception e) {
> >               System.err.println("failed 3");
> >             e.printStackTrace();
> >       }
> >   }
> >
> > }
> > Output
> > RI
--------------------------------------------------------------------
> > passed 1
> > java.lang.IndexOutOfBoundsException
> >       at java.lang.Character.codePointAt(Character.java:2400)
> >       at bug9276.main(bug9276.java:6)
> > passed 2
> > java.lang.NullPointerException
> >       at java.lang.Character.codePointAt(Character.java:2399)
> >       at bug9276.main(bug9276.java:16)
> > passed 3
> > java.lang.IndexOutOfBoundsException
> >       at java.lang.Character.codePointAt(Character.java:2400)
> >       at bug9276.main(bug9276.java:26)
> > Harmony -----------------------------------------------------------
> > failed 1
> > java.lang.NullPointerException
> >       at java.lang.Character.codePointAt(Character.java:1918)
> >       at bug9276.main(bug9276.java:6)
> > passed 2
> > java.lang.NullPointerException
> >       at java.lang.Character.codePointAt(Character.java:1918)
> >       at bug9276.main(bug9276.java:16)
> > failed 3
> > java.lang.NullPointerException
> >       at java.lang.Character.codePointAt(Character.java:1918)
> >       at bug9276.main(bug9276.java:26)
>
> --
> 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
>
>
>


--
Denis M. Kishenko
Intel Middleware Products Division

---------------------------------------------------------------------
Terms of use : http://incubator.apache.org/harmony/mailing.html
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




--
Andrew Zhang
China Software Development Lab, IBM

Reply via email to