Is it possible to throw a JexlException from an JxltTemplate evaluation
when a property exists, but is null?
For example, if our context contains this class (using pseudo-code,with
accessors omitted for brevity):
public class User {
private String firstName;
private String lastName;
}
context.put("user1", new User("firstname", "lastname"));
context.put("user3", new User(null, "lastname"));
and evaulate a JxltTemplate such as:
hello ${user1.firstName}, ${user2.firstName} ${user3.firstName}
${user1.firstName} will return "firstname"
${user2.firstName} will throw a Variable exception, as there is no user2 in
the context
${user3.firstName} will output an empty string, as introspection will find
getLastName() on the class, though invoking it provides a null value.
I have been unable to hit on the proper combination of
strict/silent/strategy to throw any type of JexlException in the third
case, as well, as any strategy comes up with an executor that finds the
property accessor, but the value is not handled until later,
inInterpreter#visit(ASTReference, Object). A custom resolver that gets the
value and throws an exception does work, but doubles the potential gets and
seems like a brittle approach.
I understand that built-in template functions (empty) or custom functors
could also work, but those writing templates would prefer nothing more
complicated than dot syntax. Is there a way to accomplish getting an error
in this case, or perhaps another tactic I have missed?
Thanks,
Greg