Bug 136309 - [compiler][null][correlation] non final boolean and non final array length
Summary: [compiler][null][correlation] non final boolean and non final array length
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-12 08:13 EDT by Johan Compagner CLA
Modified: 2018-08-30 10:39 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 Johan Compagner CLA 2006-04-12 08:13:22 EDT
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;
			}
		}
Comment 1 Johan Compagner CLA 2006-04-12 08:21:10 EDT
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.
Comment 2 Maxime Daniel CLA 2006-04-12 08:30:07 EDT
(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.
Comment 3 Maxime Daniel CLA 2006-04-12 08:31:44 EDT
(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.
Comment 4 Maxime Daniel CLA 2006-04-12 08:35:57 EDT
(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.
Comment 5 Maxime Daniel CLA 2006-04-12 08:42:00 EDT
Thanks for the input. Will reconsider post 3.2.
Comment 6 Johan Compagner CLA 2006-04-12 16:15:03 EDT
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.
Comment 7 Maxime Daniel CLA 2006-04-14 05:58:32 EDT
(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.
Comment 8 Johan Compagner CLA 2006-04-14 07:36:28 EDT
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.
Comment 9 Johan Compagner CLA 2006-04-15 04:58:20 EDT
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.
Comment 10 Maxime Daniel CLA 2007-04-24 08:48:10 EDT
*** Bug 183765 has been marked as a duplicate of this bug. ***
Comment 11 Olivier Thomann CLA 2007-04-24 12:06:48 EDT
*** Bug 183765 has been marked as a duplicate of this bug. ***
Comment 12 Maxime Daniel CLA 2007-06-19 08:07:45 EDT
Reopening as P5 (since RESOLVED LATER is deprecated).
Comment 13 Stephan Herrmann CLA 2016-06-28 17:18:09 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 14 Sasikanth Bharadwaj CLA 2016-08-02 04:31:38 EDT
Verified for 4.7 M1
Comment 15 Stephan Herrmann CLA 2018-08-30 10:39:14 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 ***