microsoftgraph / microsoftgraph/msgraph-sdk-java

ClassCastException while uploading content to OneDrive using Graph API

未关闭
#2,155 4 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

Needs: Attention :wave: type:bug type:legacy-version
主要语言
Java
星标
444
派生
154
平均合并
18 小时 28 分钟
30 天内合并 PR
4

描述

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_

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

从复现的 createUploadSession 调用以及 OneDriveStorageService.java:103 处的 ClassCastException 开始,使用 microsoft-graph 1.9.0 和 microsoft-graph-core 1.0.9。验证 callback 为什么接收到 BufferedInputStream 而不是 UploadSession;当相同的上传流程在没有发生强制类型转换失败的情况下完成时,即表示完成。

由索引模型根据 Issue 内容生成。

评估

技术栈
java
领域
api, cloud
Issue 类型
缺陷
难度
4/5
预计耗时
3-5 天
活跃度
停滞
描述清晰度
基本清楚
新手友好度
30/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。