Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

guavaRetry模块出现问题

未关闭
#13 4 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
3/5
预计耗时
1-2 天
新手友好度
45/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
停滞
技术栈
java

调研方向

Read TestClient.java and guavaRetry.java, focusing first on the retryIfResult call and how concurrent requests produce responses. Reproduce the issue with more than ten threads and verify that a null response does not stop retry handling or cause a NullPointerException; the retry listener should report subsequent attempts.

由索引模型根据 Issue 内容生成。

描述

我在TestClient.java里用for循环创建10个以上线程同时向服务器发送请求时会抛出几个异常,似乎是客户端的请求得到了空的返回结果
尤其是后面的线程在执行到guavaRetry.java的

.retryIfResult(response -> Objects.equals(response.getCode(), 500))

这行代码时会抛出异常
java.lang.NullPointerException: Cannot invoke "part1.common.Message.RpcResponse.getCode()" because "response" is null
然后retryer不会进行下一次重试了,控制台输出也只有RetryListener: 第1次调用 没有第二次和第三次
我把代码改成

.retryIfResult(response -> response == null || Objects.equals(response.getCode(), 500))

之后才能正常进行下一次重试
请问这是代码的问题还是我运行方式有问题

public class TestClient {
    public static void main(String[] args) throws InterruptedException {
        ClientProxy clientProxy=new ClientProxy();
        UserService proxy=clientProxy.getProxy(UserService.class);
        for(int i = 0; i < 15; i++) {
            Integer i1 = i;
            new Thread(()->{
                try{
                    User user = proxy.getUserByUserId(i1);

                    System.out.println("从服务端得到的user="+user.toString());

                    Integer id = proxy.insertUserId(User.builder().id(i1).userName("User" + i1.toString()).sex(true).build());
                    System.out.println("向服务端插入user的id"+id);
                } catch (NullPointerException e){
                    System.out.println("user为空");
                    e.printStackTrace();
                }
            }).start();
            }
        }
//        User u=User.builder().id(100).userName("wxx").sex(true).build();
//        Integer id = proxy.insertUserId(u);
//        System.out.println("向服务端插入user的id"+id);
}

微信图片_20240725144009

主要语言
Java
星标
694
派生
165
PR 合并指标
30 天内没有已合并 PR

环境准备

这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

youngyangyang04/RPC-Java 的其他 Issue

查看 youngyangyang04/RPC-Java 的全部 Issue

相似的 Issue

更多 Java Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。