Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

guavaRetry模块出现问题

Đang mở
#13 4 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức phù hợp với người mới
45/100
Loại issue
Lỗi
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Đình trệ
Công nghệ
java
Lĩnh vực
backend-api-design

Hướng nghiên cứu

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.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

我在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

Ngôn ngữ chính
Java
Star
694
Fork
165
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Chuẩn bị môi trường

Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của youngyangyang04/RPC-Java

Tất cả issue của youngyangyang04/RPC-Java

Issue tương tự

Thêm issue về Java

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.