Community
Participate
Working Groups
Build ID: I20070625-1500 Steps To Reproduce: If you type in a java file: public class X { boolean test() { return true; } int foo() { if ((test() ? null : null) == null) return 1; return 0; } // more complex int bar() { String s = null; if ((test() ? s : null) == null) return 1; return 0; } } In both case, a "redundant null check" should be reported. More information:
While the test cases are different (and should be used for additional regression tests), the cure would be the same as for bug 133125, namely compute and use the null status of the ternary operator in due time. Hence I will consider this bug as a duplicate (and we'll leverage the test cases as needed if/when we go after bug 133125). *** This bug has been marked as a duplicate of bug 133125 ***
Changing OS from Mac OS to Mac OS X as per bug 185991
The test case given here is not fixed by bug 133125. Hence reopening this.
(In reply to comment #3) > The test case given here is not fixed by bug 133125. Hence reopening this. While part of bug 133125 has moved to bug 324178, which is still open, the test cases from this bug are different as analysis of the condition is not required here. To start narrow down the issue, consider the following variant, where the ternaries have been extracted into local variables: public class Bug_195757 { boolean test() { return true; } int foo() { Object ternary1 = test() ? null : null; if (ternary1 == null) return 1; return 0; } // more complex int bar() { String s = null; String ternary2 = test() ? s : null; if (ternary2 == null) return 1; return 0; } } Already in 3.6.0 this produces the expected warnings: Description Resource Path Location Type Dead code Bug_195757.java /Bug/src line 11 Java Problem Dead code Bug_195757.java /Bug/src line 21 Java Problem Redundant null check: The variable ternary1 can only be null at this location Bug_195757.java /Bug/src line 9 Java Problem Redundant null check: The variable ternary2 can only be null at this location Bug_195757.java /Bug/src line 19 Java Problem This seems to support Maxime's analysis that this is a matter of when the required information is available.
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet. If you have further information on the current state of the bug, please add it. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant. -- The automated Eclipse Genie.
still relevant, but not on our plan, currently.