473,545 Members | 1,797 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Strange bug: condition true in IF statement, false the next statement

Hi

I'm facing a very strange problem here. My code looks like this

if(A == null
return
doSomethingWith (A.b)

When I run my code (in debug mode), I get a NullReferenceEx ception -- and on breaking, I discover that A is indeed null. (The exception is raised in the doSomethingWith line.

How can this be? No code has been executed between the IF statement and the next statement. In the context I run the code, A *shouldn't* be null, and even if it were - why does it not step into the IF statement and return

What's worse, when I set a breakpoint anywhere near this segment in my code, the problem *disappeaers* -- A isn't null, and everything works properly

This looks like the classic '=' instead of '==' mistake I'm used to from C++, but that's not the case here (I checked, and anyway C# IF statements require bool...). The fact that it disappears on extensive debugging makes me think it's some sort of debugger/runtime-environment bug. I thought it might be related to garbage collection, but that doesn't make sense either (since I have a reference to A, it shouldn't be collected, right?)

Does anyone have any idea what's going wrong

(For completeness' sake, I should mention that the code I'm running was developed for the 1.0 Framework, and I'm now running it with 1.1.)
Nov 15 '05 #1
5 2238
jec
You don't have another thread making changes to A?
Nov 15 '05 #2
Hi,

we some times have the identical behaviour. It looks like a bug in if-
statement.
I'm realy sure, that there ist no threading issue, because it also
happens to local variables. But i never could reproduce the situation in
sample programs.
It happens on one maschin, but not on another one.

Bye, Jan

=?Utf-8?B?SGF0dWwgU2h pbGd5?= <an*******@disc ussions.microso ft.com> wrote
in news:63******** *************** ***********@mic rosoft.com:
Hi,

I'm facing a very strange problem here. My code looks like this:

if(A == null)
return;
doSomethingWith (A.b); .......
Does anyone have any idea what's going wrong?

(For completeness' sake, I should mention that the code I'm running
was developed for the 1.0 Framework, and I'm now running it with 1.1.)


Nov 15 '05 #3
No, my application is single-threaded; also, unlike the
poster who responded, my bug is deterministic - it *always*
happens, on *every* machine we tried it on...
-----Original Message-----
Hi,

I'm facing a very strange problem here. My code looks like this:
if(A == null)
return;
doSomethingWit h(A.b);

When I run my code (in debug mode), I get a NullReferenceEx ception -- and on breaking, I discover that
A is indeed null. (The exception is raised in the
doSomethingWith line.)
How can this be? No code has been executed between the IF statement and the next statement. In the context I run the
code, A *shouldn't* be null, and even if it were - why does
it not step into the IF statement and return?
What's worse, when I set a breakpoint anywhere near this segment in my code, the problem *disappeaers* -- A isn't
null, and everything works properly.
This looks like the classic '=' instead of '==' mistake I'm used to from C++, but that's not the case here (I
checked, and anyway C# IF statements require bool...). The
fact that it disappears on extensive debugging makes me
think it's some sort of debugger/runtime-environment bug. I
thought it might be related to garbage collection, but
that doesn't make sense either (since I have a reference to
A, it shouldn't be collected, right?).
Does anyone have any idea what's going wrong?

(For completeness' sake, I should mention that the code I'm running was developed for the 1.0 Framework, and I'm
now running it with 1.1.).

Nov 15 '05 #4
Do you have a reproducible bit of code you could post here? eg maybe just
the function called from Main().

I'd be happy to have a look at it if you can post some non-working code.

(Trouble is, it sounds either like a silly mistake of the sort we all make
from time to time, or one of those problems that disappears when you try to
isolate it).

<an*******@disc ussions.microso ft.com> wrote in message
news:5e******** *************** *****@phx.gbl.. .
No, my application is single-threaded; also, unlike the
poster who responded, my bug is deterministic - it *always*
happens, on *every* machine we tried it on...
-----Original Message-----
Hi,

I'm facing a very strange problem here. My code looks like

this:

if(A == null)
return;
doSomethingWit h(A.b);

When I run my code (in debug mode), I get a

NullReferenceEx ception -- and on breaking, I discover that
A is indeed null. (The exception is raised in the
doSomethingWith line.)

How can this be? No code has been executed between the IF

statement and the next statement. In the context I run the
code, A *shouldn't* be null, and even if it were - why does
it not step into the IF statement and return?

What's worse, when I set a breakpoint anywhere near this

segment in my code, the problem *disappeaers* -- A isn't
null, and everything works properly.

This looks like the classic '=' instead of '==' mistake

I'm used to from C++, but that's not the case here (I
checked, and anyway C# IF statements require bool...). The
fact that it disappears on extensive debugging makes me
think it's some sort of debugger/runtime-environment bug. I
thought it might be related to garbage collection, but
that doesn't make sense either (since I have a reference to
A, it shouldn't be collected, right?).

Does anyone have any idea what's going wrong?

(For completeness' sake, I should mention that the code

I'm running was developed for the 1.0 Framework, and I'm
now running it with 1.1.)
.

Nov 15 '05 #5
Sorry, can't post any code -- but it really is much like the fake snippet I posted.

It's not *my* code, either, or even code developed by my company... it appears in the XtraGrid control, developed by DevExpress.
I just checked, and it doesn't happen in Visual Studio.NET 2002 (I used 2003 before) with framework 1.0, so that settles it as far as I'm concerned -- it's a .NET platform bug.
Do you have a reproducible bit of code you could post here? eg maybe just
the function called from Main().

I'd be happy to have a look at it if you can post some non-working code.

(Trouble is, it sounds either like a silly mistake of the sort we all make
from time to time, or one of those problems that disappears when you try to
isolate it).

<an*******@disc ussions.microso ft.com> wrote in message
news:5e******** *************** *****@phx.gbl.. .
No, my application is single-threaded; also, unlike the
poster who responded, my bug is deterministic - it *always*
happens, on *every* machine we tried it on...
-----Original Message-----
Hi,

I'm facing a very strange problem here. My code looks like

this:

if(A == null)
return;
doSomethingWit h(A.b);

When I run my code (in debug mode), I get a

NullReferenceEx ception -- and on breaking, I discover that
A is indeed null. (The exception is raised in the
doSomethingWith line.)

How can this be? No code has been executed between the IF

statement and the next statement. In the context I run the
code, A *shouldn't* be null, and even if it were - why does
it not step into the IF statement and return?

What's worse, when I set a breakpoint anywhere near this

segment in my code, the problem *disappeaers* -- A isn't
null, and everything works properly.

This looks like the classic '=' instead of '==' mistake

I'm used to from C++, but that's not the case here (I
checked, and anyway C# IF statements require bool...). The
fact that it disappears on extensive debugging makes me
think it's some sort of debugger/runtime-environment bug. I
thought it might be related to garbage collection, but
that doesn't make sense either (since I have a reference to
A, it shouldn't be collected, right?).

Does anyone have any idea what's going wrong?

(For completeness' sake, I should mention that the code

I'm running was developed for the 1.0 Framework, and I'm
now running it with 1.1.)
.



___
Newsgroups brought to you courtesy of www.dotnetjohn.com
Nov 15 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
1601
by: Marcin | last post by:
Why does the following script output 3? Can anyone explain that? <?php echo true? 2: false? 3: 4 ; ?> Thanks, -Marcin
6
4525
by: Kiteman - Canada | last post by:
I have the following: a form called Form1 an image called Image1 twelve lines that have been drawn and superimposed on the image I wish to have a command button that will toggle the lines on and off. I am able to do this with a command for each of the twelve lines, but I thought that I could use a For...Each...Next routine instead. ...
3
2551
by: drs | last post by:
I just upgraded my Python install, and for the first time have True and False rather than 1 and 0. I was playing around at the command line to test how they work (for instance, "if 9:" and "if True:" both lead to the conditional being executed, but True == 9 -> False, that this would be true was not obvious to me -- "True is True" is True,...
2
5585
by: Elmar Grandel | last post by:
Hello, i just updated my mysql database from 4.0.x to 4.1 because i like to have the possibility to create subqueries. My problem with the new release is the following: In my running project i have some tables with the column name True and False. In the old version it was possible to do a INSERT in the following manner: INSERT INTO
11
2434
by: Arpan | last post by:
<% If(False) Then Response.Write("False") Else Response.Write("True") End If %> In the above code, the Else condition will be executed. Why?
22
29959
by: Paminu | last post by:
As I remember if(1) evaluates to true and all other numbers including 0 evaluate to false. But where do I find out about this for sure?? I have looked through K&R, all the C for dummies books and various other C programming books but nowhere there is a mention on what a number in an if statement evaluates to. Is this some kind of big...
1
1187
by: Tmillwee | last post by:
I have the following while statement in my code While dataReader.read( ‘Do Stuff†End Whil The dataReader contains 19 rows of data, but the while loop continues and fails on a 20th loop. I have attached a debugger and watched the value of dataReader.read go from True to False after the 19th loop. For some strange reason the loop...
16
4467
by: koutoo | last post by:
I tried writing a true and false If statement and didn't get anything? I read some previous posts, but I must be missing something. I just tried something easy: a = if "c" in a == True: Print "Yes" When I run this, it runs, but nothing prints. What am I doing wrong?
0
7487
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7680
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7934
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7446
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
4966
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3459
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1908
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1033
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
731
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.