Replace occurrences of getParameterTypes().length and getParameters().length with getParameterCount()

This should reduce GC pressure.

Closes #12644
This commit is contained in:
Clara Fang 2022-02-20 04:28:26 +01:00 committed by Hynek Mlnařík
parent ccc0449314
commit 4643fd09e3
5 changed files with 9 additions and 9 deletions

View file

@ -163,9 +163,9 @@ public class Types {
if (method == intfMethod) return true; if (method == intfMethod) return true;
if (!method.getName().equals(intfMethod.getName())) return false; if (!method.getName().equals(intfMethod.getName())) return false;
if (method.getParameterTypes().length != intfMethod.getParameterTypes().length) return false; if (method.getParameterCount() != intfMethod.getParameterCount()) return false;
for (int i = 0; i < method.getParameterTypes().length; i++) for (int i = 0; i < method.getParameterCount(); i++)
{ {
Class rootParam = method.getParameterTypes()[i]; Class rootParam = method.getParameterTypes()[i];
Class intfParam = intfMethod.getParameterTypes()[i]; Class intfParam = intfMethod.getParameterTypes()[i];

View file

@ -323,7 +323,7 @@ public class LDAPUtils {
@Override @Override
public boolean methodMatches(Method m) { public boolean methodMatches(Method m) {
if ((m.getName().startsWith("get") || m.getName().startsWith("is")) if ((m.getName().startsWith("get") || m.getName().startsWith("is"))
&& m.getParameterTypes().length > 0) { && m.getParameterCount() > 0) {
return false; return false;
} }

View file

@ -49,7 +49,7 @@ class MethodPropertyImpl<V> implements MethodProperty<V> {
if (method.getReturnType() == Void.TYPE) { if (method.getReturnType() == Void.TYPE) {
throw new IllegalArgumentException( throw new IllegalArgumentException(
"Invalid accessor method, must have return value if starts with 'get'. Method: " + method); "Invalid accessor method, must have return value if starts with 'get'. Method: " + method);
} else if (method.getParameterTypes().length > 0) { } else if (method.getParameterCount() > 0) {
throw new IllegalArgumentException( throw new IllegalArgumentException(
"Invalid accessor method, must have zero arguments if starts with 'get'. Method: " + method); "Invalid accessor method, must have zero arguments if starts with 'get'. Method: " + method);
} }
@ -59,7 +59,7 @@ class MethodPropertyImpl<V> implements MethodProperty<V> {
if (method.getReturnType() != Void.TYPE) { if (method.getReturnType() != Void.TYPE) {
throw new IllegalArgumentException( throw new IllegalArgumentException(
"Invalid accessor method, must not have return value if starts with 'set'. Method: " + method); "Invalid accessor method, must not have return value if starts with 'set'. Method: " + method);
} else if (method.getParameterTypes().length != 1) { } else if (method.getParameterCount() != 1) {
throw new IllegalArgumentException( throw new IllegalArgumentException(
"Invalid accessor method, must have one argument if starts with 'set'. Method: " + method); "Invalid accessor method, must have one argument if starts with 'set'. Method: " + method);
} }
@ -151,7 +151,7 @@ class MethodPropertyImpl<V> implements MethodProperty<V> {
Method[] methods = clazz.getMethods(); Method[] methods = clazz.getMethods();
for (Method method : methods) { for (Method method : methods) {
String methodName = method.getName(); String methodName = method.getName();
if (methodName.startsWith(SETTER_METHOD_PREFIX) && method.getParameterTypes().length == 1) { if (methodName.startsWith(SETTER_METHOD_PREFIX) && method.getParameterCount() == 1) {
if (Introspector.decapitalize(methodName.substring(SETTER_METHOD_PREFIX_LENGTH)).equals(name)) { if (Introspector.decapitalize(methodName.substring(SETTER_METHOD_PREFIX_LENGTH)).equals(name)) {
return method; return method;
} }
@ -163,7 +163,7 @@ class MethodPropertyImpl<V> implements MethodProperty<V> {
private static Method getGetterMethod(Class<?> clazz, String name) { private static Method getGetterMethod(Class<?> clazz, String name) {
for (Method method : clazz.getDeclaredMethods()) { for (Method method : clazz.getDeclaredMethods()) {
String methodName = method.getName(); String methodName = method.getName();
if (method.getParameterTypes().length == 0) { if (method.getParameterCount() == 0) {
if (methodName.startsWith(GETTER_METHOD_PREFIX)) { if (methodName.startsWith(GETTER_METHOD_PREFIX)) {
if (Introspector.decapitalize(methodName.substring(GETTER_METHOD_PREFIX_LENGTH)).equals(name)) { if (Introspector.decapitalize(methodName.substring(GETTER_METHOD_PREFIX_LENGTH)).equals(name)) {
return method; return method;

View file

@ -1973,7 +1973,7 @@ public class PermissionsTest extends AbstractKeycloakTest {
List<String> ignoreList = Arrays.asList(ignore); List<String> ignoreList = Arrays.asList(ignore);
for (Method m : rep.getClass().getDeclaredMethods()) { for (Method m : rep.getClass().getDeclaredMethods()) {
if (m.getParameters().length == 0 && m.getName().startsWith("get") && !ignoreList.contains(m.getName())) { if (m.getParameterCount() == 0 && m.getName().startsWith("get") && !ignoreList.contains(m.getName())) {
try { try {
Object o = m.invoke(rep); Object o = m.invoke(rep);
assertNull("Expected " + m.getName() + " to be null", o); assertNull("Expected " + m.getName() + " to be null", o);

View file

@ -276,7 +276,7 @@ public class MultiVersionClusterTest extends AbstractClusterTest {
if (Arrays.asList(classForName.getDeclaredConstructors()).stream() if (Arrays.asList(classForName.getDeclaredConstructors()).stream()
.filter(c -> !c.isSynthetic()) .filter(c -> !c.isSynthetic())
.anyMatch(c -> c.getParameterTypes().length == 0 )) { .anyMatch(c -> c.getParameterCount() == 0 )) {
newInstance = Reflections.newInstance(classForName); newInstance = Reflections.newInstance(classForName);
} else { } else {
Constructor<?> constructor = Arrays.asList(classForName.getDeclaredConstructors()).stream() Constructor<?> constructor = Arrays.asList(classForName.getDeclaredConstructors()).stream()