Bug 198157 - [compiler][null][correlation] False positive on potential null pointer access warning when re-using a condition
Summary: [compiler][null][correlation] False positive on potential null pointer access...
Status: CLOSED DUPLICATE of bug 538421
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.3   Edit
Hardware: PC Windows XP
: P5 enhancement (vote)
Target Milestone: 4.7 M1   Edit
Assignee: JDT-Core-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords: helpwanted
Depends on:
Blocks:
 
Reported: 2007-07-27 15:29 EDT by Daniel Aborg CLA
Modified: 2018-08-30 10:33 EDT (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Daniel Aborg CLA 2007-07-27 15:29:07 EDT
Build ID: I20070621-1340

Steps To Reproduce:

The following code produces a potential null pointer warning:

final String s;
if (condition) {
	s = "Hello";
} else { 
	s = null;
}

if (condition) {
	s.indexOf(1);
}

As does this code:

String s = null;
if (condition) {
	s = "Hello";
}

if (condition) {
	s.indexOf(1);
}
Comment 1 Daniel Aborg CLA 2007-07-27 15:31:09 EDT
The warning disappears if you replace the if with a conditional, but that is not always possible (e.g. the if branches contain multiple statements).
Comment 2 Maxime Daniel CLA 2007-07-28 06:21:53 EDT
This is a case of variables correlation. We currently have no plans to address that class of null analysis issues. Lowering the priority accordingly.
Comment 3 Max Gilead CLA 2010-02-18 14:09:58 EST
I believe this is the same issue so I'll post a bit another test case here:

void test(final Object a, final Object b) {
    if (a == null && b == null) {
        return;
    }
    if (a == null && b != null) {
        return;
    }
    System.out.println(a.hashCode()); // Potential null pointer access
}
Comment 4 Stephan Herrmann CLA 2016-06-28 17:17:24 EDT
Bulk closing all compiler bugs tagged [null][correlation], because we have no plans to add such a feature: it would be a tremendous implementation effort, beyond our current man power, and may be impossible to achieve within the desired performance bounds.

If s.o. has a viable strategy or even implementation for such a feature, I'm all ears.
Comment 5 Jay Arthanareeswaran CLA 2016-08-03 07:58:06 EDT
Verified for 4.7 M1.
Comment 6 Stephan Herrmann CLA 2018-08-30 10:33:17 EDT
I created a new umbrella RFE outlining what would be needed to address this issue.

*** This bug has been marked as a duplicate of bug 538421 ***