Bug 134933 - [compiler][null][correlation] use of an intermediate boolean results into a false positive detection
Summary: [compiler][null][correlation] use of an intermediate boolean results into a f...
Status: CLOSED DUPLICATE of bug 538421
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.2   Edit
Hardware: PC Windows XP
: P5 enhancement (vote)
Target Milestone: 4.7 M1   Edit
Assignee: Ayushman Jain CLA
QA Contact:
URL:
Whiteboard:
Keywords: helpwanted
Depends on:
Blocks:
 
Reported: 2006-04-04 22:53 EDT by Simon Archer CLA
Modified: 2018-08-30 10:38 EDT (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Simon Archer CLA 2006-04-04 22:53:12 EDT
Using Eclipse 3.2/M6.

Given the following Java class:

  public class Test {
    private Object getObject() {
      return "Hello World";
    }
	
    public void foo() {
      Object o = getObject();
      boolean legal = o != null;
      if (legal == false) return;
      String s = o.toString();  // WARNING: "The variable o may be null"
      System.out.println(s);
    }	
  }

The "Java > Compiler > Errors/Warnings" preference for "Null reference" is being somewhat over zealous, issuing the warning, "The variable o may be null".  While clearly the use the word "may" indicates possibilities, it is rather unfortunate that the JDT cannot detect this usage pattern.  

Of course, for this simply test case it would be fine to fold the validation into the "if" statement, but for many real applications where validation is more complicated the use of temporary variables is useful.

Sadly, as it works today I think many people would choose to disable this feature due to the large number of false positives.
Comment 1 Maxime Daniel CLA 2006-04-05 05:00:28 EDT
Compared to bug 129907, this case introduces two extra difficulties:
- the boolean variable legal is not final, which means that changes to its relationship to o null status should be tracked;
- the expression that guards o being null is composite (even if it is a simple composite in this case).
Hence the case would call for a more general variables correlation analysis than what we can do with the current technology.
Not in 3.2.
Comment 2 Simon Archer CLA 2006-04-05 09:32:49 EDT
Fair enough.  I guess I'll either change my coding style or adust my preferences.  Thanks for considering this one.
Comment 3 Maxime Daniel CLA 2007-06-19 08:07:34 EDT
Reopening as P5 (since RESOLVED LATER is deprecated).
Comment 4 Stephan Herrmann CLA 2016-06-28 17:18:00 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 Sasikanth Bharadwaj CLA 2016-08-02 04:33:34 EDT
Verified for 4.7 M1
Comment 6 Stephan Herrmann CLA 2018-08-30 10:38:49 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 ***