microsoftgraph / microsoftgraph/msgraph-sdk-java

BatchResponseContent fails when processing "error": null in batch responses

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

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

status:waiting-for-triage type:bug
Ngôn ngữ chính
Java
Star
444
Fork
154
Merge trung bình
18 giờ 28 phút
Pull request đã merge (30 ngày)
4

Mô tả

Description

The SDK throws IllegalStateException while processing batch responses when the body.error field is explicitly present but set to null.

The following exception is thrown:

java.lang.IllegalStateException: Not a JSON Object: null
    at com.google.gson.JsonElement.getAsJsonObject(JsonElement.java:91)
    at com.microsoft.graph.core.content.BatchResponseContent.getResponseFromJsonObject(BatchResponseContent.java:199)
Expected behavior

The SDK should ignore error: null and correctly process value.

How to reproduce

Create a batch request with a countIf operation in Microsoft Graph java SDK.

public void countIf(String driveId, String itemId, String criteria, String range) throws IOException {
  // Construct the CountIfPostRequestBody

CountIfPostRequestBody countIfPostRequestBody = new CountIfPostRequestBody();

countIfPostRequestBody.setCriteria(new UntypedString(criteria));
countIfPostRequestBody.setRange(new UntypedObject(Map.of("Address", new UntypedString(range))));

// Call the Graph API

RequestInformation postRequestInformation = graphServiceClient
        .drives()
        .byDriveId(driveId)
        .items()
        .byDriveItemId(itemId)
        .workbook()
        .functions()
        .countIf()
        .toPostRequestInformation(countIfPostRequestBody);


BatchRequestContent batchRequestContent = new BatchRequestContent(graphServiceClient);


String requestId = batchRequestContent.addBatchRequestStep(postRequestInformation);

BatchResponseContent batchResponseContent =
        graphServiceClient.getBatchRequestBuilder().post(batchRequestContent, null);

Response response = batchResponseContent.getResponseById(requestId);

}

Microsoft Graph API returns a valid batch response like this:

{
    "responses": [
        {
            "id": "countIfRequest",
            "status": 200,
            "body": {
                "@odata.context": "https://graph.microsoft.com/v1.0/$metadata#microsoft.graph.workbookFunctionResult",
                "error": null,
                "value": 174
            }
        }
    ]
}
SDK Version

6.39.0

Latest version known to work for scenario above?

No response

Known Workarounds

No response

Debug output
Click to expand log ```
</details>


### Configuration

_No response_

### Other information

_No response_

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.

Hướng nghiên cứu

Bắt đầu trong BatchResponseContent.java tại getResponseFromJsonObject, khoảng dòng 199, và tái hiện phản hồi batch chứa một trường lỗi null rõ ràng. Xác minh rằng giá trị phản hồi vẫn được xử lý thành công và IllegalStateException không còn xảy ra.

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

Đánh giá

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

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.