microsoftgraph / microsoftgraph/msgraph-sdk-java

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

Aperta
#2,386 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

status:waiting-for-triage type:bug
Lingua principale
Java
Stelle
444
Fork
154
Merge medio
18h 28m
PR unite (30g)
4

Descrizione

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_

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Inizia in BatchResponseContent.java, in getResponseFromJsonObject, intorno alla riga 199, e riproduci la risposta batch contenente un campo di errore null esplicito. Verifica che il valore della risposta venga ancora elaborato correttamente e che IllegalStateException non si verifichi più.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
java
Ambito
api
Tipo di issue
Bug
Difficoltà
2/5
Tempo stimato
1-3 ore
Stato di attività
Ferma
Chiarezza
Specificata chiaramente
Idoneità per principianti
45/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.