Bug 358827 - [1.7] exception analysis for t-w-r spoils null analysis
Summary: [1.7] exception analysis for t-w-r spoils null analysis
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.8   Edit
Hardware: Other Linux
: P3 normal (vote)
Target Milestone: 3.7.2   Edit
Assignee: Stephan Herrmann CLA
QA Contact:
URL:
Whiteboard:
Keywords:
: 367879 (view as bug list)
Depends on:
Blocks:
 
Reported: 2011-09-25 14:59 EDT by Stephan Herrmann CLA
Modified: 2012-01-19 00:44 EST (History)
6 users (show)

See Also:
srikanth_sankaran: review+


Attachments
test and proposed fix (4.79 KB, patch)
2011-09-25 17:34 EDT, Stephan Herrmann CLA
no flags Details | Diff
full patch (8.10 KB, patch)
2011-09-27 09:59 EDT, Stephan Herrmann CLA
no flags Details | Diff
same patch for R3_7_maintenance (8.63 KB, patch)
2011-09-27 17:47 EDT, Stephan Herrmann CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Stephan Herrmann CLA 2011-09-25 14:59:53 EDT
This is a generalization of bug 349326 comment 60:

This works:
	Object foo2() {
		String o = null;
		try {
			o = o.toUpperCase(); // warn here: o is null
		} finally {
			o = "OK";
		}
		return o;
	}
but this doesn't:
	Object foo2() throws FileNotFoundException, IOException {
		String o = null;
		try (FileReader fr = new FileReader("f1")) {
			o = o.toUpperCase();
		} finally {
			o = "OK";
		}
		return o;
	}

Initial analysis: the call to handlingContext.checkExceptionHandlers(..) 
from TryStatement.java:275 causes that the flow info of the finally block 
is erroneously merged into the main flowInfo.
(line number is with bug 349326 applied).
Comment 1 Stephan Herrmann CLA 2011-09-25 15:19:19 EDT
Another find: TryStatement.analyseCode contains two similar calls to
checkExceptionHandlers. The first in l.135 passes true to
isExceptionOnAutoClose, the second in l.261 (head) lacks this param.

@Srikanth, it seems you wrote some of this. Do you recall if the
difference is by intention?

Adding the flag to the second call doesn't fix the issue but based
on this flag we could easily avoid the bogus update of the flowInfo.
Comment 2 Stephan Herrmann CLA 2011-09-25 17:34:02 EDT
Created attachment 203976 [details]
test and proposed fix

