Skip to content

Commit

Permalink
Merge pull request hazelcast#6185 from jerrinot/fix/NPE_onIntefacesWh…
Browse files Browse the repository at this point in the history
…enFieldDoesNotExist/maintanance-3.x

[Backport] - Do not throw NPE when intermediate field is an interface
  • Loading branch information
Serkan ÖZAL committed Sep 12, 2015
2 parents cf709ca + e0f29e7 commit 0454e62
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
Expand Up @@ -175,7 +175,7 @@ private static Getter createGetter(Object obj, String attribute) {
}
if (localGetter == null) {
Class c = clazz;
while (!Object.class.equals(c)) {
while (!c.isInterface() && !Object.class.equals(c)) {
try {
final Field field = c.getDeclaredField(name);
field.setAccessible(true);
Expand Down
@@ -1,13 +1,16 @@
package com.hazelcast.query.impl.getters;

import com.hazelcast.query.QueryException;
import com.hazelcast.query.impl.AttributeType;
import com.hazelcast.test.HazelcastParallelClassRunner;
import com.hazelcast.test.annotation.QuickTest;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.junit.runner.RunWith;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.fail;

@RunWith(HazelcastParallelClassRunner.class)
@Category(QuickTest.class)
Expand All @@ -19,4 +22,31 @@ public void test_getAttributeType() throws Exception {

assertNull(attributeType);
}


@Test
public void extractValue_whenIntermediateFieldIsInterfaceAndDoesNotContainField_thenThrowIllegalArgumentException() throws Exception {
OuterObject object = new OuterObject();
try {
ReflectionHelper.extractValue(object, "emptyInterface.doesNotExist");
fail("Non-existing field has been ignored");
} catch (QueryException e) {
// createGetter() method is catching everything throwable and wraps it in QueryException
// I don't think it's the right thing to do, but I don't want to change this behaviour.
// Hence I have to use try/catch in this test instead of just declaring
// IllegalArgumentException as expected exception.
assertEquals(IllegalArgumentException.class, e.getCause().getClass());
}
}



private static class OuterObject {
private EmptyInterface emptyInterface;
}

private interface EmptyInterface {

}

}

0 comments on commit 0454e62

Please sign in to comment.