Bug 198044 - [compiler][null] Redundant null check gives false positive due to asserts
Summary: [compiler][null] Redundant null check gives false positive due to asserts
Status: CLOSED DUPLICATE of bug 325342
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.3   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 3.7 M3   Edit
Assignee: Maxime Daniel CLA
QA Contact:
URL:
Whiteboard:
Keywords:
: 234549 (view as bug list)
Depends on:
Blocks:
 
Reported: 2007-07-26 18:57 EDT by Daniel Aborg CLA
Modified: 2010-09-30 02:34 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-26 18:57:14 EDT
Build ID: I20070621-1340

Steps To Reproduce:

assert transformer != null : "null transformer for " + key;

if (transformer == null)
	return null;

I get a redundant null check error on the second statement, which is a false positive since asserts have to be enabled to take effect, hence the variable can be null at that location.
Comment 1 Maxime Daniel CLA 2007-08-02 05:04:59 EDT
We deliberately decided that assertions and null reference analysis should work hand in hand (see bug 127244), the null reference analysis always pretending that assertions would be executed. The rationale behind this is that some developers use assertions to program by contract, and that when they take care of a potential null condition by protecting it by an assert, then they should be confident that the protection is recognized downstream by the null analysis, which should no more have doubts about the null valuation of the protected variables.
We believe that this brings more value to the developer than the more conservative approach that would consider that, the execution of assertions being conditioned at runtime, their influence upon variables null status should be disregarded.
Resolving as WONTFIX.
Comment 2 Daniel Aborg CLA 2007-08-02 10:16:56 EDT
I see the rationale for doing that. Might it be an idea to make this a configurable preference?
Comment 3 Maxime Daniel CLA 2007-08-03 16:09:46 EDT
If you believe this is forth it, please feel free to open a feature request. Would need to think more about the details (name, precise semantics, impact on other related cases and relative priority to other tentative null-related options) before making progress though, especially because we try hard to keep the number of options in that area reasonably low.
Comment 4 Frederic Fusier CLA 2007-12-20 06:49:51 EST
Verified for 3.4M1
Comment 5 Maxime Daniel CLA 2008-05-29 04:36:13 EDT
*** Bug 234549 has been marked as a duplicate of this bug. ***
Comment 6 Dani Megert CLA 2010-09-30 02:34:37 EDT
This got fixed along with the fix for bug 325342.

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