Re: Test for an initialised object

David Hakim <dhakim-Gkm/TONP9n1Wk0Htik3J/[email protected]> Tue, 6 May 2003 22:19:30 -0400
Newsgroups gmane.comp.lang.moto.devel
Message-ID <[email protected]>
If the NullPointerException is being thrown during interpretation (and 
not during verification) than throwing the exception is correct 
behavior. It is the same result that would be generated by a method 
call on a null object.

On Tuesday, May 6, 2003, at 08:34  PM, Stefano Corsi wrote:

>
>>
>> Did you want to add this field so motov could report a warning to
>> programmers that they 'might' be using a variable that they did not 
>> yet
>> assign a value to ?
>>
>
> Yes, the problem is that if you try to lookup the correct method 
> operator
> (like += -- ++ *= and so on) in motox_try_overload_..., and the 
> underlying
> object is not initialized, you get a Null Pointer exception.

During the lookup or during the function call ? The lookup itself 
should not fail since the lookup should depend only on the MotoVal's 
type, which should be set.

> ex:
>
> ${
>     use "codex.util";
>
>     // SymbolTable i = new SymbolTable();
>     SymbolTable i;
>     i["dasd"] = "pippo";
>
> }$
>
> Uncaught NullPointerException
>    message:A method overloaded operator may not be identified on null
>
> NullPointerException thrown in <main>(motox.c:228)
>
> The same happens if you call a method on a non initialized object...
> Wouldn't be possible (and maybe cleaner) to warn the user that he's 
> using a
> non-initialized object?
>
This is a non trivial task for a couple reasons.

First is requires a measure of data flow analysis. When we see a method 
(or unary operator) called on a value we would need to be able to tell 
that 'there exists a path of execution where by that value is never 
explicitly assigned anything'. That test requires some significant 
bookkeeping we don't do right now.

Second, since moto does give all variables default values already, we 
would want this to be a warning (like in C), and not a verification 
error . But when developing pages on a web-server through the 
interpreter, there is really no good mechanism that I've thought of to 
present warnings. We wouldn't want to send the warnings to the browser 
since the page is capable of executing. But if we wrote the warnings to 
the log ... who would read them :)

-Dave

> Stefano
>