spring-projects / spring-projects/spring-data-mongodb

Why is DefaultDbRefResolver.LazyLoadingInterceptor avoiding ONLY the resolution process when method's declaring class is Object [DATAMONGO-1353]

Open
#2,270 0 comments 0 reactions 1 assignee View on GitHub

@odrotbohm is already working on this.

Since Dec 30, 2020.

in: core in: mapping type: enhancement
Dominant language
Java
Stars
1.7k
Forks
1.1k
PR merge metrics
No merged PRs in 30d

Description

Jordi Llach Fernandez opened DATAMONGO-1353 and commented

Code taken from the intercept method public Object intercept(Object obj, Method method, Object[] args, MethodProxy proxy) throws Throwable of the above mentioned DefaultDbRefResolver.LazyLoadingInterceptor

...
if (isObjectMethod(method) && Object.class.equals(method.getDeclaringClass())) {

			if (ReflectionUtils.isToStringMethod(method)) {
				return proxyToString(proxy);
			}

			if (ReflectionUtils.isEqualsMethod(method)) {
				return proxyEquals(proxy, args[0]);
			}

			if (ReflectionUtils.isHashCodeMethod(method)) {
				return proxyHashCode(proxy);
			}

			// DATAMONGO-1076 - finalize methods should not trigger proxy initialization
			if (FINALIZE_METHOD.equals(method)) {
				return null;
			}
...
}

I do not see any good reason for this check isObjectMethod(method) && Object.class.equals(method.getDeclaringClass(), and in fact proxyToString, proxyEquals and proxyHashCode implementations could always be used instead of the original ones, preventing the resolution process when for instance a proxy of this kind is stored in a map.
Maybe I am wrong


Affects: 1.7.2 (Fowler SR2)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.