On Sat, May 14, 2011 at 9:22 AM, <zun...@google.com> wrote:

> I know I've asked this before, but if code isn't live in the runer, we
> replace it with null.nullMethod(), null.nullField or the likes.  Why do
> we keep this around?  Dead Code elimination usually gets rid of it (but
> not always?) is it just left there to trip over at run time in case
> there is a bug in our liveness tests?


It's a correct translation of code where static analysis proves that a
qualifier is null.

User code:
String s = null;
s.toCharArray();

Translation:
null.nullMethod();

That way, we throw an NPE in the correct place at runtime.  Or more
technically, it generates an implicit null ref JavaScriptException.  If it
weren't for the desire to match the platform semantics, we could just as
easily replace it with "throw new NullPointerException()".

Arguably, we could just leave it as "null.toCharArray()", but the whole idea
is to remove 'toCharArray()" from the AST, and we wouldn't want to leave a
dangling reference to it that we'd have to worry about later.

-- 
http://groups.google.com/group/Google-Web-Toolkit-Contributors

Reply via email to