directory-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Stefan Seelmann <seelm...@apache.org>
Subject Re: Swallowing Exceptions
Date Sat, 06 Mar 2010 13:25:09 GMT
Felix Knecht wrote:
> -----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)?

I think it that case we could wrap the UnsupportedEncodingException into 
a RuntimeException. We know that UTF-8 is always supported, and in case 
it is not there then something really strange is going on.

My 2 cents.
Stefan

> 
> 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