harmony-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Tony Wu" <wuyue...@gmail.com>
Subject Re: [general]what do you think about this kind of exception order?
Date Sat, 23 Dec 2006 04:56:38 GMT
The method name causes misunderstanding maybe. I'm talking about API
behavior. Since may methods in harmony check the parameters then throw
IllegalArgumentException before entering the critical block. But
according testing for RI, I found it may throw another Exception
before examing the arguments.

let's take JIRA-2404 as a real example. The testcase below passed on
RI whereas got IllegalArgumentException on harmony.

public void test2404() {
    try {
        PipedWriter writer= new PipedWriter();
        writer.write(new char[] { 1, 1 }, 10, 1);
        fail("IOException should be thrown");
    } catch (IOException e) {
            // expected
    }
}

then in method write, we check the IAE before all IOE. It does improve
performance but will be very hard to follow RI.
        if (0 <= offset && offset <= buffer.length && 0 <= count
                && count <= buffer.length - offset) {
            synchronized (lock) {
                if (!closed) {
                    if (dest != null) {
                        dest.receive(buffer, offset, count);
                    } else {
                        throw new IOException(Msg.getString("K007b"));
//$NON-NLS-1$
                    }
                } else {
                    throw new IOException(Msg.getString("K0078")); //$NON-NLS-1$
                }
            }
        } else {
            throw new IndexOutOfBoundsException();
        }

On 12/23/06, Geir Magnusson Jr. <geir@pobox.com> wrote:
> I don't grok.  You are talking about test behavior?  or some API
> behavior?  I'm guessing the latter.
>
> geir
>
> On Dec 22, 2006, at 11:52 AM, Tony Wu wrote:
>
> > There are two methods, which throw exceptions in different order.
> >
> > public test1(int a, int b){
> >    if(a>b){
> >        throw AException();
> >    }
> >    synchronized(obj){
> >       if(blabla){
> >           throw BException();
> >       }
> >   }
> > }
> >
> > public test2(int a, int b){
> >   synchronized(obj){
> >       if(blabla){
> >           throw BException();
> >       }
> >       if(a>b){
> >           throw AException();
> >       }
> >   }
> > }
> >
> >
> > test1 checks the parameters before entering the synchronized block, It
> > returns immediately instead of waiting for a lock in the condition
> > which should throw AException. IMHO, test1 is more elegant. The
> > problem is, if RI do something like the test2 where harmony using
> > test1, should we follow RI here? What's your opinion?
> >
> > Thanks.
> >
> > --
> > Tony Wu
> > China Software Development Lab, IBM
>
>


-- 
Tony Wu
China Software Development Lab, IBM

Mime
View raw message