larksuite / larksuite/oapi-sdk-java
继承BaseResponse<ByteArrayOutputStream>的Resp类在反序列化时产生InaccessibleObjectException
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 310
- Forks
- 115
- PR merge metrics
- No merged PRs in 30d
Description
在API返回非200状态码(如权限问题、QPS超限等场景)时,SDK会将RawResponse反序列化为Resp类,以获取错误信息。
但继承BaseResponse<ByteArrayOutputStream>的Resp类(主要见于文件下载类API),由于其data字段的类型为ByteArrayOutputStream,在jdk17进行反序列化时,gson会抛出InaccessibleObjectException(因为ByteArrayOutputStream存在非public字段buf和count),导致程序无法正确获取API返回的code和msg
ByteArrayOutputStream本身其实不具备反序列化的可能性,SDK应当在处理此类数据时避免反序列化Resp类的data字段
举例:
GetMessageResourceResp类
https://github.com/larksuite/oapi-sdk-java/blob/4ec09ba4918b5907c17aebd5f95f604e69ea6cc8/larksuite-oapi/src/main/java/com/lark/oapi/service/im/v1/model/GetMessageResourceResp.java#L29
MessageResource类中对GetMessageResourceResp的反序列化操作
https://github.com/larksuite/oapi-sdk-java/blob/4ec09ba4918b5907c17aebd5f95f604e69ea6cc8/larksuite-oapi/src/main/java/com/lark/oapi/service/im/v1/resource/MessageResource.java#L123
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with GetMessageResourceResp.java and the deserialization code in MessageResource.java around line 123, then trace how RawResponse becomes Resp on non-200 responses under JDK 17. Reproduce the InaccessibleObjectException and verify that the response code and message can be obtained without deserializing the ByteArrayOutputStream data field.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- api
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100