Skip to content

Commit

Permalink
[KYUUBI #5497] [AuthZ] Simplify debug message for missing field/metho…
Browse files Browse the repository at this point in the history
…d in ReflectUtils

### _Why are the changes needed?_

It's easy for developers to check a member or method from a Java class using a code viewer or online Java doc.

The current debug msg is kinda noisy for them to locate the key information they want, which is
Java class and field name. It makes our debug log unreadable.

### _How was this patch tested?_
- [ ] Add some test cases that check the changes thoroughly including negative and positive cases if possible

- [ ] Add screenshots for manual tests if appropriate

- [x] [Run test](https://kyuubi.readthedocs.io/en/master/contributing/code/testing.html#running-tests) locally before make a pull request

### _Was this patch authored or co-authored using generative AI tooling?_

Closes #5497 from yaooqinn/debug.

Closes #5497

3ad42d5 [Kent Yao] addr comments
23e8e7a [Kent Yao] [AuthZ] Simplify debug message for missing field/methond in ReflectUtils
b7a7fbb [Kent Yao] [AuthZ] Simplify debug message for missing field/methond in ReflectUtils
9f94c62 [Kent Yao] [AuthZ] Simplify debug message for missing field/methond in ReflectUtils
78a66a3 [Kent Yao] [AuthZ] Simplify debug message for missing field/methond in ReflectUtils

Authored-by: Kent Yao <yao@apache.org>
Signed-off-by: liangbowen <liangbowen@gf.com.cn>
  • Loading branch information
yaooqinn authored and davidyuan1223 committed Oct 26, 2023
1 parent 0c8be79 commit c039e1b
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
</File>
</Appenders>
<Loggers>
<Root level="INFO">
<Root level="DEBUG">
<AppenderRef ref="stdout"/>
<AppenderRef ref="file"/>
</Root>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand Down Expand Up @@ -92,14 +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(", ")}]",
s"$clz does not have $methodName${argClasses.map(_.getName).mkString("(", ", ", ")")}",
e)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)]")
}("class org.apache.kyuubi.util.reflect.ObjectA$ does not have methodNotExists(" +
"java.lang.String, java.lang.String)")
}
}

Expand Down

0 comments on commit c039e1b

Please sign in to comment.