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:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user