microsoftgraph / microsoftgraph/msgraph-sdk-java
BatchResponseContent fails when processing "error": null in batch responses
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 444
- Forks
- 154
- Avg merge
- 18h 28m
- Merged PRs (30d)
- 4
Description
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_
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in BatchResponseContent.java at getResponseFromJsonObject, around line 199, and reproduce the batch response containing an explicit null error field. Verify that the response value is still processed successfully and that the IllegalStateException no longer occurs.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- api
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100