You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@harmony.apache.org by Sian January <si...@googlemail.com> on 2007/01/08 11:23:38 UTC

[classlib] [luni] Ignored Exceptions and HARMONY-2939

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.  Details at
https://issues.apache.org/jira/browse/HARMONY-2939.

Thanks,

Sian

-- 
Sian January

IBM Java Technology Centre, UK

Re: [classlib] [luni] Ignored Exceptions and HARMONY-2939

Posted by Andrew Zhang <zh...@gmail.com>.
On 1/8/07, Sian January <si...@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 {
                sm.checkPermission(result.openConnection().getPermission());
            } catch (IOException e) {
                return null;
            } catch (SecurityException e) {
                return null;
            }
So it's easy to mock a security manager to disable
"result.openConnection().getPermission()",
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
reference.

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

Re: [classlib] [luni] Ignored Exceptions and HARMONY-2939

Posted by Tony Wu <wu...@gmail.com>.
On 1/10/07, Sian January <si...@googlemail.com> wrote:
> Hi Tony,
>
> When I run this testcase with the RI I do see a SecurityException, but it's
> thrown from the call to new SecurityManager() on the last line of the test()
> method (and not the call to ucl.findResources("test.txt");).  So unless I'm
> doing something wrong it looks like the inconsistency between Harmony and
> the RI is not in the findResources method.
>

Oh, yes, you are right, that's another difference from RI. sorry for
inconvenience caused.

> Thanks,
>
> Sian
>
>
> On 09/01/07, Tony Wu <wu...@gmail.com> wrote:
> >
> > I just scratched a testcase. It does cause a SecurityException on RI
> > whereas passes on Harmony. I post it below. Hope it could do some
> > help. bedtime ;-)
> >
> > public class Harmony2939 extends TestCase {
> >    public void test() throws IOException {
> >        URL[] urls = new URL[1];
> >        File dir = File.createTempFile("hytemp", "");
> >        dir.delete();
> >        dir.mkdir();
> >        File file = new File(dir.getPath() + "/test.txt");
> >        file.createNewFile();
> >        urls[0] = new URL("file:///" + dir.getPath()+"/");
> >        assertTrue(new File("/"+file.getAbsolutePath()).exists());
> >        URLClassLoader ucl = URLClassLoader.newInstance(urls);
> >        SecurityManager sm = new MySecurityManager(file.getPath());
> >        System.setSecurityManager(sm);
> >        ucl.findResources("test.txt");
> >        System.setSecurityManager(new SecurityManager());
> >    }
> >
> >    class MySecurityManager extends SecurityManager {
> >        private String dir;
> >        public MySecurityManager(String dir) {
> >            super();
> >            this.dir = dir;
> >        }
> >        public void checkPermission(Permission perm) {
> >            FilePermission p = new FilePermission(dir, "read");
> >            if(perm.equals(p)){
> >                throw new SecurityException();
> >            }
> >        }
> >    }
> > }
> >
> >
> > On 1/10/07, Sian January <si...@googlemail.com> wrote:
> > > Thanks Andrew and Alexey.  I tried writing a test case for the
> > > SecurityException as Andrew described and the RI does not throw an
> > > Exception, so it's definitely right that we should catch the
> > > SecurityException.  I'm still unsure about the IOException, especially
> > as
> > > the signature of the method states that an IOException is thrown, but if
> > it
> > > can't be tested then it's probably best to leave it.
> > >
> > > Sian
> > >
> > >
> > > On 09/01/07, Alexey Petrenko <al...@gmail.com> wrote:
> > > >
> > > > Sian,
> > > >
> > > > the logic looks OK for me in this method. SecurityException shows that
> > > > testing url should not be added to reduced list in this case.
> > > >
> > > > SY, Alexey
> > > >
> > > > 2007/1/8, Sian January <si...@googlemail.com>:
> > > > > 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.  Details at
> > > > > https://issues.apache.org/jira/browse/HARMONY-2939.
> > > > >
> > > > > Thanks,
> > > > >
> > > > > Sian
> > > > >
> > > > > --
> > > > > Sian January
> > > > >
> > > > > IBM Java Technology Centre, UK
> > > > >
> > > > >
> > > >
> > >
> > >
> > >
> > > --
> > > Sian January
> > >
> > > IBM Java Technology Centre, UK
> > >
> > >
> >
> >
> > --
> > Tony Wu
> > China Software Development Lab, IBM
> >
>
>
>
> --
> Sian January
>
> IBM Java Technology Centre, UK
>
>


