Skip to content

Conversation

@loveTsong
Copy link
Contributor

🔗 相关问题 / Related Issue

Issue 链接 / Issue Link: #595

  • 我已经创建了相关 Issue 并进行了讨论 / I have created and discussed the related issue
  • 这是一个微小的修改(如错别字),不需要 Issue / This is a trivial change (like typo fix) that doesn't need an issue

📋 变更类型 / Type of Change

  • 🐛 Bug 修复 / Bug fix (non-breaking change which fixes an issue)
  • ✨ 新功能 / New feature (non-breaking change which adds functionality)
  • 💥 破坏性变更 / Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • 📚 文档更新 / Documentation update
  • 🔧 重构 / Refactoring (no functional changes)
  • ⚡ 性能优化 / Performance improvement
  • 📦 依赖升级 / Dependency upgrade (update dependencies to newer versions)
  • 🚀 功能增强 / Feature enhancement (improve existing functionality without breaking changes)
  • 🧹 代码清理 / Code cleanup

📝 变更目的 / Purpose of Change

修复 DataMateKnowledgeBaseManager 和 QianfanKnowledgeBaseManager 中的空指针异常问题。当 HTTP 状态码不在 exceptionMap 中时,使用 get() 方法会返回 null,导致调用 .getMsg() 时抛出 NullPointerException。

Fix the NullPointerException issue in DataMateKnowledgeBaseManager and QianfanKnowledgeBaseManager. When the HTTP status code is not in the exceptionMap, using the get() method returns null, causing a NullPointerException when calling .getMsg().

📋 主要变更 / Brief Changelog

  • DataMateKnowledgeBaseManager: 使用 getOrDefault() 替代 get() 方法,当状态码不存在时返回默认的 INTERNAL_SERVICE_ERROR

  • QianfanKnowledgeBaseManager: 使用 getOrDefault() 替代 get() 方法,当状态码不存在时返回默认的 INTERNAL_SERVICE_ERROR

  • DataMateKnowledgeBaseManager: Use getOrDefault() instead of get() method, return default INTERNAL_SERVICE_ERROR when status code is not found

  • QianfanKnowledgeBaseManager: Use getOrDefault() instead of get() method, return default INTERNAL_SERVICE_ERROR when status code is not found

🧪 验证变更 / Verifying this Change

测试步骤 / Test Steps

  1. 编译 data-mate-knowledge 模块:mvn clean compile (成功)

  2. 编译 qianfan-knowledge 模块:mvn clean compile (成功)

  3. 验证代码逻辑:当 statusCode 不在 exceptionMap 中时,返回 INTERNAL_SERVICE_ERROR 而不是抛出 NullPointerException

  4. Compile data-mate-knowledge module: mvn clean compile (passed)

  5. Compile qianfan-knowledge module: mvn clean compile (passed)

  6. Verify code logic: When statusCode is not in exceptionMap, return INTERNAL_SERVICE_ERROR instead of throwing NullPointerException

测试覆盖 / Test Coverage

  • 我已经添加了单元测试 / I have added unit tests
  • 所有现有测试都通过 / All existing tests pass
  • 我已经进行了手动测试 / I have performed manual testing

📸 截图 / Screenshots

不适用 / Not applicable

✅ 贡献者检查清单 / Contributor Checklist

基本要求 / Basic Requirements:

  • 确保有 GitHub Issue 对应这个变更(微小变更如错别字除外)/ Make sure there is a Github issue filed for change (trivial changes like typos excluded)
  • 你的 Pull Request 只解决一个 Issue,没有包含其他不相关的变更 / Your PR addresses just this issue, without pulling in other changes - one PR resolves one issue
  • PR 中的每个 commit 都有有意义的主题行和描述 / Each commit in PR has a meaningful subject line and body

代码质量 / Code Quality:

  • 我的代码遵循项目的代码规范 / My code follows the project's coding standards
  • 我已经进行了自我代码审查 / I have performed a self-review of my code
  • 我已经为复杂的代码添加了必要的注释 / I have commented my code, particularly in hard-to-understand areas

测试要求 / Testing Requirements:

  • 我已经编写了必要的单元测试来验证逻辑正确性 / I have written necessary unit-tests to verify the logic correction
  • 当存在跨模块依赖时,我尽量使用了 mock / I have used mocks when cross-module dependencies exist
  • 基础检查通过:mvn -B clean package -Dmaven.test.skip=truenpm install --force && npm run build:pro / Basic checks pass
  • 单元测试通过:mvn clean install / Unit tests pass

文档和兼容性 / Documentation and Compatibility:

  • 我已经更新了相应的文档 / I have made corresponding changes to the documentation
  • 如果有破坏性变更,我已经在 PR 描述中详细说明 / If there are breaking changes, I have documented them in detail
  • 我已经考虑了向后兼容性 / I have considered backward compatibility

📋 附加信息 / Additional Notes

这是一个简单的修复,仅修改了异常处理逻辑,不影响其他功能。修复后的代码使用 getOrDefault() 方法,当状态码不存在时返回默认的 INTERNAL_SERVICE_ERROR,避免了空指针异常。

This is a simple fix that only modifies the exception handling logic and does not affect other functionality. The fixed code uses the getOrDefault() method, returning the default INTERNAL_SERVICE_ERROR when the status code is not found, avoiding the NullPointerException.


审查者注意事项 / Reviewer Notes:

请重点关注异常处理逻辑是否正确,以及默认错误码的选择是否合理。

Please focus on whether the exception handling logic is correct and whether the default error code selection is reasonable.

🤖 Create by Agent

… codes (ModelEngine-Group#595)

- Use getOrDefault() instead of get() in handleException method
- Return INTERNAL_SERVICE_ERROR when statusCode is not in exceptionMap
- Apply fix to both DataMateKnowledgeBaseManager and QianfanKnowledgeBaseManager
int statusCode = ex.statusCode();
log.error(this.exceptionMap.get(statusCode).getMsg(), ex);
return new KnowledgeException(this.exceptionMap.get(statusCode), ex, ex.getSimpleMessage());
KnowledgeManagerRetCode retCode = this.exceptionMap.getOrDefault(statusCode, INTERNAL_SERVICE_ERROR);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

缺少单元测试覆盖

int statusCode = ex.statusCode();
log.error(this.exceptionMap.get(statusCode).getMsg(), ex);
return new KnowledgeException(this.exceptionMap.get(statusCode), ex.getSimpleMessage());
KnowledgeManagerRetCode retCode = this.exceptionMap.getOrDefault(statusCode, INTERNAL_SERVICE_ERROR);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

缺少单元测试覆盖

@loveTsong loveTsong force-pushed the bugfix/data-mate-knowledge-nullpointer-fix branch from f253013 to db094ff Compare February 12, 2026 03:08
@loveTsong loveTsong self-assigned this Feb 12, 2026
@loveTsong loveTsong added type: bug A general bug in: builder Issues in app-builder modules labels Feb 12, 2026
@loveTsong loveTsong added this to the 1.3.3 milestone Feb 12, 2026
@loveTsong loveTsong linked an issue Feb 12, 2026 that may be closed by this pull request
@loveTsong loveTsong added this to Nova Feb 12, 2026
@loveTsong loveTsong merged commit e11ef3e into ModelEngine-Group:1.3.x Feb 12, 2026
1 check passed
@github-project-automation github-project-automation bot moved this to Done in Nova Feb 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

in: builder Issues in app-builder modules type: bug A general bug

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

DataMateKnowledge中错误处理场景可能出现空指针

1 participant