microsoftgraph / microsoftgraph/msgraph-sdk-java
BatchResponseContent fails when processing "error": null in batch responses
未關閉
還沒有人認領這個 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_
貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
研究方向
從 BatchResponseContent.java 中的 getResponseFromJsonObject(約第 199 行)開始,重現包含明確 null 錯誤欄位的批次回應。驗證回應值是否仍能成功處理,以及是否不再發生 IllegalStateException。
由索引模型根據 Issue 內容生成。
評估
- 技術堆疊
- java
- 領域
- api
- Issue 類型
- 缺陷
- 難度
- 2/5
- 預估耗時
- 1-3 小時
- 活躍度
- 停滯
- 描述清晰度
- 描述清楚
- 新手友好度
- 45/100