[stringtemplate-interest] [ST4 Beta4] NullPointerException when redefining embedded region
Udo Borkowski
ub at abego-software.de
Sat Feb 19 02:00:07 PST 2011
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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/stringtemplate-interest/attachments/20110219/d71af7e4/attachment.html
More information about the stringtemplate-interest
mailing list