Skip to content

Commit

Permalink
[Blazebit#722] Fix NPE during view attribute accessor resolving when …
Browse files Browse the repository at this point in the history
…lacking an explicit version mapping
  • Loading branch information
beikov committed Jan 22, 2019
1 parent 45f1ad9 commit 7465aa7
Showing 1 changed file with 8 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,16 @@ public class ViewAttributeAccessor implements AttributeAccessor {
private final Field field;

ViewAttributeAccessor(EntityViewManagerImpl evm, MethodAttribute<?, ?> attribute, boolean readonly) {
Class<?> clazz = attribute.getDeclaringType().getJavaType();
Method getter = ReflectionUtils.getGetter(clazz, attribute.getName());
if (!Modifier.isPublic(getter.getModifiers()) || !Modifier.isPublic(getter.getDeclaringClass().getModifiers())) {
Method getter = attribute.getJavaMethod();
if (getter != null && (!Modifier.isPublic(getter.getModifiers()) || !Modifier.isPublic(getter.getDeclaringClass().getModifiers()))) {
try {
getter.setAccessible(true);
} catch (Exception e) {
throw new RuntimeException("Couldn't make method for entity view attribute accessible for reading!", e);
}
}
this.getter = getter;
if (readonly) {
if (readonly && getter != null) {
this.field = null;
} else {
Class<?> proxyClass = evm.getProxyFactory().getProxy(evm, (ManagedViewTypeImplementor<Object>) attribute.getDeclaringType(), null);
Expand All @@ -67,7 +66,11 @@ public Object getOrCreateValue(Object object) {
@Override
public Object getValue(Object object) {
try {
return getter.invoke(object);
if (getter == null) {
return field.get(object);
} else {
return getter.invoke(object);
}
} catch (Exception e) {
throw new RuntimeException("Couldn't get value from entity view attribute!", e);
}
Expand Down

0 comments on commit 7465aa7

Please sign in to comment.