Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Infinite loop when setting the team property on a Group under specific circumstances #2106

Closed
mkomko opened this issue Aug 1, 2024 · 0 comments · Fixed by microsoft/kiota-java#1558
Assignees
Labels
area:backing-store Focused on functional modules of the product type:bug A broken experience

Comments

@mkomko
Copy link

mkomko commented Aug 1, 2024

Describe the bug

When loading all groups and then trying to populate the team property, an infinite loop occurs.
It is important that the group was loaded with the "resourceProvisioningOptions" collection property selected!
It occurs on the first call of group#setTeam. I posted the stack trace below.

Expected behavior

No infinite loop occurs as in V5 of the SDK.

How to reproduce

You should only need to replace the GraphClient initialization with your own and your tenant needs to contain Teams groups.

package test;

import com.microsoft.graph.core.tasks.PageIterator;
import com.microsoft.graph.models.BaseCollectionPaginationCountResponse;
import com.microsoft.graph.models.Entity;
import com.microsoft.graph.models.Group;
import com.microsoft.graph.models.GroupCollectionResponse;
import com.microsoft.graph.serviceclient.GraphServiceClient;
import com.microsoft.kiota.serialization.UntypedArray;
import com.microsoft.kiota.serialization.UntypedNode;
import org.junit.jupiter.api.Test;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Objects;

public class TestClass
{
    @Test
    public void infiniteLoop() throws ReflectiveOperationException
    {
        graphConnector.ensureGraphClient();
        GraphServiceClient graphClient = graphConnector.getGraphClient();

        GroupCollectionResponse groupCollectionResponse = graphClient.groups().get(
                requestConfig -> requestConfig.queryParameters.select = new String[]{"id", "displayName", "resourceProvisioningOptions"});

        List<Group> groups = new ArrayList<>();

        PageIterator<Group, BaseCollectionPaginationCountResponse> pageIterator =
                new PageIterator.Builder<Group, BaseCollectionPaginationCountResponse>()
                        .client(graphClient)
                        .collectionPage(Objects.requireNonNull(groupCollectionResponse))
                        .collectionPageFactory(GroupCollectionResponse::createFromDiscriminatorValue)
                        .requestConfigurator(requestInfo ->
                        {
                            requestInfo.addQueryParameter("%24select", new String[]{"id", "displayName", "resourceProvisioningOptions"});
                            return requestInfo;
                        })
                        .processPageItemCallback(groups::add)
                        .build();

        pageIterator.iterate();

        for (Group group : groups)
        {
            if (isTeam(group))
                group.setTeam(graphClient.teams().byTeamId(group.getId()).get());
        }
    }

    public static boolean isTeam(Group group)
    {
        Objects.requireNonNull(group);
        Objects.requireNonNull(group.getAdditionalData());

        return getAdditionalDataStringList(group, "resourceProvisioningOptions").contains("Team");
    }

    public static List<String> getAdditionalDataStringList(Entity entity, String key)
    {
        if (entity == null
            || key == null
            || key.isEmpty()
            || !entity.getAdditionalData().containsKey(key))
            return Collections.emptyList();

        List<String> result = new ArrayList<>();

        UntypedArray untypedArray = (UntypedArray) entity.getAdditionalData().get("resourceProvisioningOptions");
        for (UntypedNode untypedNode : untypedArray.getValue())
        {
            if (untypedNode.getValue() == null)
                continue;

            result.add(untypedNode.getValue().toString());
        }

        return result;
    }
}

SDK Version

6.13.0

Latest version known to work for scenario above?

V5

Known Workarounds

No response

Debug output

Click to expand log ```

setIsInitializationCompleted:68, InMemoryBackingStore (com.microsoft.kiota.store) [103]
setupNestedSubscriptions:207, InMemoryBackingStore (com.microsoft.kiota.store)
set:151, InMemoryBackingStore (com.microsoft.kiota.store)
lambda$setupNestedSubscriptions$1:210, InMemoryBackingStore (com.microsoft.kiota.store)
accept:-1, InMemoryBackingStore$$Lambda$642/0x000001bcdb571a48 (com.microsoft.kiota.store)
set:176, InMemoryBackingStore (com.microsoft.kiota.store)
ensureCollectionPropertyIsConsistent:231, InMemoryBackingStore (com.microsoft.kiota.store)
setIsInitializationCompleted:65, InMemoryBackingStore (com.microsoft.kiota.store) [102]
setupNestedSubscriptions:207, InMemoryBackingStore (com.microsoft.kiota.store)
set:151, InMemoryBackingStore (com.microsoft.kiota.store)
lambda$setupNestedSubscriptions$1:210, InMemoryBackingStore (com.microsoft.kiota.store)
accept:-1, InMemoryBackingStore$$Lambda$642/0x000001bcdb571a48 (com.microsoft.kiota.store)
set:176, InMemoryBackingStore (com.microsoft.kiota.store)
ensureCollectionPropertyIsConsistent:231, InMemoryBackingStore (com.microsoft.kiota.store)
setIsInitializationCompleted:65, InMemoryBackingStore (com.microsoft.kiota.store) [101]
...

</details>


### Configuration

_No response_

### Other information

_No response_
@mkomko mkomko added status:waiting-for-triage An issue that is yet to be reviewed or assigned type:bug A broken experience labels Aug 1, 2024
@Ndiritu Ndiritu added area:backing-store Focused on functional modules of the product and removed status:waiting-for-triage An issue that is yet to be reviewed or assigned labels Aug 12, 2024
@Ndiritu Ndiritu self-assigned this Aug 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:backing-store Focused on functional modules of the product type:bug A broken experience
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants