Bug 130359 - [compiler][null] wrong warning in try/catch with RuntimeException
Summary: [compiler][null] wrong warning in try/catch with RuntimeException
Status: CLOSED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.2   Edit
Hardware: PC Windows 2000
: P3 normal (vote)
Target Milestone: 3.2 M6   Edit
Assignee: Maxime Daniel CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-03-03 12:44 EST by Görge Albrecht CLA
Modified: 2006-04-03 12:02 EDT (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Görge Albrecht CLA 2006-03-03 12:44:19 EST
In the following code the "null reference analysis" produces a false positive:
1:	Object element = null;
2:	try {
3:		element = foo();
4:		bar(element);
5:	} catch (RuntimeException e) {
6:		System.out.println(element.toString());
7:	}
8:	private Object foo() {
9:		return "";
10:	}
11:	private void bar(Object element) {
12:		throw new IllegalArgumentException("");
13:	}

In line 6 "element" is considered as "can only be null" but should be "may be null". 

If you change line 11 to 
11: 	private void bar(Object element) throws Exception {
and line 5 to
5: 		} catch (Exception e) {
you get the correct warning.
Comment 1 Maxime Daniel CLA 2006-03-23 11:07:01 EST
Reproduced with build I20060321-1210. Entered (skipped) test case NullReferenceTest #561.
Comment 2 Maxime Daniel CLA 2006-03-24 03:33:08 EST
Fixed and released in HEAD.
The key for verification is to use an unchecked exception. 
Comment 3 Frederic Fusier CLA 2006-03-28 06:03:21 EST
Verified for 3.2 M6 using warm-up build I20060327-0010.
Comment 4 Görge Albrecht CLA 2006-04-03 12:02:56 EDT
Verified for 3.2M6. Mark as closed. Thanks