-- 
Tony Wu
China Software Development Lab, IBM

Re: [classlib] [luni] Ignored Exceptions and HARMONY-2939

Posted by Sian January <si...@googlemail.com>.
Hi Tony,

When I run this testcase with the RI I do see a SecurityException, but it's
thrown from the call to new SecurityManager() on the last line of the test()
method (and not the call to ucl.findResources("test.txt");).  So unless I'm
doing something wrong it looks like the inconsistency between Harmony and
the RI is not in the findResources method.

Thanks,

Sian


On 09/01/07, Tony Wu <wu...@gmail.com> wrote:
>
> I just scratched a testcase. It does cause a SecurityException on RI
> whereas passes on Harmony. I post it below. Hope it could do some
> help. bedtime ;-)
>
> public class Harmony2939 extends TestCase {
>    public void test() throws IOException {
>        URL[] urls = new URL[1];
>        File dir = File.createTempFile("hytemp", "");
>        dir.delete();
>        dir.mkdir();
>        File file = new File(dir.getPath() + "/test.txt");
>        file.createNewFile();
>        urls[0] = new URL("file:///" + dir.getPath()+"/");
>        assertTrue(new File("/"+file.getAbsolutePath()).exists());
>        URLClassLoader ucl = URLClassLoader.newInstance(urls);
>        SecurityManager sm = new MySecurityManager(file.getPath());
>        System.setSecurityManager(sm);
>        ucl.findResources("test.txt");
>        System.setSecurityManager(new SecurityManager());
>    }
>
>    class MySecurityManager extends SecurityManager {
>        private String dir;
>        public MySecurityManager(String dir) {
>            super();
>            this.dir = dir;
>        }
>        public void checkPermission(Permission perm) {
>            FilePermission p = new FilePermission(dir, "read");
>            if(perm.equals(p)){
>                throw new SecurityException();
>            }
>        }
>    }
> }
>
>
> On 1/10/07, Sian January <si...@googlemail.com> wrote:
> > Thanks Andrew and Alexey.  I tried writing a test case for the
> > SecurityException as Andrew described and the RI does not throw an
> > Exception, so it's definitely right that we should catch the
> > SecurityException.  I'm still unsure about the IOException, especially
> as
> > the signature of the method states that an IOException is thrown, but if
> it
> > can't be tested then it's probably best to leave it.
> >
> > Sian
> >
> >
> > On 09/01/07, Alexey Petrenko <al...@gmail.com> wrote:
> > >
> > > Sian,
> > >
> > > the logic looks OK for me in this method. SecurityException shows that
> > > testing url should not be added to reduced list in this case.
> > >
> > > SY, Alexey
> > >
> > > 2007/1/8, Sian January <si...@googlemail.com>:
> > > > 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.  Details at
> > > > https://issues.apache.org/jira/browse/HARMONY-2939.
> > > >
> > > > Thanks,
> > > >
> > > > Sian
> > > >
> > > > --
> > > > Sian January
> > > >
> > > > IBM Java Technology Centre, UK
> > > >
> > > >
> > >
> >
> >
> >
> > --
> > Sian January
> >
> > IBM Java Technology Centre, UK
> >
> >
>
>
> --
> Tony Wu
> China Software Development Lab, IBM
>



-- 
Sian January

IBM Java Technology Centre, UK

Re: [classlib] [luni] Ignored Exceptions and HARMONY-2939

Posted by Tony Wu <wu...@gmail.com>.
I just scratched a testcase. It does cause a SecurityException on RI
whereas passes on Harmony. I post it below. Hope it could do some
help. bedtime ;-)

