java.lang.ArithmeticException: / by zero
csxcsx00 opened this issue · comments
I want to use the API 'OGNL.getValue' get specific value from an object, some properties in the object have symbol ‘/’, the problem 'java.lang.ArithmeticException: / by zero' will occur when call the API 'OGNL.getValue', is there some solutions to solve this problem?
Could you give some example? It looks like you perform a double evaluation, in first step you collect data from properties, in the second evaluation of the result of collected data is performed.
Could you give some example? It looks like you perform a double evaluation, in first step you collect data from properties, in the second evaluation of the result of collected data is performed.
The following code can reproduce this problem:
public static void main(String[] args) throws OgnlException {
Map<String, Object> root = new HashMap<>();
root.put("receive/borrow_time", "2022/01/05");
Map context = Ognl.createDefaultContext(root, new DefaultMemberAccess());
Object tree = Ognl.parseExpression("receive/borrow_time");
Object value = Ognl.getValue(tree, context, root);
System.out.println(value);
}
static class DefaultMemberAccess implements MemberAccess {
@Override
public Object setup(Map context, Object target, Member member, String propertyName) {
Object result = null;
if (isAccessible(context, target, member, propertyName)) {
AccessibleObject accessible = (AccessibleObject) member;
if (!accessible.isAccessible()) {
result = Boolean.FALSE;
accessible.setAccessible(true);
}
}
return result;
}
@Override
public void restore(Map context, Object target, Member member, String propertyName, Object state) {
}
@Override
public boolean isAccessible(Map context, Object target, Member member, String propertyName) {
return true;
}
}
In such a case it isn't possible and I don't see an option how to change the behaviour.