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

Excessive NullPointerException in Mapper.getId() #1255

Closed
xtracoder opened this issue Aug 3, 2018 · 0 comments
Closed

Excessive NullPointerException in Mapper.getId() #1255

xtracoder opened this issue Aug 3, 2018 · 0 comments

Comments

@xtracoder
Copy link

Would it be possible to rewrite this piece of code without throwing exception in known cases?

public Object getId(final Object entity) {
    Object unwrapped = entity;
    if (unwrapped == null) {
        return null;
    }
    unwrapped = ProxyHelper.unwrap(unwrapped);
    try {
        return getMappedClass(unwrapped.getClass()).getIdField().get(unwrapped);
    } catch (Exception e) {
        return null;
    }
}

The known case is - getIdField() may return null and that consecutively throws NPE in .get().
In IDE with enabled capture of NullPointerException's debugging of code which uses Morpha is somewhat annoying.

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

No branches or pull requests

2 participants