dotgnu-general
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [DotGNU]Bug - null objects and stack traces.


From: Rhys Weatherley
Subject: Re: [DotGNU]Bug - null objects and stack traces.
Date: Sun, 06 Oct 2002 09:43:42 +1000

Jonathan P Springer wrote:
> 
> See attached program.
> 
> When executed, it reports a null pointer exception as follows:
> 
> Uncaught exception: System.NullReferenceException: The value 'null' was found
> where an instance of an object was required
>         at System.Private.Stack.Push(Object) in Stack.cs:74
>         at Test.Main() in Stack.cs:155
> 
> The null pointer in question is actually the uninitialized Stack object
> in Main, but it gets into Push before complaining.  The extra layer of
> stack drove me nuts for several hours last night.  Any thoughts on how
> to eliminate it?

It is perfectly legitimate to call a method with a null "this"
object in CLI.  Object references are checked at the point they
are first dereferenced.  Dereferences occur when you access a
field or make a virtual method call (which needs to access the
vtable in the object).  Because "Push" is not virtual, the first
time that "s" is dereferenced is within the method body.  MS'es
CLR does the same thing.

Annoying, isn't it? :-)

Cheers,

Rhys.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]