Object reference not set to an instance of an object

Apr 11, 2011 at 2:27 PM
Edited Apr 11, 2011 at 2:34 PM


I am writing to you as I am facing an Exception while minifying some javascript. (I am using Ajax Minifier 4.15)

This is happening even before my attempt at pruning some console statements (which I did not see how to do it in the documentation, so you might have some advice in there)

I encountered the issue with a line of code like this : a = b[null]; as soon as I call Parser.parse(cs).

I had not yet seen such a key and hence went to ECMA-262 and saw it as something valid.

Try minifying (parsing at least) the following code:


a = { toto:"titi" };
a[null] = "tata"; // !_!
a[undefined] = "tete"; // ?_?
a[true] = "tutu";
a[false] = "tyty";
a[3.45] = "numeral 3.45";


alert(a[null]); // O_o
alert(a[undefined]); // ^-^
alert(a[1 == 1]);
alert(a[1 == 0]);




it raises an Exception with a[null] whereas loading this under IE/FF/Chrome is just fine.

I am pasting here my "minifying code" in case I am not doing something right...


// Configure Javascript Shrinking Options
cs = new CodeSettings();
cs.LocalRenaming = LocalRenaming.CrunchAll;
cs.MacSafariQuirks = true;
cs.OutputMode = OutputMode.MultipleLines;
cs.IndentSize = 0;
cs.StripDebugStatements = true;
cs.CollapseToLiteral = true;

private String MinifyJavaScript(String text)
	JSParser parser = new JSParser(text, null);

		Block scriptBlock = parser.Parse(cs);
		// parse the input  

		return scriptBlock.ToCode();
	catch (JScriptException e)
		// other error handling 
		Console.WriteLine("MinifyJavaScript got a JScriptException : " + e.Message);
	catch (Exception e)
		Console.WriteLine("MinifyJavaScript got an Exception : " + e.Message);

	return "";

private void parseNodes(IEnumerable<AstNode> ie)
	foreach (AstNode node in ie)
		if (node is CallNode && node.Context.Code.StartsWith("console."))
			if (!node.Context.Code.StartsWith("console.error") && !node.Context.Code.StartsWith("console.warn"))
				node.Parent.ReplaceChild(node, null);


I thank you in advance with all the help you could provide me with.

I am currently using Ajax Minifier to "build layers" ala Dojo buildscript and it's quite useful.

Thanks and Regards


Apr 18, 2011 at 9:35 PM

[Sorry for the delay; been in Hawaii the last two weeks]

I can repro the error -- I'll get a fixed build out for you this afternoon.

Apr 18, 2011 at 10:20 PM

Okay, this should be fixed now in version 4.16. Great catch -- thanks for reporting it!

Apr 21, 2011 at 12:47 PM


i just tested it, it works like a charm now ! 

Thanks for the quick fix, no worries for the delay, time in Hawaii has to be enjoyed ;-)