handlebars.java
handlebars.java copied to clipboard
[Q] {{#values}} causes StackOverflowError
Let's say I have a class like this:
public class CodegenMap extends CodegenType {
private CodegenType values;
// constructors...
// setters & getters...
@Override
public boolean isMap() {
return true;
}
}
And we have this recursive template (property.hbs):
{{#if isArray}}{{{typeName}}}<{{#items}}{{>property}}{{/items}}>{{/if}}
{{~#if isMap}}{{{typeName}}}<{{#values}}{{>property}}{{/values}}>{{/if}}
{{~#if isModel}}{{{typeName}}}{{/if}}
{{~#if isPrimitive}}{{{typeName}}}{{/if}}
Using the log helpers I got the followings:
-
{{log values}}->[2, false] -
{{log this.values}}->...model.CodegenMap@aeab7ff3So as we can see, usingthis.valuesworks fine.
I dug into the code a bit to figure out what Handlebars was doing with the values value, but I couldn't.
Could you please explain this behavior of Handlebars to me?
Also, are there any other "keywords" that should be avoided or can only be used with "this"?
UPDATE!
When values is used, Handlebars.java is calling Map.values() instead of SomeObject.getValues() / SomeObject.values().
If this is the expected behavior, that's fine. But please indicate it in the documentation. ❤️