DATACMNS-619 - DefaultCrudMethods now exposes accessible methods.
We now make sure that all methods detected are made accessible so that clients using them can reflectively invoke them without additional checks.
This commit is contained in:
@@ -29,6 +29,8 @@ import org.springframework.data.repository.PagingAndSortingRepository;
|
||||
import org.springframework.data.repository.core.CrudMethods;
|
||||
import org.springframework.data.repository.core.RepositoryMetadata;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.ClassUtils;
|
||||
import org.springframework.util.ReflectionUtils;
|
||||
|
||||
/**
|
||||
* Default implementation to discover CRUD methods based on the given {@link RepositoryMetadata}. Will detect methods
|
||||
@@ -167,6 +169,27 @@ public class DefaultCrudMethods implements CrudMethods {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Looks up the most specific method for the given method and type and returns an accessible version of discovered
|
||||
* {@link Method} if found.
|
||||
*
|
||||
* @param method
|
||||
* @param type
|
||||
* @see ClassUtils#getMostSpecificMethod(Method, Class)
|
||||
* @return
|
||||
*/
|
||||
private static Method getMostSpecificMethod(Method method, Class<?> type) {
|
||||
|
||||
Method result = ClassUtils.getMostSpecificMethod(method, type);
|
||||
|
||||
if (result == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
ReflectionUtils.makeAccessible(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.repository.core.support.CrudMethods#getSaveMethod()
|
||||
|
||||
@@ -174,6 +174,8 @@ class ReflectionRepositoryInvoker implements RepositoryInvoker {
|
||||
Assert.notNull(method, "Method must not be null!");
|
||||
Assert.notNull(parameters, "Parameters must not be null!");
|
||||
|
||||
ReflectionUtils.makeAccessible(method);
|
||||
|
||||
return invoke(method, prepareParameters(method, parameters, pageable, sort));
|
||||
}
|
||||
|
||||
@@ -225,8 +227,6 @@ class ReflectionRepositoryInvoker implements RepositoryInvoker {
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
private <T> T invoke(Method method, Object... arguments) {
|
||||
|
||||
ReflectionUtils.makeAccessible(method);
|
||||
return (T) ReflectionUtils.invokeMethod(method, repository, arguments);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user