[stringtemplate-interest] [ST4-Beta2] NullPointerException in Interpreter.storeArgs
Terence Parr
parrt at cs.usfca.edu
Tue Jan 25 11:42:34 PST 2011
Fixed.
@Test public void testMessedUpTemplateDoesntCauseRuntimeError() throws Exception {
String templates =
"main(p) ::= <<\n" +
"<f(x=\"abc\")>\n" +
">>\n" +
"\n" +
"f() ::= <<\n" +
"<x>\n" +
">>\n";
writeFile(tmpdir, "t.stg", templates);
STGroupFile group = null;
ErrorBuffer errors = new ErrorBuffer();
group = new STGroupFile(tmpdir+"/"+"t.stg");
group.setListener(errors);
ST st = group.getInstanceOf("main");
st.render();
String expected = "[context [main] 1:1 passed 1 arg(s) to template f with 0 declared arg(s)," +
" context [main] 1:1 attribute x isn't defined," +
" context [main f] 1:1 attribute x isn't defined]";
String result = errors.errors.toString();
assertEquals(expected, result);
}
Ter
On Jan 24, 2011, at 3:29 AM, Udo Borkowski wrote:
> A NPE may occur in void storeArgs(ST self, Map<String,Object> attrs, ST st).
>
> formalArguments in
>
> if ( !st.impl.formalArguments.containsKey(argName) ) {
> errMgr.runTimeError(self,
> current_ip,
> ErrorType.NO_SUCH_ATTRIBUTE,
> argName);
> continue;
> }
>
> may be null, thus generating the NPE.
>
>
>
> Possible fix:
>
> if ( st.impl.formalArguments == null || !st.impl.formalArguments.containsKey(argName) ) {
> errMgr.runTimeError(self,
> current_ip,
> ErrorType.NO_SUCH_ATTRIBUTE,
> argName);
> continue;
> }
>
>
> Udo
>
> P.S.: This (invalid) definition will generate the NPE:
>
> main(p) ::= <<
> <f(x="abc")>
> >>
>
> f(x) ::= <<
> <x
> >>
>
> _______________________________________________
> stringtemplate-interest mailing list
> stringtemplate-interest at antlr.org
> http://www.antlr.org/mailman/listinfo/stringtemplate-interest
More information about the stringtemplate-interest
mailing list