Bug 28641 - Erroneous compiler warning about hidden catch block
Summary: Erroneous compiler warning about hidden catch block
Status: RESOLVED INVALID
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 2.0.2   Edit
Hardware: PC Windows 2000
: P3 minor (vote)
Target Milestone: 2.1 M5   Edit
Assignee: JDT-Core-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2002-12-18 14:06 EST by Jim Pinkham CLA
Modified: 2003-03-23 12:38 EST (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jim Pinkham CLA 2002-12-18 14:06:31 EST
The complete warning is: "Catch block is hidden by another one in the same try 
statement"

Here is a sample code that demonstrates this bug.  The signifigant thing
is that TransformerConfigurationException is a subclass of TransformerException.
Same code compiles clean with jikes +P  (v1.18)

 import javax.xml.transform.*;

 ...

 try
 {
   ... stuff using XML transformers ...
   retVal = transformerFactory.newTransformer(new StreamSource(new File
(xslFileLocation.toString())));	
   xslTransformers.put(xslKey, retVal);
 }
 catch(TransformerConfigurationException e)
 {
   throw new RemoteException("oh, darn!", e);
 }
 catch(TransformerException e)
 {    <-- The warning's red squiggle appears under the brace here
   throw new RemoteException("oh, double darn!", e);
 }
Comment 1 Philipe Mulet CLA 2002-12-19 06:02:27 EST
This is an optional warning which you can turn off if you don't like it.
The rational is that if you would separate these 2 catch blocks in nested try 
statements, the outer catch would get a blame (claiming its unreachable).

Isn't it the case ?
Comment 2 Jim Pinkham CLA 2002-12-19 09:23:13 EST
Based on the wording of the message, I think it is trying to warn of an 
unreachable catch block where the superclass is first and the subclass second.  
(I would think that should be an unreachable code error, not a warning).

If it is truly working as intended, then I guess I just don't get it.  I don't 
see how the use of multiple catch blocks with catch (specific class) ... catch 
(subclass) is something to be discouraged with a warning?  Sure, I can turn it 
off (thus low severity), but it seems like an incorrect warning to me.  (The 
second block is NOT hidden.)

I'm sorry I don't understand what you mean about separating the 2 catch blocks?
Comment 3 Philipe Mulet CLA 2002-12-19 09:39:05 EST
If you wrote instead the following code, wouldn't the outer catch be flagged as 
being unreachable ?

 try
 {
     try 
     {
        ... stuff using XML transformers ...
        retVal = transformerFactory.newTransformer(new StreamSource(new File
           (xslFileLocation.toString())));	
        xslTransformers.put(xslKey, retVal);
      }
      catch(TransformerConfigurationException e)
      {
        throw new RemoteException("oh, darn!", e);
      }
 }
 catch(TransformerException e)
 {    <-- The warning's red squiggle appears under the brace here
   throw new RemoteException("oh, double darn!", e);
 }
Comment 4 Jim Pinkham CLA 2002-12-19 11:35:32 EST
No, in that case the outer catch would still be reachable (assuming the stuff 
in the inner try block is declared to throw TransformerException and not just 
TransformerConfigurationException).  So if it threw some other subclass it 
would go to the outer catch block.

Since I first posted this bug, I found the help description of the intent of 
the message.  It appears to be doing exactly what is intended, so I'm marking 
this as INVALID (aka Not a bug).  

I still don't undertand why anyone would want such a warning, but there is so 
much to love about Eclipse, I'll just turn it off and move on.