microsoftgraph / microsoftgraph/msgraph-sdk-java

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

未关闭
#2,386 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

status:waiting-for-triage type:bug
主要语言
Java
星标
444
派生
154
平均合并
18 小时 28 分钟
30 天内合并 PR
4

描述

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_

贡献指南

打开贡献指南

从这里开始

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

调研方向

从 BatchResponseContent.java 中的 getResponseFromJsonObject(约第 199 行)开始,复现包含显式 null 错误字段的批量响应。验证响应值是否仍能成功处理,以及是否不再发生 IllegalStateException。

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

评估

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

把新 issue 发到你的邮箱

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