handlebars.java icon indicating copy to clipboard operation
handlebars.java copied to clipboard

[Q] {{#values}} causes StackOverflowError

Open DatApplePy opened this issue 5 months ago • 1 comments

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@aeab7ff3 So as we can see, using this.values works 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"?

DatApplePy avatar Aug 29 '25 14:08 DatApplePy

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. ❤️

DatApplePy avatar Sep 02 '25 12:09 DatApplePy