Skip to content

Drives appear empty resulting in NullPointerException when retriving DriveItemsΒ #2225

@AAckerlund

Description

@AAckerlund

Describe the bug

It doesn't seem to matter what I try. I am able to obtain drive IDs (which I have confirmed point to a drive that has documents) using code like graphClient.users().byUserId(uid).drives().get();. But when I attempt to get the items inside those drives I get a nullPointerException, code for this looks like graphClient.drives().byDriveId(driveId).get().getItems(); or graphClient.users().byUserId(uid).drives().byDriveId(driveId).get().getItems();. I've also tried replacing the .getItems() with .getRoot().getChildren(); but that also throws a null pointer (.getRoot() is null so .getChildren() throws nullPointer).

I have confirmed that these drives have items to retrieve because I can pass the driveID into this curl call and can see the documents I am trying to retrieve, I can also see the documents when I log in to the UI.

curl --location 'https://graph.microsoft.com/v1.0/drives/[driveID]/root/children' \
--header 'Authorization: Bearer [valid_access_token]'

Expected behavior

Expected behavior is to be able to retrieve DriveItems programmatically (presumably using the code described above)

How to reproduce

Run the following code with a valid String value for clientID, clientSecret, tenantID, and uid(userId)

ClientSecretCredential credential = new ClientSecretCredentialBuilder()
        .clientId(clientID)
        .clientSecret(clientSecret)
        .tenantId(tenantID)
        .build();

    String defaultScope = "https://graph.microsoft.com/.default";
    GraphServiceClient graphClient = new GraphServiceClient(credential, defaultScope);
    DriveCollectionResponse driveCollectionResponse = graphClient.users().byUserId(uid).drives().get();

    for(Drive drive : driveCollectionResponse.getValue()){

      System.out.println("Drive ID: " + drive.getId());
      List<DriveItem> driveItemList = drive.getItems();
      System.out.println("Drive Items: " + driveItemList);

      try {
        for (DriveItem item : driveItemList) {
          System.out.println("\tItem: " + item.getName());
        }
      } catch (Exception e) {
        System.out.println("\tError: " + e.getMessage());
      }
    }
    System.out.println("Done");

SDK Version

6.19.0

Latest version known to work for scenario above?

unknown

Known Workarounds

None

Debug output

Log output from running the above code ```

Task :Main.main()
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
Drive ID: [driveID]
Drive Items: null
Error: Cannot invoke "java.util.List.iterator()" because "driveItemList" is null
Drive ID: [driveID]
Drive Items: null
Error: Cannot invoke "java.util.List.iterator()" because "driveItemList" is null
Done
Error: Cannot invoke "java.util.List.iterator()" because "driveItemList" is null

Deprecated Gradle features were used in this build, making it incompatible with Gradle 8.0.

You can use '--warning-mode all' to show the individual deprecation warnings and determine if they come from your own scripts or plugins.

See https://docs.gradle.org/7.4/userguide/command_line_interface.html#sec:command_line_warnings

</details>


### Configuration

_No response_

### Other information

_No response_

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions