From bc27c7c464988e88ca36217b434e1014ecdcdc2a Mon Sep 17 00:00:00 2001 From: Clara Fang Date: Sat, 19 Feb 2022 22:28:26 -0500 Subject: [PATCH] Replace occurrences of getParameterTypes().length and getParameters().length with getParameterCount() Closes #10333 --- .../adapters/jbossweb/JBossWebPrincipalFactory.java | 2 +- .../java/org/keycloak/common/util/reflections/Types.java | 4 ++-- .../main/java/org/keycloak/storage/ldap/LDAPUtils.java | 2 +- .../models/utils/reflection/MethodPropertyImpl.java | 8 ++++---- .../org/keycloak/testsuite/admin/PermissionsTest.java | 2 +- .../migration/cluster/MultiVersionClusterTest.java | 2 +- 6 files changed, 10 insertions(+), 10 deletions(-) diff --git a/adapters/oidc/as7-eap6/as7-adapter-spi/src/main/java/org/keycloak/adapters/jbossweb/JBossWebPrincipalFactory.java b/adapters/oidc/as7-eap6/as7-adapter-spi/src/main/java/org/keycloak/adapters/jbossweb/JBossWebPrincipalFactory.java index b7916f20de..d95d21a1d4 100755 --- a/adapters/oidc/as7-eap6/as7-adapter-spi/src/main/java/org/keycloak/adapters/jbossweb/JBossWebPrincipalFactory.java +++ b/adapters/oidc/as7-eap6/as7-adapter-spi/src/main/java/org/keycloak/adapters/jbossweb/JBossWebPrincipalFactory.java @@ -163,7 +163,7 @@ public class JBossWebPrincipalFactory implements PrincipalFactory { static Constructor findJBossGenericPrincipalConstructor() { for (Constructor c : JBossGenericPrincipal.class.getConstructors()) { - if (c.getParameterTypes().length == 9 && + if (c.getParameterCount() == 9 && c.getParameterTypes()[0].equals(Realm.class) && c.getParameterTypes()[1].equals(String.class) && c.getParameterTypes()[3].equals(List.class) && diff --git a/common/src/main/java/org/keycloak/common/util/reflections/Types.java b/common/src/main/java/org/keycloak/common/util/reflections/Types.java index adf8626ac3..377f5102f4 100644 --- a/common/src/main/java/org/keycloak/common/util/reflections/Types.java +++ b/common/src/main/java/org/keycloak/common/util/reflections/Types.java @@ -163,9 +163,9 @@ public class Types { if (method == intfMethod) return true; 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 intfParam = intfMethod.getParameterTypes()[i]; diff --git a/federation/ldap/src/main/java/org/keycloak/storage/ldap/LDAPUtils.java b/federation/ldap/src/main/java/org/keycloak/storage/ldap/LDAPUtils.java index 9a1ce30aa6..20335d1db9 100755 --- a/federation/ldap/src/main/java/org/keycloak/storage/ldap/LDAPUtils.java +++ b/federation/ldap/src/main/java/org/keycloak/storage/ldap/LDAPUtils.java @@ -323,7 +323,7 @@ public class LDAPUtils { @Override public boolean methodMatches(Method m) { if ((m.getName().startsWith("get") || m.getName().startsWith("is")) - && m.getParameterTypes().length > 0) { + && m.getParameterCount() > 0) { return false; } diff --git a/server-spi-private/src/main/java/org/keycloak/models/utils/reflection/MethodPropertyImpl.java b/server-spi-private/src/main/java/org/keycloak/models/utils/reflection/MethodPropertyImpl.java index befd024788..679035c78e 100755 --- a/server-spi-private/src/main/java/org/keycloak/models/utils/reflection/MethodPropertyImpl.java +++ b/server-spi-private/src/main/java/org/keycloak/models/utils/reflection/MethodPropertyImpl.java @@ -49,7 +49,7 @@ class MethodPropertyImpl implements MethodProperty { if (method.getReturnType() == Void.TYPE) { throw new IllegalArgumentException( "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( "Invalid accessor method, must have zero arguments if starts with 'get'. Method: " + method); } @@ -59,7 +59,7 @@ class MethodPropertyImpl implements MethodProperty { if (method.getReturnType() != Void.TYPE) { throw new IllegalArgumentException( "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( "Invalid accessor method, must have one argument if starts with 'set'. Method: " + method); } @@ -151,7 +151,7 @@ class MethodPropertyImpl implements MethodProperty { Method[] methods = clazz.getMethods(); for (Method method : methods) { 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)) { return method; } @@ -163,7 +163,7 @@ class MethodPropertyImpl implements MethodProperty { private static Method getGetterMethod(Class clazz, String name) { for (Method method : clazz.getDeclaredMethods()) { String methodName = method.getName(); - if (method.getParameterTypes().length == 0) { + if (method.getParameterCount() == 0) { if (methodName.startsWith(GETTER_METHOD_PREFIX)) { if (Introspector.decapitalize(methodName.substring(GETTER_METHOD_PREFIX_LENGTH)).equals(name)) { return method; diff --git a/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/admin/PermissionsTest.java b/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/admin/PermissionsTest.java index 71002a0888..9387b93962 100644 --- a/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/admin/PermissionsTest.java +++ b/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/admin/PermissionsTest.java @@ -1973,7 +1973,7 @@ public class PermissionsTest extends AbstractKeycloakTest { List ignoreList = Arrays.asList(ignore); 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 { Object o = m.invoke(rep); assertNull("Expected " + m.getName() + " to be null", o); diff --git a/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/migration/cluster/MultiVersionClusterTest.java b/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/migration/cluster/MultiVersionClusterTest.java index c728d16809..f3610f2459 100644 --- a/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/migration/cluster/MultiVersionClusterTest.java +++ b/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/migration/cluster/MultiVersionClusterTest.java @@ -276,7 +276,7 @@ public class MultiVersionClusterTest extends AbstractClusterTest { if (Arrays.asList(classForName.getDeclaredConstructors()).stream() .filter(c -> !c.isSynthetic()) - .anyMatch(c -> c.getParameterTypes().length == 0 )) { + .anyMatch(c -> c.getParameterCount() == 0 )) { newInstance = Reflections.newInstance(classForName); } else { Constructor constructor = Arrays.asList(classForName.getDeclaredConstructors()).stream()