harmony-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Geir Magnusson Jr <g...@pobox.com>
Subject Re: More helpful error messages
Date Fri, 24 Mar 2006 17:27:40 GMT


Mark Hindess wrote:
> While reading some of the classlib code I've spotted a few examples of
> code like:
> 
>   if (A || B) throw Exception("A or B");
> 
> Please can we agree, for the sake of the sanity of those trying to
> debug code throwing exceptions like this, to split these into two
> statements:
> 
> if (A) throw Exception("A");
> if (B) throw Exception("B");

This isn't even debatable.

> 
> For instance, modules/security/src/common/javasrc/java/security/KeyStore.java,
> line 492 has:
> 
>         if ((alias == null) || (entryClass == null)) {
>             throw new NullPointerException("alias or entryClass is null");
>         }
> 
> which could be split in to two distinct cases with unambiguous messages.
> 
> Personally, I'd even split this test, from
> modules/security/src/common/javasrc/java/security/MessageDigestSpi.java:
> 
>         if ((offset < 0) || (offset + len > buf.length)) {
>             engineReset();
>             throw new DigestException("Incorrect offset or len value");
>         }
> 
> since if the first condition is true then we know for certain that the
> offset is invalid even if we'd still have to report the more ambiguous
> error for the second test.

or

   if ( A || B ) {
      engineReset();
      throw new DigestException( A ?
                 "offset incorrect  = " + offset
                 : "incorrect len value ");
}

> 
> Regards,
>  Mark.
> 
> --
> Mark Hindess <mark.hindess@googlemail.com>
> IBM Java Technology Centre, UK.
> 
> 

Mime
View raw message