Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 345579

Summary: [1.7][compiler] Weird error message in rethrow site
Product: [Eclipse Project] JDT Reporter: Srikanth Sankaran <srikanth_sankaran>
Component: CoreAssignee: Satyam Kandula <satyam.kandula>
Status: VERIFIED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: Olivier_Thomann, satyam.kandula, stephan.herrmann
Version: 3.7Flags: srikanth_sankaran: review+
Target Milestone: 3.7.1   
Hardware: PC   
OS: Windows XP   
Whiteboard:
Attachments:
Description Flags
Patch under consideration
none
Patch under consideration
none
Proposed patch none

Description Srikanth Sankaran CLA 2011-05-12 06:53:46 EDT
Follow up of bug 345522: BETA_JAVA7

public class X {
    X() throws Exception {
        try {
            throw (Throwable) new Exception();
        } catch (Exception e) {
            throw e;   // <<<<----------------  here
        } catch (Throwable e) {
        }
    }
}

On this program eclipse reports an error "Unhandled exception type Throwable"

JDK7 compiles it alright.
Comment 1 Satyam Kandula CLA 2011-05-12 10:43:59 EDT
Created attachment 195499 [details]
Patch under consideration

Srikanth, I knew exactly what is happening and hence fixed this up. Please review.
Comment 2 Srikanth Sankaran CLA 2011-05-13 02:39:57 EDT
Even with precise exception analysis, JDK7 does not flag the first
catch block as unreachable.

public class X {
	void foo() {
		try {
			goo();
		} catch(SubTypeOfSpecialException e) {
			
		} catch (SpecialException e) {
			
		}
	}
	void goo() throws SpecialException {
		
	}
}

class SpecialException extends Exception {}
class SubTypeOfSpecialException extends SpecialException {}

Eclipse conforms at the moment.
Comment 3 Srikanth Sankaran CLA 2011-05-13 03:24:56 EDT
(In reply to comment #2)
> Even with precise exception analysis, JDK7 does not flag the first
> catch block as unreachable.

Satyam pointed out my muddled thinking, this block can of course be
reached based on what actually gets thrown. So comment#2 should be
ignored.
Comment 4 Satyam Kandula CLA 2011-05-13 06:48:47 EDT
Created attachment 195578 [details]
Patch under consideration

Srikanth has pointed out that the earlier patch haven't considered InitializationFlowContext. The earlier patch though will not cause problems, but it is not clean. In this patch, I am passing a new parameter which will tell the exception that the particular catch block will process.

Srikanth, please review.
Comment 5 Olivier Thomann CLA 2011-05-13 10:33:29 EDT
Satyam,

I believe the last test (test027) should be a conform test and not a negative test.
Comment 6 Satyam Kandula CLA 2011-05-13 11:16:57 EDT
(In reply to comment #5)
> Satyam,
> 
> I believe the last test (test027) should be a conform test and not a negative
> test.
Yes, I will change it accordingly. Thanks.
Comment 7 Srikanth Sankaran CLA 2011-05-16 02:03:59 EDT
Patch looks good. Please release after (a) making the change
suggested in comment# 4. (b) I think it is better to short circuit the
call to org.eclipse.jdt.internal.compiler.lookup.CatchParameterBinding.setPreciseType(TypeBinding) if caughtException is null.
Comment 8 Satyam Kandula CLA 2011-05-16 07:00:20 EDT
Created attachment 195717 [details]
Proposed patch

Patch with Olivier's and Srikanth's comments.
Comment 9 Satyam Kandula CLA 2011-05-16 07:02:52 EDT
Released in BETA_JAVA7 branch
Comment 10 Stephan Herrmann CLA 2011-06-28 09:39:54 EDT
Verified using patch feature 1.0.0-20110623-0900