Allow access coercion to be disabled.

I'm not disabling it by default because that would change behavior for anyone
who was using reflection, which seems like annoying breakage. People who are
using JMustache with Java 9 can configure a non-coercing DefaultCollector to
eliminate the illegal access warnings.
This commit is contained in:
Michael Bayne
2019-12-17 13:39:22 -08:00
parent 9f0ade9db7
commit da7970e993
2 changed files with 53 additions and 5 deletions
@@ -275,4 +275,22 @@ public class MustacheTest extends SharedTests
test("k1v1k2v2", "{{#map.entrySet}}{{key}}{{value}}{{/map.entrySet}}",
context("map", data));
}
@Test public void testNoAccesCoercion () {
Object ctx = new Object() {
public Object foo () {
return new Object() {
public Object bar = new Object() {
public String baz = "hello";
private String quux = "hello";
};
};
}
};
test("hello:hello", "{{foo.bar.baz}}:{{foo.bar.quux}}", ctx);
Mustache.Compiler comp = Mustache.compiler().
withCollector(new DefaultCollector(false)).
defaultValue("missing");
test(comp, "hello:missing", "{{foo.bar.baz}}:{{foo.bar.quux}}", ctx);
}
}