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

BackgroundFunctionExecutor.java failes to detect type when sub-classed

Đang mở
#95 1 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ó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
38/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, cloud

Hướng nghiên cứu

Bắt đầu trong BackgroundFunctionExecutor.java tại dòng 140 và kiểm tra backgroundFunctionTypeArgument. Tái hiện cấu trúc phân cấp MyExtendedBackgroundFunction và MyFunctionHandler được mô tả trong issue, sau đó xác minh rằng executor phát hiện MyReturnType đồng thời vẫn giữ nguyên hành vi đối với các kiểu BackgroundFunction được triển khai trực tiếp.

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

Mô tả

bug P3

Error Condition

Exception in thread "main" java.lang.RuntimeException: Could not determine the payload type for BackgroundFunction of type com.example.MyFunctionHandler; must implement BackgroundFunction for some T at com.google.cloud.functions.invoker.BackgroundFunctionExecutor.forClass(BackgroundFunctionExecutor.java:140) at com.google.cloud.functions.invoker.BackgroundFunctionExecutor.forClass(BackgroundFunctionExecutor.java:113) at com.google.cloud.functions.invoker.runner.Invoker.startServer(Invoker.java:256) at com.google.cloud.functions.invoker.runner.Invoker.main(Invoker.java:127)

Occurs when BackgroundFunction<T> is subclassed:

public abstract class MyExtendedBackgroundFunction<T> implements BackgroundFunction<T>

and

public class MyFunctionHandler extends MyExtendedBackgroundFunction<MyReturnType>

In the class mentioned, the following function fails to detect sub-classed BackgroundFunction type:

static Optional<Type> backgroundFunctionTypeArgument(Class<? extends BackgroundFunction<?>> functionClass) {    
// If this is BackgroundFunction<Foo> then the user must have implemented a method    
// accept(Foo, Context), so we look for that method and return the type of its first argument.    
// We must be careful because the compiler will also have added a synthetic method    
// accept(Object, Context).    
return Arrays.stream(functionClass.getMethods())        
.filter(m -> m.getName().equals("accept") &amp;&amp; m.getParameterCount() == 2            && m.getParameterTypes()[1] == Context.class            &amp;&amp; m.getParameterTypes()[0] != Object.class)        
.map(m -> m.getGenericParameterTypes()[0])        
.findFirst();  
}

This fails for described MyFunctionHandler.

The intent is to add common boilerplate handling for a couple of functions which is common to all. A separate abstract function is employed, but the function fails to load because the type is not determined.

Temporary workaround is to re-implement accept() with the type in the sub-classed object with the type, but is inelegant.

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

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

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 GoogleCloudPlatform/functions-framework-java

Tất cả issue của GoogleCloudPlatform/functions-framework-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.