public class Harmony2939 extends TestCase {
    public void test() throws IOException {
        URL[] urls = new URL[1];
        File dir = File.createTempFile("hytemp", "");
        dir.delete();
        dir.mkdir();
        File file = new File(dir.getPath() + "/test.txt");
        file.createNewFile();
        urls[0] = new URL("file:///" + dir.getPath()+"/");
        assertTrue(new File("/"+file.getAbsolutePath()).exists());
        URLClassLoader ucl = URLClassLoader.newInstance(urls);
        SecurityManager sm = new MySecurityManager(file.getPath());
        System.setSecurityManager(sm);
        ucl.findResources("test.txt");
        System.setSecurityManager(new SecurityManager());
    }

    class MySecurityManager extends SecurityManager {
        private String dir;
        public MySecurityManager(String dir) {
            super();
            this.dir = dir;
        }
        public void checkPermission(Permission perm) {
            FilePermission p = new FilePermission(dir, "read");
            if(perm.equals(p)){
                throw new SecurityException();
            }
        }
    }
}


On 1/10/07, Sian January <si...@googlemail.com> wrote:
> Thanks Andrew and Alexey.  I tried writing a test case for the
> SecurityException as Andrew described and the RI does not throw an
> Exception, so it's definitely right that we should catch the
> SecurityException.  I'm still unsure about the IOException, especially as
> the signature of the method states that an IOException is thrown, but if it
> can't be tested then it's probably best to leave it.
>
> Sian
>
>
> On 09/01/07, Alexey Petrenko <al...@gmail.com> wrote:
> >
> > Sian,
> >
> > the logic looks OK for me in this method. SecurityException shows that
> > testing url should not be added to reduced list in this case.
> >
> > SY, Alexey
> >
> > 2007/1/8, Sian January <si...@googlemail.com>:
> > > 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.  Details at
> > > https://issues.apache.org/jira/browse/HARMONY-2939.
> > >
> > > Thanks,
> > >
> > > Sian
> > >
> > > --
> > > Sian January
> > >
> > > IBM Java Technology Centre, UK
> > >
> > >
> >
>
>
>
> --
> Sian January
>
> IBM Java Technology Centre, UK
>
>


-- 
Tony Wu
China Software Development Lab, IBM

Re: [classlib] [luni] Ignored Exceptions and HARMONY-2939

Posted by Sian January <si...@googlemail.com>.
Thanks Andrew and Alexey.  I tried writing a test case for the
SecurityException as Andrew described and the RI does not throw an
Exception, so it's definitely right that we should catch the
SecurityException.  I'm still unsure about the IOException, especially as
the signature of the method states that an IOException is thrown, but if it
can't be tested then it's probably best to leave it.

Sian


On 09/01/07, Alexey Petrenko <al...@gmail.com> wrote:
>
> Sian,
>
> the logic looks OK for me in this method. SecurityException shows that
> testing url should not be added to reduced list in this case.
>
> SY, Alexey
>
> 2007/1/8, Sian January <si...@googlemail.com>:
> > 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.  Details at
> > https://issues.apache.org/jira/browse/HARMONY-2939.
> >
> > Thanks,
> >
> > Sian
> >
> > --
> > Sian January
> >
> > IBM Java Technology Centre, UK
> >
> >
>



-- 
Sian January

IBM Java Technology Centre, UK

Re: [classlib] [luni] Ignored Exceptions and HARMONY-2939

Posted by Tony Wu <wu...@gmail.com>.
On 1/10/07, Alexey Petrenko <al...@gmail.com> wrote:
> 2007/1/9, Tony Wu <wu...@gmail.com>:
> > Does it make sense?
> > I think the code below does nothing...
> >
> > try {
> > sm.checkPermission(url.openConnection().getPermission());
> > } catch (SecurityException e) {
> > }
> >
> > If access is not permitted based on the current security policy, then
> > it will throw a SecurityException. So if you want to ignore the
> > exception, why to call the checkPermission?
> The original piece of code is
> try {
>    sm.checkPermission(url.openConnection().getPermission());
>    reduced.addElement(url);
> } catch (IOException e) {
> } catch (SecurityException e) {
> }
>
> So the url is added to reduced list only if connection has opened OK
> and security checks has passed.
>

