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

ClassCastException while uploading content to OneDrive using Graph API #2155

Open
ukalhapu opened this issue Sep 13, 2024 · 4 comments
Open
Labels
Needs: Attention 👋 type:bug A broken experience type:legacy-version Old version of the SDK

Comments

@ukalhapu
Copy link

Describe the bug

We are trying to upload content to OneDrive root and getting following error consistently.

java.lang.ClassCastException: class java.io.BufferedInputStream cannot be cast to class com.microsoft.graph.models.extensions.UploadSession (java.io.BufferedInputStream is in module java.base of loader 'bootstrap'; com.microsoft.graph.models.extensions.UploadSession is in unnamed module of loader 'app')
at com.ptc.cloudstorage.onedrive.OneDriveStorageService$1.success(OneDriveStorageService.java:103)
at com.microsoft.graph.concurrency.DefaultExecutors$1.run(DefaultExecutors.java:92)
at com.microsoft.graph.concurrency.SynchronousExecutor.execute(SynchronousExecutor.java:45)
at com.microsoft.graph.concurrency.DefaultExecutors.performOnForeground(DefaultExecutors.java:89)
at com.microsoft.graph.http.CoreHttpProvider$1.run(CoreHttpProvider.java:155)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
at java.base/java.lang.Thread.run(Thread.java:829)

Expected behavior

Upload should work as expected.

How to reproduce

try {
IAuthenticationProvider authProvider = new AuthenticationProvider(accessToken);
// Build a Graph client
final IGraphServiceClient graphServiceClient = GraphServiceClient.builder()
.authenticationProvider(authProvider)
.buildClient();
final BlockingQueue queue = new LinkedBlockingQueue<>(1);
DriveItemUploadableProperties itemProperties = new DriveItemUploadableProperties();
graphServiceClient
.me()
.drive()
.root()
.itemWithPath(escapeSpace(filename))
.createUploadSession(itemProperties)
.buildRequest()
.post(new ICallback() {
@OverRide
public void failure(final ClientException ex) {
logger.error("createUploadSession.failure: Error occured durring post " + ex);
if (logger.isTraceEnabled()) {
ex.printStackTrace();
}
try {
queue.put("");
} catch (InterruptedException ie) {
}
}

                    @Override
                    public void success(final UploadSession result) {
                        if (logger.isDebugEnabled()) {
                            logger.debug("createUploadSession.success: UploadSession= " + result);
                        }
                        try {
                            ChunkedUploadProvider<DriveItem> chunkedUploadProvider = new ChunkedUploadProvider<DriveItem>(
                                    result, graphServiceClient, inputStream, streamSize, DriveItem.class);
                            chunkedUploadProvider.upload(new IProgressCallback<DriveItem>() {
                                @Override
                                public void failure(ClientException ce) {
                                    logger.error("failure: Error occured durring upload " + ce);
                                    if (logger.isTraceEnabled()) {
                                        ce.printStackTrace();
                                    }
                                    try {
                                        queue.put("");
                                    } catch (InterruptedException ie) {
                                    }
                                }

                                @Override
                                public void success(DriveItem driveItem) {
                                    if (logger.isDebugEnabled()) {
                                        logger.debug("success: driveItem = " + driveItem);
                                    }
                                    try {
                                        queue.put(driveItem.webUrl);
                                    } catch (InterruptedException ie) {
                                    }
                                }

                                @Override
                                public void progress(long current, long max) {
                                    if (logger.isDebugEnabled()) {
                                        logger.debug("progress: current=" + current + ", max=" + max);
                                    }
                                }
                            }, new int[] { finalChunkSize });
                        } catch (Exception e) {
                            logger.error("Exception occured in upload to One Drive", e);
                            try {
                                queue.put("");
                            } catch (InterruptedException ie) {
                            }
                        }

SDK Version

microsoft-graph-core 1.0.9 microsoft-graph 1.9.0

Latest version known to work for scenario above?

No response

Known Workarounds

No response

Debug output

Click to expand log ```
</details>


### Configuration

_No response_

### Other information

_No response_
@ukalhapu ukalhapu added status:waiting-for-triage An issue that is yet to be reviewed or assigned type:bug A broken experience labels Sep 13, 2024
@ukalhapu ukalhapu changed the title ClassCastException while uploading content to OneDrive using Grapah API ClassCastException while uploading content to OneDrive using Graph API Sep 13, 2024
@Ndiritu
Copy link
Contributor

Ndiritu commented Sep 13, 2024

Hi @ukalhapu.
Unfortunately we're not actively supporting version 1.x of this SDK.
We provide working code samples & active fixes on version 6.x of the SDK. Would it be viable for you to upgrade to version 6.x?

@Ndiritu Ndiritu added status:waiting-for-author-feedback Issue that we've responded but needs author feedback to close and removed status:waiting-for-triage An issue that is yet to be reviewed or assigned labels Sep 13, 2024
@ukalhapu
Copy link
Author

Hi @Ndiritu
Thanks for response.
No immediate plan to upgrade.
Only few of customers are getting this issue, other customers on 1.x not getting the ClassCast exception.
We are not able to reproduce in-house.
Is there any workaround/configuration ?

@microsoft-github-policy-service microsoft-github-policy-service bot added Needs: Attention 👋 and removed status:waiting-for-author-feedback Issue that we've responded but needs author feedback to close labels Sep 16, 2024
@ukalhapu
Copy link
Author

Hi @Ndiritu
Could you please comment?

@Ndiritu Ndiritu added the type:legacy-version Old version of the SDK label Sep 23, 2024
@ukalhapu
Copy link
Author

ukalhapu commented Oct 9, 2024

Hello @Ndiritu,
Customer pushing for resolution.
Could you please comment?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs: Attention 👋 type:bug A broken experience type:legacy-version Old version of the SDK
Projects
None yet
Development

No branches or pull requests

2 participants