harmony-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Andrew Zhang" <zhanghuang...@gmail.com>
Subject Re: [classlib] [luni] Ignored Exceptions and HARMONY-2939
Date Mon, 08 Jan 2007 14:59:41 GMT
On 1/8/07, Sian January <sianjanuary@googlemail.com> wrote:

> Hello everyone,
> I have recently been looking at ignored Exceptions in luni (i.e. places
> where an Exception is caught but the catch block is empty).  These are
> generally a bad idea because if an Exception does occur it is lost - the
> user doesn't see it and it's not logged anywhere either, so if it causes a
> problem in the program it is very difficult to find the root cause.
> I would like to discuss one of these in particular, in
> URLCLassLoader.findResources where an IOException and a
> SecurityException are ignored.  Since the signature of the method says
> that
> it throws an IOException (and SecurityException is a subtype of
> RuntimeException) I thought the try-catch block could probably be removed
> entirely.  However it is an API method and I am finding it difficult to
> write a test case for this because I'm not sure how to force either of
> those
> Exceptions.
> Geir suggested it might be an interesting topic for the mailing list so
> please post your thoughts.  Also if anyone knows how to write the test
> case
> that would be especially helpful.

I think it's not difficult to write test cases for SecurityException. Write
a specific security manager and set it as system security manager. For this
case, the source code is as follow:
            try {
            } catch (IOException e) {
                return null;
            } catch (SecurityException e) {
                return null;
So it's easy to mock a security manager to disable
and write a test to see whether RI returns silently or throws a security
exception. There're many similar tests already in luni module. You may take
a look at SocketTest#test_ConstructorLjava_net_Proxy_Exception() for

IOException is a bit complicated, maybe you need to mock more things. :-)

>   Details at
> https://issues.apache.org/jira/browse/HARMONY-2939.
> Thanks,
> Sian
> --
> Sian January
> IBM Java Technology Centre, UK

Best regards,
Andrew Zhang

  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message