harmony-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Mark Hindess" <mark.hind...@googlemail.com>
Subject More helpful error messages
Date Fri, 24 Mar 2006 16:35:44 GMT
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");

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.

Regards,
 Mark.

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

Mime
View raw message