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

4.3.0 seems to shadow 'size' under OpenJDK 17

Open dsvensson opened this issue 2 years ago • 2 comments

When upgrading to OpenJDK 17, and bumping to 4.3.0, the output of a variable called 'size' used in a loop silently became 1 rather than its expected value of 10. Reverting to 4.2.1, still using Java 17, it's 10 again. Renaming the variable fixes the problem. Would be nice with some warning/error on such shadowing.

dsvensson avatar Jan 13 '22 10:01 dsvensson

Can you include some more code?

Do you have field called size that is protected or private right?

In 4.2.1 on JDK 17 you could not get the value of List.of("stuff").size(). The below would throw an exception.

    MethodValueResolver r = new MethodValueResolver();
    var list = List.of("hello", "stuff");
    Object o = r.resolve(list, "size");

In 4.3.0 it works now.

I still don't know how you didn't see the exception.

agentgt avatar Mar 30 '22 14:03 agentgt

You also probably ran into this:

https://github.com/jknack/handlebars.java/blob/master/handlebars/src/main/java/com/github/jknack/handlebars/ValueResolver.java#L87

agentgt avatar Mar 30 '22 14:03 agentgt