You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Update it
Note the difference in the upload session creation: above (creation) we use the parentId and the file name byDriveItemId(parent.getId() + ":/" + name + ":") while, below (update), we use the file id byDriveItemId(id)
java.lang.NullPointerException: Cannot invoke "java.util.Collection.toArray()" because "c" is null
at java.base/java.util.ArrayList.([ArrayList.java:181](vscode-file://vscode-app/c:/Users/03200692/AppData/Local/Programs/Microsoft%20VS%20Code/resources/app/out/vs/code/electron-sandbox/workbench/workbench.html))
at com.microsoft.graph.core.models.UploadSession.getNextExpectedRanges([UploadSession.java:61](vscode-file://vscode-app/c:/Users/03200692/AppData/Local/Programs/Microsoft%20VS%20Code/resources/app/out/vs/code/electron-sandbox/workbench/workbench.html))
at com.microsoft.graph.core.requests.upload.UploadResponseHandler.handleResponse([UploadResponseHandler.java:79](vscode-file://vscode-app/c:/Users/03200692/AppData/Local/Programs/Microsoft%20VS%20Code/resources/app/out/vs/code/electron-sandbox/workbench/workbench.html))
at com.microsoft.graph.core.requests.upload.UploadSliceRequestBuilder.put([UploadSliceRequestBuilder.java:69](vscode-file://vscode-app/c:/Users/03200692/AppData/Local/Programs/Microsoft%20VS%20Code/resources/app/out/vs/code/electron-sandbox/workbench/workbench.html))
at com.microsoft.graph.core.tasks.LargeFileUploadTask.uploadSlice([LargeFileUploadTask.java:207](vscode-file://vscode-app/c:/Users/03200692/AppData/Local/Programs/Microsoft%20VS%20Code/resources/app/out/vs/code/electron-sandbox/workbench/workbench.html))
at com.microsoft.graph.core.tasks.LargeFileUploadTask.upload([LargeFileUploadTask.java:131](vscode-file://vscode-app/c:/Users/03200692/AppData/Local/Programs/Microsoft%20VS%20Code/resources/app/out/vs/code/electron-sandbox/workbench/workbench.html))
at com.microsoft.graph.core.tasks.LargeFileUploadTask.upload([LargeFileUploadTask.java:111](vscode-file://vscode-app/c:/Users/03200692/AppData/Local/Programs/Microsoft%20VS%20Code/resources/app/out/vs/code/electron-sandbox/workbench/workbench.html))
[...]
Important
The file on the onedrive is correctly updated!!!
Bug hunting
When you create a file, the server returns a 201 Created with the following response: :
The response is the same (and, actually, it's as documented in the REST reference, but the problem is in the HTTP response code. The response, indeed, is parsed by com.microsoft.graph.core.requests.upload.UploadResponseHandler#handleResponse:
At the 18th line there is the block that manages the creation response.code() == HttpURLConnection.HTTP_CREATED; if you update the file instead of creating it, you receive a 201 and go in the else block which fails at the line if (!uploadSession.getNextExpectedRanges().isEmpty()) because the received JSON (see above) does not have any property called nextExpectedRanges thus uploadSession.getNextExpectedRanges() returns null and invoking isEmpty() causes the NPE.
Possible solution
Replace line 18 of the method:
if (response.code() == HttpURLConnection.HTTP_CREATED) {
The proposed solution in #1517 (comment) will break the test com.microsoft.graph.core.requests.upload.UploadResponseHandlerTest#getUploadSessionOnProgressingUpload, but... with respect to this test:
why does it have a 200/OK as a response? In the REST reference it's written that this type of response has a 202/Accepted as a response code and that 200/OK and 201/Created are used when the upload is completed.
This is a duplication of #microsoftgraph/msgraph-sdk-java#1804.
Initially, I opened the issue on that repo, but it is more correct opening it here
As stated in the object, updating (i.e. modifying) a file via the LargeFileUploadTask does not work and results in a NullPointerException.
Expected behavior
Not receiving a NullPointerException
Actual behavior
Receiving a NullPointerException
API version
implementation 'com.microsoft.graph:microsoft-graph:6.2.0' // Include the sdk as a dependency
Steps to reproduce the behavior
Note the difference in the upload session creation: above (creation) we use the parentId and the file name
byDriveItemId(parent.getId() + ":/" + name + ":")
while, below (update), we use the file idbyDriveItemId(id)
Important
The file on the onedrive is correctly updated!!!
Bug hunting
When you create a file, the server returns a 201 Created with the following response: :
while, when you update a file the server returns a 200 OK with the following response:
The response is the same (and, actually, it's as documented in the REST reference, but the problem is in the HTTP response code. The response, indeed, is parsed by
com.microsoft.graph.core.requests.upload.UploadResponseHandler#handleResponse
:At the 18th line there is the block that manages the creation
response.code() == HttpURLConnection.HTTP_CREATED
; if you update the file instead of creating it, you receive a 201 and go in the else block which fails at the lineif (!uploadSession.getNextExpectedRanges().isEmpty())
because the received JSON (see above) does not have any property callednextExpectedRanges
thusuploadSession.getNextExpectedRanges()
returns null and invokingisEmpty()
causes the NPE.Possible solution
Replace line 18 of the method:
with:
I haven't tried it (not quite at ease with github and pull requests, but that should work)
The text was updated successfully, but these errors were encountered: