[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[news.eclipse.tools] Re: [ANT]Cannot ignore Unreachable Code

Very Strange, By all accounts you are correct
AccessController.doPrivileged(PrivilegedExceptionAction) only throws a
PrivilegedActionException, which wrappers the exception returned by run().
So the second catch is never reached.

I compiled with both SUN J2SE build 1.4.1_01-b01 and IBM J2SE 1.4.0
cn140-20020902  Javac and decompiled with JAD to see if any optimization was
done. Nope, both completely ignored the fact the the second catch was
unreachable. Only the JDTCompilerAdapter caught this. Unless I am studying
this wrong???...

I was able to remove the second catch and move the code into the first
catch, and it seems to work as designed.

Thanks

Mike C.


"Olivier Thomann" <Olivier_Thomann@xxxxxxx> wrote in message
news:b7540v8tn4sv2242tjpgq2rlqiqg1h73rp@xxxxxxxxxx
> I don't know why javac doesn't report the second catch has been
> unreachable. It looks like a bug.
>
> I checked the API you are using and the only exception that can be
> thrown by java.security.AccessController.doPrivileged method is a
> PrivilegedActionException exception. This exception is caught properly
> by the first catch clause.
>
> The statement:
>  s = (Socket) java.security.AccessController.doPrivileged( new
> java.security.PrivilegedExceptionAction() {
> public Object run() throws IOException { return new
> Socket(instTunnelHost,
> instTunnelPort);
> }});
>
> cannot throw a IOException. If the run method throws a IOException, it
> will be wrapped by a PrivilegedActionException. Then you can do
> getException() to get the IOException and do whatever you want with
> it.
>
> The Eclipse compiler simply reports that the catch clause for the
> IOException will never be reached.
>
> You can safely remove this catch clause and your code will compile
> fine.
>
> If you find a way to throw an IOException within the try block
> statements, then we have a bug and you can open a bug report against
> JDT/Core.
>
> Hope this help,
>
> Olivier