Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Dec 24, 2025

修复 WxCpRedisConfigImpl 中的无限递归调用问题

问题描述

WxCpRedisConfigImpl 类的 getWebhookKey() 方法存在无限递归调用,导致栈溢出错误。

问题来源

该问题由提交 8e760a972ddbe9e79ca29d3b3d0499de36a293bf 引入,该提交日期为 2025-12-22 09:37:25 +0800,提交信息为 ":art: #3654 【开放平台】消息路由处理程序增加对小程序的支持"。

修复内容

  1. 修复 WxCpRedisConfigImpl.getWebhookKey() 方法,将 return this.getWebhookKey(); 改为 return this.webhookKey;
  2. 添加单元测试 WxCpRedisConfigImplTest 验证修复,确保:
    • 未设置 webhookKey 时返回 null,不抛出 StackOverflowError
    • 设置 webhookKey 后能够正确返回值
  3. 根据代码审查反馈优化测试:
    • 使用 Mockito mock JedisPool,避免测试时尝试真实连接 Redis
    • 恢复反射字段的可访问性设置
    • 移除不必要的 null 检查

验证结果

  • ✅ 代码风格检查通过(mvn checkstyle:check)
  • ✅ 编译构建通过(mvn clean compile)
  • ✅ 测试代码编译通过(mvn test-compile)
  • ✅ 代码审查反馈已全部处理
Original prompt

This section details on the original issue you should resolve

<issue_title>无限递归调用</issue_title>
<issue_description>WxCpRedisConfigImpl

@OverRide
public String getWebhookKey() {
return this.getWebhookKey();
}</issue_description>

<agent_instructions>这是哪次提交代码导致的?</agent_instructions>

Comments on the Issue (you are @copilot in this section)

Custom agent used: 全部用中文
需要用中文,包括PR标题和分析总结过程


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 2 commits December 24, 2025 02:08
Co-authored-by: binarywang <1343140+binarywang@users.noreply.github.com>
Co-authored-by: binarywang <1343140+binarywang@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix infinite recursive calls in WxCpRedisConfigImpl 修复 WxCpRedisConfigImpl.getWebhookKey() 无限递归调用 Dec 24, 2025
Copilot AI requested a review from binarywang December 24, 2025 02:14
@binarywang binarywang marked this pull request as ready for review December 24, 2025 07:07
Copilot AI review requested due to automatic review settings December 24, 2025 07:07
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

本 PR 修复了 WxCpRedisConfigImpl.getWebhookKey() 方法中的严重递归调用 bug,该方法错误地调用自身导致 StackOverflowError。修复方式是将递归调用改为直接返回实例变量,并添加了单元测试以验证修复有效性。

主要变更:

  • 修复无限递归调用 bug,将 return this.getWebhookKey(); 改为 return this.webhookKey;
  • 添加单元测试验证 getWebhookKey() 方法正确返回实例变量而非递归调用

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
weixin-java-cp/src/main/java/me/chanjar/weixin/cp/config/impl/WxCpRedisConfigImpl.java 修复 getWebhookKey() 方法的无限递归 bug,改为直接返回 webhookKey 字段
weixin-java-cp/src/test/java/me/chanjar/weixin/cp/config/impl/WxCpRedisConfigImplTest.java 新增单元测试验证 getWebhookKey() 方法的正确性,包括 null 值和反射设置值的测试场景

binarywang and others added 2 commits December 24, 2025 15:49
…WxCpRedisConfigImplTest.java

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…WxCpRedisConfigImplTest.java

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: binarywang <1343140+binarywang@users.noreply.github.com>
@binarywang binarywang merged commit 912ba35 into develop Dec 24, 2025
1 check passed
@binarywang binarywang deleted the copilot/fix-infinite-recursion-issue branch December 24, 2025 08:13
@binarywang binarywang added this to the 4.8.0 milestone Dec 24, 2025
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