Skip to content

fix: correct error message display and improve agent class loading robustness (fixes #1)#2

Merged
wl2027 merged 1 commit into
mainfrom
claude/lucid-franklin-nxqJj
May 26, 2026
Merged

fix: correct error message display and improve agent class loading robustness (fixes #1)#2
wl2027 merged 1 commit into
mainfrom
claude/lucid-franklin-nxqJj

Conversation

@wl2027
Copy link
Copy Markdown
Owner

@wl2027 wl2027 commented May 26, 2026

问题分析 (Issue #1 - ClassNotFoundException)

经过代码分析,找到了两个导致问题的 bug。


Bug 1(关键):错误弹窗显示的是错误的变量

文件RuntimeEvaluationCallback.java 第 65 行

// 修复前(错误)
Messages.showErrorDialog(
    RuntimePivotBundle.message("runtime.pivot.plugin.action.callback.error", myErrorOccurred),
    ...
);

// 修复后(正确)
Messages.showErrorDialog(
    RuntimePivotBundle.message("runtime.pivot.plugin.action.callback.error", errorMessage),
    ...
);

根因myErrorOccurredConsumer<String> 类型的 lambda 回调字段,而 errorMessage 才是方法参数中的实际错误字符串。消息模板 {0} 需要一个字符串,传入 Consumer 对象后显示的是其 toString()(如 null 或 lambda 引用地址),导致用户无法看到真实的 ClassNotFoundException 信息。


Bug 2(增强):agent 类加载缺乏回退机制

文件ActionExecutorUtil.java

原代码只通过 ClassLoader.getSystemClassLoader() 查找 com.runtime.pivot.agent.ActionExecutor,在以下场景会失败:

  • 远程调试(远端 JVM 未附加 agent)
  • 使用自定义类加载器的框架(如某些 OSGi 容器)

修复:依次尝试系统类加载器 → 线程上下文类加载器,两者都失败时抛出带有明确提示的异常,告知用户需要重启应用并附加 agent。

变更内容

  • RuntimeEvaluationCallback.errorOccurred(): myErrorOccurrederrorMessage
  • ActionExecutorUtil.EXECUTE_EXPRESSION: 添加 Thread 上下文类加载器回退,并在 agent 未找到时输出可读的错误提示

测试

  • 当 agent 正常加载时,行为与修复前一致
  • ClassNotFoundException 发生时,弹窗正确显示实际异常信息
  • 当系统类加载器找不到 agent 类时,尝试线程上下文类加载器作为回退

Generated by Claude Code

…bustness

- RuntimeEvaluationCallback.errorOccurred(): was passing myErrorOccurred
  (a Consumer<String> lambda) instead of errorMessage (the actual error
  string) to the message bundle, causing the error dialog to show a
  garbled Consumer.toString() rather than the real ClassNotFoundException.

- ActionExecutorUtil.EXECUTE_EXPRESSION: add Thread context classloader
  as a fallback when getSystemClassLoader() cannot find the agent class,
  and throw a descriptive message if neither loader succeeds (e.g. when
  debugging remotely without the agent attached).

Fixes #1
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: fca02a0370

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

"try { actionExecutorClass = java.lang.ClassLoader.getSystemClassLoader().loadClass(\"com.runtime.pivot.agent.ActionExecutor\"); } catch (java.lang.ClassNotFoundException rtPivotE) {}\n" +
"if (actionExecutorClass == null) {\n" +
" java.lang.ClassLoader rtPivotCtxCl = java.lang.Thread.currentThread().getContextClassLoader();\n" +
" if (rtPivotCtxCl != null) { actionExecutorClass = rtPivotCtxCl.loadClass(\"com.runtime.pivot.agent.ActionExecutor\"); }\n" +
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Catch context-loader miss before final agent-not-found error

In ActionExecutorUtil.EXECUTE_EXPRESSION, the fallback branch calls rtPivotCtxCl.loadClass(...) without a try/catch, so when the thread context class loader exists but also cannot find com.runtime.pivot.agent.ActionExecutor, a ClassNotFoundException is thrown immediately and the new explicit guidance ("Please restart the application with the agent attached.") is never reached. This regresses the intended error clarity in common environments where a context class loader is present but does not contain the agent; wrap the context-loader call similarly to the system-loader attempt so the final custom exception path is reliably used.

Useful? React with 👍 / 👎.

@wl2027 wl2027 merged commit 44becb1 into main May 26, 2026
4 of 6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants