Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

java.lang.ArithmeticException: / by zero #142

Open
csxcsx00 opened this issue Jan 5, 2022 · 3 comments
Open

java.lang.ArithmeticException: / by zero #142

csxcsx00 opened this issue Jan 5, 2022 · 3 comments

Comments

@csxcsx00
Copy link

csxcsx00 commented Jan 5, 2022

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?

@lukaszlenart
Copy link
Collaborator

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.

@csxcsx00
Copy link
Author

csxcsx00 commented Jan 5, 2022

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;
    }
}

@lukaszlenart
Copy link
Collaborator

In such a case it isn't possible and I don't see an option how to change the behaviour.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants