[stringtemplate-interest] [ST4 Beta4] NullPointerException when redefining embedded region

Udo Borkowski ub at abego-software.de
Sat Feb 19 11:09:20 PST 2011


An addition to the earlier message: the following (invalid) region definition also raises a NullPointerException, but at a slightly different location. I guess a fix will cover both situations.

---------------
@t.() ::= "" 
---------------

TestCase:

	public void testIt2() throws Exception {
		STMessageTextCollector messages = new STMessageTextCollector();

		String templates = "@t.() ::= \"\"";
		writeFile(tmpdir, "t.stg", templates);
		org.stringtemplate.v4.STGroup group = new org.stringtemplate.v4.STGroupFile(
				tmpdir + "/t.stg");
		group.errMgr = new ErrorManager(messages);

		// Force loading the group
		// (this led to an NPE earlier that is reported in the error messages)
		org.stringtemplate.v4.ST st = group.getInstanceOf("main");

		// A proper error messages should be written
		Assert.assertEquals(
				"t.stg 1:3: missing ID at '('\n"
						+ "1:3: template t doesn't have a region called <missing ID>\n",
				messages.getText());
	}


Udo

On 19.02.2011, at 11:00, Udo Borkowski wrote:

> The following template raises an NullPointerException:
> 
> ------------
> main() ::= <<
> <@r>a<@end>
> <@r()>
> >>
> ------------
> 
> The NPE is caught by ST4 and reported through the ErrorManager.
> 
> 
> TestCase:
> 
> 	public void testIt() throws Exception {
> 		STMessageTextCollector messages = new STMessageTextCollector();
> 
> 		String templates = "main() ::= <<\n<@r>a<@end>\n<@r()>\n>>";
> 		writeFile(tmpdir, "t.stg", templates);
> 		org.stringtemplate.v4.STGroup group = new org.stringtemplate.v4.STGroupFile(
> 				tmpdir + "/t.stg");
> 		group.errMgr = new ErrorManager(messages);
> 
> 		// Force the compilation (this led to an NPE earlier that is reported in
> 		// the error messages)
> 		org.stringtemplate.v4.ST st = group.getInstanceOf("main");
> 
> 		// A proper error messages should be written
> 		Assert.assertEquals(
> 				"0:-1: region main.r is embedded and thus already implicitly defined\n",
> 				messages.getText());
> 	}
> 
> 
> CodeFix:
> 
> I don't have a fix for this. I implemented a workaround in ErrorManager#compileTimeError, however the cause for the problem is deeper inside the ST4 code, possibly related to STGroup#rawDefineTemplate and its callers.
> 
> 
> Udo
> 
> _______________________________________________
> stringtemplate-interest mailing list
> stringtemplate-interest at antlr.org
> http://www.antlr.org/mailman/listinfo/stringtemplate-interest

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/stringtemplate-interest/attachments/20110219/7bd1501b/attachment.html 


More information about the stringtemplate-interest mailing list