apache / apache/kyuubi

ReflectUtils re-labels invocation and bind failures as missing members

Open
#7,731 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Scala
Stars
2.4k
Forks
1k
PR merge metrics
No merged PRs in 30d

Description

### Describe the bug

`ReflectUtils.getField` and `invokeAs` wrap the whole body in one `try` and rewrite any `Exception` into a missing-member message:

```scala
def invokeAs[T](target: AnyRef, methodName: String, args: (Class[_], AnyRef)*): T = {
val (clz, obj) = getTargetClass(target)
val argClasses = args.map(_._1)
try {
val method = DynMethods.builder(methodName)
.hiddenImpl(clz, argClasses: _*)
.impl(clz, argClasses: _*)
.buildChecked
if (method.isStatic) {
method.asStatic.invoke[T](args.map(_._2): _*)
} else {
method.bind(obj).invoke[T](args.map(_._2): _*)
}
} catch {
case e: Exception =>
throw new RuntimeException(
s"$clz does not have $methodName${argClasses.map(_.getName).mkString("(", ", ", ")")}",
e)
}
}
```

The `catch` covers more than the lookup. Once `buildChecked` has found the method, `invoke` runs inside the same `try`, so an exception thrown by the invoked method itself is relabeled `"$clz does not have $methodName(...)"`, a missing-member message for a member that was found and ran. `getField` has the same shape: a failure while binding or reading the found field is reported as a missing field. The real exception survives only as the wrapper's cause.

That points a reader at a lookup problem that does not exist. These helpers reflect into Spark and Hive internals, so when a called method throws (a bad argument, an illegal state), the failure reads as if the method were missing.

### Affects Version(s)

master (1.13.0-SNAPSHOT), and earlier releases carrying `kyuubi-util-scala`.

### Are you willing to submit PR?

Yes.

Contributor guide

Open the contributing guide

Research direction

Start with ReflectUtils.getField and invokeAs, focusing on the try/catch boundaries around buildChecked, binding, reading, and invocation. Verify the behavior with the existing reflection-related tests, if present; done means lookup failures still receive missing-member context while exceptions from a found field or method are reported without being relabeled as missing.

Written by the indexing model from the issue text.

Assessment

Tech stack
scala
Domain
backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Active
Clarity
Clearly specified
Newbie friendliness
72/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.