Test case and proposed fix.
Comment 3 Stephan Herrmann CLA 2011-09-25 17:36:31 EDT
Srikanth, do you want to check if this collides with your intentions
inside TryStatement.analyseCode(..)? 
Thanks.
Comment 4 Srikanth Sankaran CLA 2011-09-26 02:15:28 EDT
(In reply to comment #1)
> Another find: TryStatement.analyseCode contains two similar calls to
> checkExceptionHandlers. The first in l.135 passes true to
> isExceptionOnAutoClose, the second in l.261 (head) lacks this param.
> 
> @Srikanth, it seems you wrote some of this. Do you recall if the
> difference is by intention?

This code was written by Ayush to fix the bug 348705, yes this difference
is by intention to issue slightly different error messages.

> Adding the flag to the second call doesn't fix the issue but based
> on this flag we could easily avoid the bogus update of the flowInfo.

After reviewing the bug 348705, you should be able to conclude whether
you can safely piggy back your fix on top of this without causing any
side effects, I would think.
Comment 5 Srikanth Sankaran CLA 2011-09-26 02:21:39 EDT
(In reply to comment #4)

> After reviewing the bug 348705, you should be able to conclude whether
> you can safely piggy back your fix on top of this without causing any
> side effects, I would think.


(In reply to comment #3)
> Srikanth, do you want to check if this collides with your intentions
> inside TryStatement.analyseCode(..)? 
> Thanks.

Sorry, I just saw this patch which already attempts to piggy back on
top of this extra parameter Ayush introduced. As you can see against
the backdrop of the context for bug 348705, the proposed patch would
mischaracterize the exception as the one raised by automatic close
call when it is not, and so would be a no-go.
Comment 6 Stephan Herrmann CLA 2011-09-26 03:35:46 EDT
(In reply to comment #5)
> (In reply to comment #4)
> 
> > After reviewing the bug 348705, you should be able to conclude whether
> > you can safely piggy back your fix on top of this without causing any
> > side effects, I would think.
> 
> 
> (In reply to comment #3)
> > Srikanth, do you want to check if this collides with your intentions
> > inside TryStatement.analyseCode(..)? 
> > Thanks.
> 
> Sorry, I just saw this patch which already attempts to piggy back on
> top of this extra parameter Ayush introduced. As you can see against
> the backdrop of the context for bug 348705, the proposed patch would
> mischaracterize the exception as the one raised by automatic close
> call when it is not, and so would be a no-go.

Do you have a test case that would fail with the patch?
compiler.regression.TestAll seem to be happy with the patch.

The location where I added the "true" flag is almost identical to the
one we already have, it concerns AutoCloseable resources, too,
just for the case where we also have a finally block.

BTW: try adding a finally block to TryWithResourcesStatementTest.test053()
first you get a AIOOBE (an obvious typo in the code) and after fixing
that you get the wrong error message. Which can then be fixed by the
patch I proposed here.
Comment 7 Srikanth Sankaran CLA 2011-09-26 04:38:18 EDT
(In reply to comment #6)

> Do you have a test case that would fail with the patch?
> compiler.regression.TestAll seem to be happy with the patch.

> The location where I added the "true" flag is almost identical to the
> one we already have, it concerns AutoCloseable resources, too,
> just for the case where we also have a finally block.

Sorry I didn't look closely the first time. So instead of mislabelling, your
patch indeed would complete the fix for bug 348705.

> BTW: try adding a finally block to TryWithResourcesStatementTest.test053()
> first you get a AIOOBE (an obvious typo in the code) and after fixing
> that you get the wrong error message. Which can then be fixed by the
> patch I proposed here.

Yes, the patch does look good for me. 

Ayush, do you have any comments ?
Comment 8 Ayushman Jain CLA 2011-09-26 07:12:25 EDT
(In reply to comment #7)
> Ayush, do you have any comments ?

+1 from me too
Comment 9 Stephan Herrmann CLA 2011-09-26 07:33:48 EDT
I'd suggest to backport the fix for the AIOOBE mentioned in comment 6
to 3.7.2 (typo i vs. j). 
Do we want to separate that out, or should actually the whole issue go
into 3.7.2, too?
Comment 10 Srikanth Sankaran CLA 2011-09-27 01:44:40 EDT
(In reply to comment #9)
> I'd suggest to backport the fix for the AIOOBE mentioned in comment 6
> to 3.7.2 (typo i vs. j). 
> Do we want to separate that out, or should actually the whole issue go
> into 3.7.2, too?

+1 for 3.7.2 for the full fix, given that it is small and well contained
and is obvious oversight.
Comment 11 Stephan Herrmann CLA 2011-09-27 09:59:13 EDT
Created attachment 204079 [details]
full patch

Patch fixing both issues (with tests), to be released for HEAD.
Comment 12 Stephan Herrmann CLA 2011-09-27 11:21:08 EDT
Released into HEAD for 3.8 M3.
Comment 13 Stephan Herrmann CLA 2011-09-27 17:47:35 EDT
Created attachment 204124 [details]
same patch for R3_7_maintenance

I tried the same tests in 3.7 maintenance and could observe the same
three bugs:
- AIOOBE
- wrong error re exception from t-w-r
- missing null error

All are fixed by this (small) patch.
Comment 14 Olivier Thomann CLA 2011-09-27 18:48:17 EDT
+1 for 3.7.2
Comment 15 Olivier Thomann CLA 2011-09-29 10:00:45 EDT
Stephan, will you release your patch to 3.7 maintenance or should I do it ?
Comment 16 Stephan Herrmann CLA 2011-09-29 11:41:18 EDT
(In reply to comment #15)
> Stephan, will you release your patch to 3.7 maintenance or should I do it ?

Done:
Released commit 1d6277040a15d6a361edbfc4d3f5e370c8d71128 for R3_7_maintenance
Comment 17 Srikanth Sankaran CLA 2011-10-25 02:20:03 EDT
Verified for 3.8 M3 using build id: N20111022-2000
Comment 18 Srikanth Sankaran CLA 2011-10-25 02:21:34 EDT
Leave state as resolved and clear white board status for 3.8 M3.
Comment 19 Ayushman Jain CLA 2012-01-05 07:40:35 EST
*** Bug 367879 has been marked as a duplicate of this bug. ***
Comment 20 Satyam Kandula CLA 2012-01-19 00:44:17 EST
Verified for 3.7.2RC2 using build M20120118-0800