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

Handler dispatch failed; nested exception is java.lang.NoSuchMethodError: okhttp3.RequestBody.create(Ljava/lang/String;Lokhttp3/MediaType;)Lokhttp3/RequestBody; #75

Closed
xiaofandaren-real opened this issue Dec 8, 2022 · 2 comments · Fixed by #76
Labels
bug Something isn't working

Comments

@xiaofandaren-real
Copy link

错误描述

在maven中引入0.2.1版本后执行报错,
bug发生在com.wechat.pay.java.core.http.okhttp.OkHttpClientAdapter类里面,该类中执行createOkHttpRequestBody 方法时调用了 okhttp3.RequestBody.create(MediaType contentType, String content),但是参数写反了,导致报错

重现bug的步骤

private RequestBody createOkHttpRequestBody(
com.wechat.pay.java.core.http.RequestBody wechatPayRequestBody) {
return okhttp3.RequestBody.create(
((JsonRequestBody) wechatPayRequestBody).getBody(),
okhttp3.MediaType.parse(wechatPayRequestBody.getContentType()));
}

private RequestBody createOkHttpMultipartRequestBody(
com.wechat.pay.java.core.http.RequestBody wechatPayRequestBody) {
FileRequestBody fileRequestBody = (FileRequestBody) wechatPayRequestBody;
okhttp3.RequestBody okHttpFileBody =
okhttp3.RequestBody.create(
fileRequestBody.getFile(), okhttp3.MediaType.parse(fileRequestBody.getContentType()));
return new okhttp3.MultipartBody.Builder()
.setType(MultipartBody.FORM)
.addFormDataPart(META_NAME, fileRequestBody.getMeta())
.addFormDataPart(FILE_NAME, fileRequestBody.getFileName(), okHttpFileBody)
.build();
}

预期行为

Caused by: java.lang.NoSuchMethodError: okhttp3.RequestBody.create(Ljava/lang/String;Lokhttp3/MediaType;)Lokhttp3/RequestBody;
at com.wechat.pay.java.core.http.okhttp.OkHttpClientAdapter.createOkHttpRequestBody(OkHttpClientAdapter.java:84) ~[wechatpay-java-core-0.2.1.jar:0.2.1]
at com.wechat.pay.java.core.http.okhttp.OkHttpClientAdapter.buildOkHttpRequestBody(OkHttpClientAdapter.java:70) ~[wechatpay-java-core-0.2.1.jar:0.2.1]
at com.wechat.pay.java.core.http.okhttp.OkHttpClientAdapter.buildOkHttpRequest(OkHttpClientAdapter.java:59) ~[wechatpay-java-core-0.2.1.jar:0.2.1]
at com.wechat.pay.java.core.http.okhttp.OkHttpClientAdapter.innerExecute(OkHttpClientAdapter.java:46) ~[wechatpay-java-core-0.2.1.jar:0.2.1]
at com.wechat.pay.java.core.http.AbstractHttpClient.execute(AbstractHttpClient.java:42) ~[wechatpay-java-core-0.2.1.jar:0.2.1]
at com.wechat.pay.java.service.payments.nativepay.NativePayService.prepay(NativePayService.java:162) ~[wechatpay-java-0.2.1.jar:0.2.1]

导致错误的代码片段

No response

操作系统

Windows

Java 版本

java 8

wechatpay-java 版本

0.2.1

其他信息

No response

@xiaofandaren-real xiaofandaren-real added the bug Something isn't working label Dec 8, 2022
@xy-peng
Copy link
Contributor

xy-peng commented Dec 8, 2022

请先看下 #70

我们有在看如何避免,不过确实 OkHttp 3.x 和 OkHttp 4.x 在这里不兼容。实在不好解决,会补充到《常见问题》里。

@xiaofandaren-real
Copy link
Author

请先看下 #70

我们有在看如何避免,不过确实 OkHttp 3.x 和 OkHttp 4.x 在这里不兼容。实在不好解决,会补充到《常见问题》里。

OK

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants