Skip to content

DATAMONGO-884 - Crash on calling override method of Object class when the class is an DBRef(lazy=true) #152

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

Closed
wants to merge 1 commit into from

Conversation

juhgiyo
Copy link

@juhgiyo juhgiyo commented Mar 19, 2014

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

The method can be 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 really from Object class or is from overrided method,
it needs to explicitly check method.getDeclaringClass() with Object.class
@juhgiyo juhgiyo closed this Mar 19, 2014
@juhgiyo juhgiyo deleted the patch-1 branch March 19, 2014 06:54
@juhgiyo juhgiyo restored the patch-1 branch March 19, 2014 07:26
@juhgiyo juhgiyo changed the title Check if the method is an original Object method DATAMONGO-884 - Crash on calling override method of Object class when the class is an DBRef(lazy=true) Mar 19, 2014
@juhgiyo juhgiyo reopened this Mar 19, 2014
thomasdarimont pushed a commit that referenced this pull request Mar 19, 2014
We now initialise the proxy in case an Object-method is called that is overridden in the traget class.

Initial pull request: #152.
thomasdarimont pushed a commit that referenced this pull request Mar 19, 2014
We now initialise the proxy in case an Object-method is called that is overridden in the traget class.

Based on initial pull request: #152 of @juhgiyo.
Added additional test cases.

Original pull request: #153.
@juhgiyo juhgiyo closed this Mar 20, 2014
@juhgiyo juhgiyo deleted the patch-1 branch March 20, 2014 05:26
thomasdarimont pushed a commit that referenced this pull request Mar 27, 2014
We now initialize the proxy in case an Object-method is called that is overridden in the traget class. Removed the additional check for initialization and to-DBRef-methods as they're repeated in the target method.

Original pull requests: #152, #153.
thomasdarimont pushed a commit that referenced this pull request Mar 27, 2014
We now initialize the proxy in case an Object-method is called that is overridden in the traget class. Removed the additional check for initialization and to-DBRef-methods as they're repeated in the target method.

Original pull requests: #152, #153.
thomasdarimont pushed a commit that referenced this pull request Mar 28, 2014
We now initialise the proxy in case an Object-method is called that is overridden in the traget class.

Based on initial pull request: #152 of @juhgiyo.
Added additional test cases.

Original pull request: #153.
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

Successfully merging this pull request may close these issues.

1 participant