[stringtemplate-interest] problem with null handling in parallel iteration

Terence Parr parrt at cs.usfca.edu
Fri Nov 9 13:54:50 PST 2007


Brian,

This test works great for me:

	public void testParallelAttributeIterationWithNullValue() throws  
Exception {
		StringTemplate e = new StringTemplate(
				"$names,phones,salaries:{n,p,s | $n$@$p$: $s$\n}$"
			);
		e = e.getInstanceOf();
		e.setAttribute("names", "Ter");
		e.setAttribute("names", "Tom");
		e.setAttribute("names", "Sriram");
		e.setAttribute("phones", new ArrayList() {{add("1"); add(null); add 
("3");}});
		e.setAttribute("salaries", "big");
		e.setAttribute("salaries", "huge");
		e.setAttribute("salaries", "enormous");
		String expecting = "Ter at 1: big"+newline+
						   "Tom@: huge"+newline+
						   "Sriram at 3: enormous"+newline;
		assertEquals(expecting, e.toString());
	}

note the null list element.

Perhaps you're referring to just a list literal inside ST? like  
["xxxxx1", hack.x , hack.x , "xxxxx4" ]

I guess we need a null literal, eh??

Ter


More information about the stringtemplate-interest mailing list