Bug 244222 - [compiler][null][correlation] Using xor when checking for null results in false "potential null pointer" warning
Summary: [compiler][null][correlation] Using xor when checking for null results in fal...
Status: CLOSED DUPLICATE of bug 538421
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.3.2   Edit
Hardware: PC Linux
: P5 normal (vote)
Target Milestone: ---   Edit
Assignee: JDT-Core-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords: helpwanted
Depends on:
Blocks:
 
Reported: 2008-08-14 14:28 EDT by Karl Stenerud CLA
Modified: 2018-08-30 10:29 EDT (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Karl Stenerud CLA 2008-08-14 14:28:15 EDT
The following will cause eclipse to issue a "potential null pointer" warning on the last line, even though there's no possibility for s1 to be null at that point.

public boolean areDifferent(String s1, String s2)
{
    if(s1 == null && s2 == null)
    {
        return false;
    }
    if((s1 == null) ^ (s2 == null))
    {
        return true;
    }
    return !s1.equals(s2);
}


As proof, the following lines do not cause a NullPointerException:

areDifferent(null, null);
areDifferent("a", null);
areDifferent(null, "a");
areDifferent("a", "a");
Comment 1 Remy Suen CLA 2009-08-29 16:34:44 EDT
Still a problem on I20090811-0800. If you use |, the warning will also appear.
Comment 2 Stephan Herrmann CLA 2011-02-28 06:42:01 EST
Fixing this would require analysis of the correlation of s1 and s2,
which we currently don't do.

Closing as duplicate despite the slight different in logic.

*** This bug has been marked as a duplicate of bug 290263 ***
Comment 3 Stephan Herrmann CLA 2018-08-30 10:29:43 EDT

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