microsoftgraph / microsoftgraph/msgraph-sdk-java

SDK NullPointerException due to missing @odata.type field during select query

オープン
#2,587 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

status:waiting-for-triage type:bug
主要言語
Java
スター
444
フォーク
154
平均マージ
18時間 28分
マージ済み PR(30日)
4

説明

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

https://github.com/microsoftgraph/msgraph-sdk-java/blob/main/src/main/java/com/microsoft/graph/generated/models/User.java

@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_

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

src/main/java/com/microsoft/graph/generated/models/User.java の User.createFromDiscriminatorValue から始め、欠落している @odata.type フィールドについて JsonParseNode.getChildNode を追跡します。提供された select クエリまたは JsonNode スニペットで問題を再現し、その後、id、name、mail のみを含むユーザーが NullPointerException なしでマッピングされ、返されることを確認します。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
java
領域
api
issue の種類
バグ
難易度
3/5
見積もり時間
1〜2日
活発さ
静か
明瞭さ
おおむね明確
初心者へのやさしさ
68/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。