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

Bug 351441

Summary: [1.7] Exception occurrences are not marked correctly when an exception in throws declaration is selected.
Product: [Eclipse Project] JDT Reporter: Deepak Azad <deepakazad>
Component: TextAssignee: Deepak Azad <deepakazad>
Status: VERIFIED FIXED QA Contact:
Severity: normal    
Priority: P2 CC: amj87.iitr, deepakazad, markus.kell.r
Version: 3.7   
Target Milestone: 3.7.1   
Hardware: PC   
OS: Windows XP   
Whiteboard:
Attachments:
Description Flags
fix + test none

Description Deepak Azad CLA 2011-07-07 09:04:32 EDT
Fix to go in ExceptionOccurrencesFinder. Essentially the changes already done for UnionType and twr do not fix the case when an exception in throws declaration is selected.
Comment 1 Deepak Azad CLA 2011-07-07 10:38:55 EDT
In the following snippet select void (the return type), and exit points will be marked including the closing } of twr and resource constructors. These are not marked when Throwable is selected in the throws clause.
--------------------------------------------------------------------------------
	void foo5() throws Throwable {
		FileReader reader = new FileReader("file1");
		try (FileReader reader1 = new FileReader("file1");
				FileReader reader2 = new FileReader("file2")) {
			int ch;
			while ((ch = reader1.read()) != -1) {
				reader.read();
			}
		}
	}
--------------------------------------------------------------------------------

While looking into this I also ran into an older issue. In the following snippet select 'Exception' in the throws clause => all three throw statements are marked even though 2 of the exceptions are caught. This is slightly different (and simpler to fix) than bug 75878 and bug 68305.
----------------------------------------------------------------------------
	void foo(String s) throws Exception {
		try {
			if (s == null)
				throw new NullPointerException();
			else if (s.length() > 10)
				throw new IllegalArgumentException();
			else
				throw new Exception();
		} catch (NullPointerException e) {
			e.printStackTrace();
		} catch (IllegalArgumentException e) {
			e.printStackTrace();
		}
	}
----------------------------------------------------------------------------
Comment 2 Markus Keller CLA 2011-07-07 10:51:34 EDT
Looks the same as bug 68305. Here, the outer scope is the "throws" clause whereas in bug 68305, it's the outer "try" statement. Necessary analysis is exactly the same.
Comment 3 Deepak Azad CLA 2011-07-09 01:31:34 EDT
Created attachment 199369 [details]
fix + test

(In reply to comment #1)
> In the following snippet select void (the return type), and exit points will be
> marked including the closing } of twr and resource constructors. These are not
> marked when Throwable is selected in the throws clause.
> --------------------------------------------------------------------------------
>     void foo5() throws Throwable {
>         FileReader reader = new FileReader("file1");
>         try (FileReader reader1 = new FileReader("file1");
>                 FileReader reader2 = new FileReader("file2")) {
>             int ch;
>             while ((ch = reader1.read()) != -1) {
>                 reader.read();
>             }
>         }
>     }
> --------------------------------------------------------------------------------

For now I have fixed the above problem. Bug 68305 is an older issue, which I think we should fix for 3.7.1.
Comment 4 Deepak Azad CLA 2011-07-09 01:36:20 EDT
.
Comment 5 Ayushman Jain CLA 2011-07-20 02:56:02 EDT
Verified using JDT feature patch v20110714-1300.