spring-projects/spring-data-mongodb — pull request #152 by juhgiyo (2014-03-19 06:49:56+00:00)
Title: Check if the method is an original Object method

The parameter "method" can be either from Object's method or an override of original Object method.
ReflectionUtils.isObjectMethod(method) only check if the same method exists in Object.
So in order to check if the method is an original method from Object class, it needs to explicitly check method.getDeclaringClass() with Object.class.

For example below,

public class B
{
@Id
private String id;
private String value;

@Override
public String toString(){
return String.format("B[id='%s', value='%s']",id,value);
}
}
public class A
{
@DBRef(lazy=true)
public B b;

@Override
public String toString()
{
return String.format("A[b='%s']",b);
}
}

if class A is loaded with current DefaultDbRefResolver, when class B.toString() is called, it will result NullPointerException since the toString method is not actually from Object.
If we also check "method.getDeclaringClass()==Object.class," it will resolve the issue