From 78a66a33c85118e536bfae288a402eb2c68a9e75 Mon Sep 17 00:00:00 2001 From: Kent Yao Date: Mon, 23 Oct 2023 13:15:17 +0800 Subject: [PATCH 1/5] [AuthZ] Simplify debug message for missing field/methond in ReflectUtils --- .../src/test/resources/log4j2-test.xml | 2 +- .../apache/kyuubi/util/reflect/ReflectUtils.scala | 15 ++------------- 2 files changed, 3 insertions(+), 14 deletions(-) diff --git a/extensions/spark/kyuubi-spark-authz/src/test/resources/log4j2-test.xml b/extensions/spark/kyuubi-spark-authz/src/test/resources/log4j2-test.xml index 7aaf820ad11..70940728128 100644 --- a/extensions/spark/kyuubi-spark-authz/src/test/resources/log4j2-test.xml +++ b/extensions/spark/kyuubi-spark-authz/src/test/resources/log4j2-test.xml @@ -35,7 +35,7 @@ - + diff --git a/kyuubi-util-scala/src/main/scala/org/apache/kyuubi/util/reflect/ReflectUtils.scala b/kyuubi-util-scala/src/main/scala/org/apache/kyuubi/util/reflect/ReflectUtils.scala index 08916b8d150..bb7dc91f1d1 100644 --- a/kyuubi-util-scala/src/main/scala/org/apache/kyuubi/util/reflect/ReflectUtils.scala +++ b/kyuubi-util-scala/src/main/scala/org/apache/kyuubi/util/reflect/ReflectUtils.scala @@ -60,11 +60,7 @@ object ReflectUtils { } } catch { case e: Exception => - val candidates = - (clz.getDeclaredFields ++ clz.getFields).map(_.getName).distinct.sorted - throw new RuntimeException( - s"Field $fieldName not in $clz [${candidates.mkString(",")}]", - e) + throw new RuntimeException(s"$clz does not have $fieldName field", e) } } @@ -92,15 +88,8 @@ object ReflectUtils { } } catch { case e: Exception => - val candidates = - (clz.getDeclaredMethods ++ clz.getMethods) - .map(m => s"${m.getName}(${m.getParameterTypes.map(_.getName).mkString(", ")})") - .distinct.sorted - val argClassesNames = argClasses.map(_.getName) throw new RuntimeException( - s"Method $methodName(${argClassesNames.mkString(", ")})" + - s" not found in $clz [${candidates.mkString(", ")}]", - e) + s"$clz does not have $methodName method or incorrect arguments", e) } } From 9f94c62e40d9ceebab70305eee4ba40f6b9601f8 Mon Sep 17 00:00:00 2001 From: Kent Yao Date: Mon, 23 Oct 2023 13:28:17 +0800 Subject: [PATCH 2/5] [AuthZ] Simplify debug message for missing field/methond in ReflectUtils --- .../scala/org/apache/kyuubi/util/reflect/ReflectUtils.scala | 3 ++- .../org/apache/kyuubi/util/reflect/ReflectUtilsSuite.scala | 6 ++---- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/kyuubi-util-scala/src/main/scala/org/apache/kyuubi/util/reflect/ReflectUtils.scala b/kyuubi-util-scala/src/main/scala/org/apache/kyuubi/util/reflect/ReflectUtils.scala index bb7dc91f1d1..9019ff18758 100644 --- a/kyuubi-util-scala/src/main/scala/org/apache/kyuubi/util/reflect/ReflectUtils.scala +++ b/kyuubi-util-scala/src/main/scala/org/apache/kyuubi/util/reflect/ReflectUtils.scala @@ -89,7 +89,8 @@ object ReflectUtils { } catch { case e: Exception => throw new RuntimeException( - s"$clz does not have $methodName method or incorrect arguments", e) + s"$clz does not have $methodName method or incorrect arguments", + e) } } diff --git a/kyuubi-util-scala/src/test/scala/org/apache/kyuubi/util/reflect/ReflectUtilsSuite.scala b/kyuubi-util-scala/src/test/scala/org/apache/kyuubi/util/reflect/ReflectUtilsSuite.scala index 626aeebe226..18d52c64b85 100644 --- a/kyuubi-util-scala/src/test/scala/org/apache/kyuubi/util/reflect/ReflectUtilsSuite.scala +++ b/kyuubi-util-scala/src/test/scala/org/apache/kyuubi/util/reflect/ReflectUtilsSuite.scala @@ -75,10 +75,8 @@ class ReflectUtilsSuite extends AnyFunSuite { "methodNotExists", (classOf[String], "arg1"), (classOf[String], "arg2")) - }("Method methodNotExists(java.lang.String, java.lang.String) not found " + - "in class org.apache.kyuubi.util.reflect.ObjectA$ " + - "[equals(java.lang.Object), field5(), field6(), getClass(), hashCode(), method5(), " + - "method6(), notify(), notifyAll(), toString(), wait(), wait(long), wait(long, int)]") + }("org.apache.kyuubi.util.reflect.ObjectA$ does not have methodNotExists method or" + + " incorrect arguments") } } From b7a7fbb7acc888978b8007e9933efcbb7363fc95 Mon Sep 17 00:00:00 2001 From: Kent Yao Date: Mon, 23 Oct 2023 13:41:45 +0800 Subject: [PATCH 3/5] [AuthZ] Simplify debug message for missing field/methond in ReflectUtils --- .../org/apache/kyuubi/util/reflect/ReflectUtilsSuite.scala | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/kyuubi-util-scala/src/test/scala/org/apache/kyuubi/util/reflect/ReflectUtilsSuite.scala b/kyuubi-util-scala/src/test/scala/org/apache/kyuubi/util/reflect/ReflectUtilsSuite.scala index 18d52c64b85..c4113bacde4 100644 --- a/kyuubi-util-scala/src/test/scala/org/apache/kyuubi/util/reflect/ReflectUtilsSuite.scala +++ b/kyuubi-util-scala/src/test/scala/org/apache/kyuubi/util/reflect/ReflectUtilsSuite.scala @@ -69,13 +69,13 @@ class ReflectUtilsSuite extends AnyFunSuite { } test("test invokeAs method not found exception") { - interceptEquals[RuntimeException] { + interceptEquals[NoSuchMethodException] { invokeAs[String]( ObjectA, "methodNotExists", (classOf[String], "arg1"), (classOf[String], "arg2")) - }("org.apache.kyuubi.util.reflect.ObjectA$ does not have methodNotExists method or" + + }("class org.apache.kyuubi.util.reflect.ObjectA$ does not have methodNotExists method or" + " incorrect arguments") } } From 23e8e7a09b6022e2e7b09f8892adf310dcdc8185 Mon Sep 17 00:00:00 2001 From: Kent Yao Date: Mon, 23 Oct 2023 13:44:22 +0800 Subject: [PATCH 4/5] [AuthZ] Simplify debug message for missing field/methond in ReflectUtils --- .../org/apache/kyuubi/util/reflect/ReflectUtilsSuite.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kyuubi-util-scala/src/test/scala/org/apache/kyuubi/util/reflect/ReflectUtilsSuite.scala b/kyuubi-util-scala/src/test/scala/org/apache/kyuubi/util/reflect/ReflectUtilsSuite.scala index c4113bacde4..1eff78a1148 100644 --- a/kyuubi-util-scala/src/test/scala/org/apache/kyuubi/util/reflect/ReflectUtilsSuite.scala +++ b/kyuubi-util-scala/src/test/scala/org/apache/kyuubi/util/reflect/ReflectUtilsSuite.scala @@ -69,7 +69,7 @@ class ReflectUtilsSuite extends AnyFunSuite { } test("test invokeAs method not found exception") { - interceptEquals[NoSuchMethodException] { + interceptEquals[RuntimeException] { invokeAs[String]( ObjectA, "methodNotExists", From 3ad42d523658e1f97b2f1fa65519642580103e81 Mon Sep 17 00:00:00 2001 From: Kent Yao Date: Mon, 23 Oct 2023 17:26:32 +0800 Subject: [PATCH 5/5] addr comments --- .../scala/org/apache/kyuubi/util/reflect/ReflectUtils.scala | 2 +- .../org/apache/kyuubi/util/reflect/ReflectUtilsSuite.scala | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/kyuubi-util-scala/src/main/scala/org/apache/kyuubi/util/reflect/ReflectUtils.scala b/kyuubi-util-scala/src/main/scala/org/apache/kyuubi/util/reflect/ReflectUtils.scala index 9019ff18758..f985e406705 100644 --- a/kyuubi-util-scala/src/main/scala/org/apache/kyuubi/util/reflect/ReflectUtils.scala +++ b/kyuubi-util-scala/src/main/scala/org/apache/kyuubi/util/reflect/ReflectUtils.scala @@ -89,7 +89,7 @@ object ReflectUtils { } catch { case e: Exception => throw new RuntimeException( - s"$clz does not have $methodName method or incorrect arguments", + s"$clz does not have $methodName${argClasses.map(_.getName).mkString("(", ", ", ")")}", e) } } diff --git a/kyuubi-util-scala/src/test/scala/org/apache/kyuubi/util/reflect/ReflectUtilsSuite.scala b/kyuubi-util-scala/src/test/scala/org/apache/kyuubi/util/reflect/ReflectUtilsSuite.scala index 1eff78a1148..8f0090d5dda 100644 --- a/kyuubi-util-scala/src/test/scala/org/apache/kyuubi/util/reflect/ReflectUtilsSuite.scala +++ b/kyuubi-util-scala/src/test/scala/org/apache/kyuubi/util/reflect/ReflectUtilsSuite.scala @@ -75,8 +75,8 @@ class ReflectUtilsSuite extends AnyFunSuite { "methodNotExists", (classOf[String], "arg1"), (classOf[String], "arg2")) - }("class org.apache.kyuubi.util.reflect.ObjectA$ does not have methodNotExists method or" + - " incorrect arguments") + }("class org.apache.kyuubi.util.reflect.ObjectA$ does not have methodNotExists(" + + "java.lang.String, java.lang.String)") } }