From da0e1498aad35dbb774a0b31135b749d7f086f2d Mon Sep 17 00:00:00 2001 From: Chia-Ping Tsai Date: Fri, 8 Mar 2024 10:18:27 +0800 Subject: [PATCH] refactor --- .../main/java/org/astraea/common/Utils.java | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/common/src/main/java/org/astraea/common/Utils.java b/common/src/main/java/org/astraea/common/Utils.java index 4dca63e45a..43eb3412b6 100644 --- a/common/src/main/java/org/astraea/common/Utils.java +++ b/common/src/main/java/org/astraea/common/Utils.java @@ -420,18 +420,13 @@ private static Object reflectionAttribute(Class clz, Object object, String at } private static Object reflectionMethod(Class clz, Object object, String attribute) { - do { - try { - var method = clz.getDeclaredMethod(attribute); - method.setAccessible(true); - return method.invoke(object); - } catch (NoSuchMethodException e) { - clz = clz.getSuperclass(); - } catch (Exception e) { - throw new RuntimeException(e); - } - } while (clz != null); - throw new RuntimeException(attribute + " is not existent in " + object.getClass().getName()); + try { + var method = clz.getDeclaredMethod(attribute); + method.setAccessible(true); + return method.invoke(object); + } catch (Exception e) { + throw new RuntimeException(e); + } } public static List constants(