Community
Participate
Working Groups
Not a big problem of course but just wanted to let you know that i have 2 valid src codes where a null reference is reported that isn't the case: first, simplified: boolean b = object == null; if(!b) object.toString(); << mark here and the second: String str = null; while(str != null) << mark here { str = methodThatCanReturnNullOrString(str); if(str != null) { break; } }
got another one but that is even more difficult i guess: int length = (array == null) ? 0 : array.length; final StringList strings = new StringList(length); for (int i = 0; i < length; i++) { strings.add(array[i]); <<<< } return strings; it is +/- the same as the boolean but then even harder i guess to analize.
(In reply to comment #0) > boolean b = object == null; > if(!b) object.toString(); << mark here This one is a variant of bug 129907, except that the boolean controlling variable is not final. Our current implementation cannot tackle such cases, but we may reconsider post 3.2.
(In reply to comment #1) > int length = (array == null) ? 0 : array.length; > final StringList strings = new StringList(length); > > for (int i = 0; i < length; i++) > { > strings.add(array[i]); <<<< > } > > return strings; This one is a variant of bug 125319, without the length being final. Comment #2 applies as well.
(In reply to comment #0) > String str = null; > while(str != null) << mark here > { > str = methodThatCanReturnNullOrString(str); > if(str != null) > { > break; > } > } This one seems correct to me. First time while tests str, it is null. Hence the loop does not get executed, and str does not change its value... which remains null.
Thanks for the input. Will reconsider post 3.2.
ahh you are right ofcourse with that while i copied from a real life example a bit to quick: String str = null; while(str == null) <<< { str = methodThatCanReturnNullOrString(str); if(str != null) { break; } } this reports the same, and it shouldn't do that.
(In reply to comment #6) > ahh you are right ofcourse with that while i copied from a real life example a > bit to quick: > > String str = null; > while(str == null) <<< > { > str = methodThatCanReturnNullOrString(str); > if(str != null) > { > break; > } > } > > this reports the same, and it shouldn't do that. > I would contend that this one is correct too. When methodThatCanReturnNullOrString(str) returns a non null string, you break, hence the while won't see str again. Else str is null, and while sees it as null. Whichever value is returned, while(str) always sees str as null.
this line: str = methodThatCanReturnNullOrString(str); can be ofcourse anthing it can be something like: str = methodThatCanReturnNullOrString(i++); When the i is a counter i the loop.. or something like that. I have in my project a larger example and i have no idea how i can fix that. so first the value is initialized to null. And if have while with that value testing it on null Somewhere in the while the value can be set to none null but it doesn't have to be so the next time it can still be null and the while should be evaluated to true.
you are right about the last one. I looked deeper into the real method where i have that. And on the end i also could there just do while(true) because i did break in all places where it should.
*** Bug 183765 has been marked as a duplicate of this bug. ***
Reopening as P5 (since RESOLVED LATER is deprecated).
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.
Verified for 4.7 M1
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 ***