SDK NullPointerException due to missing @odata.type field during select query
Personne n'a encore pris cette issue.
Évaluation
- Difficulté
- 3/5
- Temps estimé
- 1-2 jours
- Accessibilité débutants
- 68/100
Piste de recherche
Commencez par User.createFromDiscriminatorValue dans src/main/java/com/microsoft/graph/generated/models/User.java et suivez JsonParseNode.getChildNode pour le champ @odata.type manquant. Reproduisez le problème avec la requête select ou l’extrait JsonNode fourni, puis vérifiez que les utilisateurs contenant uniquement id, name et mail sont mappés et renvoyés sans NullPointerException.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Description
Describe the bug
During a select query for users, mapping them to the User class fails with following NPE
java.lang.NullPointerException: parameter node cannot be null
at java.util.Objects.requireNonNull(Objects.java:246)
at io.kiota.serialization.json.JsonParseNode.<init>(JsonParseNode.java:38)
at io.kiota.serialization.json.JsonParseNodeFactory.createJsonParseNode(JsonParseNodeFactory.java:32)
at io.kiota.serialization.json.JsonParseNode.getChildNode(JsonParseNode.java:48)
at com.microsoft.graph.models.User.createFromDiscriminatorValue(User.java:30)
at io.kiota.serialization.json.JsonParseNode.getObjectValue(JsonParseNode.java:248)
at io.kiota.serialization.json.JsonParseNode.getCollectionOfObjectValues(JsonParseNode.java:219)
at com.microsoft.graph.models.UserCollectionResponse.lambda$getFieldDeserializers$0(UserCollectionResponse.java:34)
at io.kiota.serialization.json.JsonParseNode.assignFieldValues(JsonParseNode.java:301)
at io.kiota.serialization.json.JsonParseNode.getObjectValue(JsonParseNode.java:249)
at com.microsoft.kiota.http.OkHttpRequestAdapter.send(OkHttpRequestAdapter.java:322)
at com.microsoft.graph.groups.item.members.graphuser.GraphUserRequestBuilder.get(GraphUserRequestBuilder.java:70)
Expected behavior
The user(s) should be selected by the query, mapped and returned in a response object
How to reproduce
Code snippet to reproduce:
final String groupId = "test group id";
final GraphUserRequestBuilder request = client.groups()
.byGroupId(groupId)
.members()
.graphUser()
.get(req -> {
req.queryParameters.select = "id,name,mail";
req.queryParameters.filter = "id in (1,2,3)";
req.queryParameters.count = true;
req.headers.add("ConsistencyLevel", "eventual");
}
})
Code snippet to reproduce the NPE with the JsonNode
import com.fasterxml.jackson.databind.node.JsonNodeFactory;
import com.fasterxml.jackson.databind.node.ObjectNode;
import io.kiota.serialization.json.JsonParseNode;
import io.kiota.serialization.json.JsonParseNodeFactory;
class Scratch {
static void main() {
try {
var a = new JsonParseNode(new JsonParseNodeFactory(), new ObjectNode(new JsonNodeFactory(false)));
var b = a.getChildNode("@odata.type");
} catch (NullPointerException e) {
System.out.println("Exception!");
}
}
}
Replicating this code in Graph UI returns following example response:
{
"@odata.context": "https://graph.microsoft.com/v1.0/$metadata#users(id,name,mail)",
"@odata.count": 2,
"value": [
{
"id": "id 1",
"name": "name 1",
"mail": "mail 1"
},
{
"id": "id 2",
"name": "name 2",
"mail": "mail 2"
}
]
}
Which then leads to the NPE as the SDK is expecting @odata.type field being set here
@jakarta.annotation.Nonnull
public static User createFromDiscriminatorValue(@jakarta.annotation.Nonnull final ParseNode parseNode) {
Objects.requireNonNull(parseNode);
final ParseNode mappingValueNode = parseNode.getChildNode("@odata.type"); <- NPE being caused here
if (mappingValueNode != null) {
final String mappingValue = mappingValueNode.getStringValue();
switch (mappingValue) {
case "#microsoft.graph.agentUser": return new AgentUser();
}
}
return new User();
}
SDK Version
6.63.0
Latest version known to work for scenario above?
6.62.0
Known Workarounds
No response
Debug output
Click to expand log
```</details>
### Configuration
_No response_
### Other information
_No response_
- Langage dominant
- Java
- Étoiles
- 444
- Forks
- 154
- Merge moyen
- 18 h 28 min
- PR mergées (30 j)
- 4
Guide de contribution
Ouvrir le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Autres issues de microsoftgraph/msgraph-sdk-java
-
status:waiting-for-triage type:bug
Difficulté 2/5 1-3 heures Accessibilité débutants 68/100
microsoftgraph/msgraph-sdk-java#2610 ·
-
status:waiting-for-triage type:bug
Difficulté 3/5 1-2 jours Accessibilité débutants 55/100
microsoftgraph/msgraph-sdk-java#2656 ·
-
status:waiting-for-triage type:bug
Difficulté 4/5 3-5 jours Accessibilité débutants 38/100
microsoftgraph/msgraph-sdk-java#2654 ·
-
status:waiting-for-triage
Difficulté 4/5 3-5 jours Accessibilité débutants 35/100
microsoftgraph/msgraph-sdk-java#2639 ·
-
Error in PATCH onlineMeeting Ouvertestatus:waiting-for-triage type:bug
Difficulté 3/5 1-2 jours Accessibilité débutants 35/100
microsoftgraph/msgraph-sdk-java#2589 · 1 commentaire ·
Toutes les issues de microsoftgraph/msgraph-sdk-java
Issues similaires
-
Difficulté 2/5 1-3 heures Accessibilité débutants 65/100
-
Difficulté 1/5 Moins d'une heure Accessibilité débutants 88/100
checkstyle/test-configs#263 ·
-
bug
Difficulté 1/5 Moins d'une heure Accessibilité débutants 90/100
apache/cloudstack#14222 ·
-
[BUG]茶杯方块在取茶时会引发崩溃 Ouverte
Difficulté 2/5 1-3 heures Accessibilité débutants 88/100
-
Cannot differ own consent and managed consents in My Consents view and detailed consent view. Ouverte1.0.0-alpha2 Type/Improvement
Difficulté 2/5 1-3 heures Accessibilité débutants 68/100
wso2/dpdp-accelerator#272 ·