directory-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Felix Knecht <fe...@otego.com>
Subject Swallowing Exceptions
Date Sat, 06 Mar 2010 13:10:11 GMT
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

IMO it's ok to return a default value in case of exception, but it's
hard to find the error if you can't find anything in the log. ( in case
of encoding exception)

Is this so on purpose or is the error logged anywhere else (not obvious
to me)?

Felix


shared-ldap/src/main/java/org/apache/directory/shared/ldap/util/StringTools.java
[3144 ff]

    public static final String utf8ToString( byte[] bytes, int start,
int length )
    {
        if ( bytes == null )
        {
            return "";
        }

        try
        {
            return new String( bytes, start, length, "UTF-8" );
        }
        catch ( UnsupportedEncodingException uee )
        {
            return "";
        }
    }


    /**
     * Return UTF-8 encoded byte[] representation of a String
     *
     * @param string The string to be transformed to a byte array
     * @return The transformed byte array
     */
    public static final byte[] getBytesUtf8( String string )
    {
        if ( string == null )
        {
            return new byte[0];
        }

        try
        {
            return string.getBytes( "UTF-8" );
        }
        catch ( UnsupportedEncodingException uee )
        {
            return new byte[]
                {};
        }
    }
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.14 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAkuSVDMACgkQ2lZVCB08qHG6KQCgsbKUAX/ny4sK6Vht0fusXd4H
dh4AoOq1KOKM6siPVeP4oakmSUqAyBVP
=MUhh
-----END PGP SIGNATURE-----

Mime
View raw message