hmm,, the original piece is reasonable. Thanks for explanation.

> SY, Alexey
>
> >
> > On 1/9/07, Alexey Petrenko <al...@gmail.com> wrote:
> > > Sian,
> > >
> > > the logic looks OK for me in this method. SecurityException shows that
> > > testing url should not be added to reduced list in this case.
> > >
> > > SY, Alexey
> > >
> > > 2007/1/8, Sian January <si...@googlemail.com>:
> > > > 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.  Details at
> > > > https://issues.apache.org/jira/browse/HARMONY-2939.
> > > >
> > > > Thanks,
> > > >
> > > > Sian
> > > >
> > > > --
> > > > Sian January
> > > >
> > > > IBM Java Technology Centre, UK
> > > >
> > > >
> > >
> >
> >
> > --
> > Tony Wu
> > China Software Development Lab, IBM
> >
>


-- 
Tony Wu
China Software Development Lab, IBM

Re: [classlib] [luni] Ignored Exceptions and HARMONY-2939

Posted by Alexey Petrenko <al...@gmail.com>.
2007/1/9, Tony Wu <wu...@gmail.com>:
> Does it make sense?
> I think the code below does nothing...
>
> try {
> sm.checkPermission(url.openConnection().getPermission());
> } catch (SecurityException e) {
> }
>
> If access is not permitted based on the current security policy, then
> it will throw a SecurityException. So if you want to ignore the
> exception, why to call the checkPermission?
The original piece of code is
try {
    sm.checkPermission(url.openConnection().getPermission());
    reduced.addElement(url);
} catch (IOException e) {
} catch (SecurityException e) {
}

So the url is added to reduced list only if connection has opened OK
and security checks has passed.

SY, Alexey

>
> On 1/9/07, Alexey Petrenko <al...@gmail.com> wrote:
> > Sian,
> >
> > the logic looks OK for me in this method. SecurityException shows that
> > testing url should not be added to reduced list in this case.
> >
> > SY, Alexey
> >
> > 2007/1/8, Sian January <si...@googlemail.com>:
> > > 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.  Details at
> > > https://issues.apache.org/jira/browse/HARMONY-2939.
> > >
> > > Thanks,
> > >
> > > Sian
> > >
> > > --
> > > Sian January
> > >
> > > IBM Java Technology Centre, UK
> > >
> > >
> >
>
>
> --
> Tony Wu
> China Software Development Lab, IBM
>

Re: [classlib] [luni] Ignored Exceptions and HARMONY-2939

Posted by Tony Wu <wu...@gmail.com>.
Does it make sense?
I think the code below does nothing...

try {
sm.checkPermission(url.openConnection().getPermission());
} catch (SecurityException e) {
}

If access is not permitted based on the current security policy, then
it will throw a SecurityException. So if you want to ignore the
exception, why to call the checkPermission?

On 1/9/07, Alexey Petrenko <al...@gmail.com> wrote:
> Sian,
>
> the logic looks OK for me in this method. SecurityException shows that
> testing url should not be added to reduced list in this case.
>
> SY, Alexey
>
> 2007/1/8, Sian January <si...@googlemail.com>:
> > 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.  Details at
> > https://issues.apache.org/jira/browse/HARMONY-2939.
> >
> > Thanks,
> >
> > Sian
> >
> > --
> > Sian January
> >
> > IBM Java Technology Centre, UK
> >
> >
>


-- 
Tony Wu
China Software Development Lab, IBM

Re: [classlib] [luni] Ignored Exceptions and HARMONY-2939

Posted by Alexey Petrenko <al...@gmail.com>.
Sian,

the logic looks OK for me in this method. SecurityException shows that
testing url should not be added to reduced list in this case.

SY, Alexey

2007/1/8, Sian January <si...@googlemail.com>:
> 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.  Details at
> https://issues.apache.org/jira/browse/HARMONY-2939.
>
> Thanks,
>
> Sian
>
> --
> Sian January
>
> IBM Java Technology Centre, UK
>
>