-
Notifications
You must be signed in to change notification settings - Fork 86
fix: When chat event type is conversation.chat.completed, a NPE will … #133
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
base: main
Are you sure you want to change the base?
Conversation
…be thrown; Error occurred: Cannot invoke "com.coze.openapi.client.connversations.message.model.Message.getType()" because the return value of "com.coze.openapi.client.chat.model.ChatEvent.getMessage()" is null
|
|
WalkthroughAdds null-safety check for Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~5–10 minutes
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (2)
example/src/main/java/example/chat/StreamChatExample.java (2)
57-59: Add null-safety check forevent.getMessage().Similar to the fix applied for
CONVERSATION_CHAT_COMPLETED, this handler accessesevent.getMessage().getContent()without verifying thatgetMessage()is non-null. This could throw a NPE if the API returns aCONVERSATION_MESSAGE_DELTAevent with a null message.Apply this diff to add the null check:
if (ChatEventType.CONVERSATION_MESSAGE_DELTA.equals(event.getEvent())) { - System.out.print(event.getMessage().getContent()); + if (event.getMessage() != null) { + System.out.print(event.getMessage().getContent()); + } }
64-66: Add defensive null checks for nested method calls.The code accesses
event.getChat().getUsage().getTokenCount()without verifying that eithergetChat()orgetUsage()returns a non-null value. This could throw a NPE if the API returns null for either of these methods.Apply this diff to add defensive checks:
} else { - System.out.println("Token usage:" + event.getChat().getUsage().getTokenCount()); + if (event.getChat() != null && event.getChat().getUsage() != null) { + System.out.println("Token usage:" + event.getChat().getUsage().getTokenCount()); + } }
🧹 Nitpick comments (1)
example/src/main/java/example/chat/StreamChatExample.java (1)
79-81: Consider translating comments to English for consistency.The comments on lines 79 and 81 are in Chinese, while the rest of the codebase uses English. For better maintainability and consistency, consider translating them.
Apply this diff:
- // 为了防止程序立即退出,添加一个简单的等待 + // Add a simple wait to prevent the program from exiting immediately try { - Thread.sleep(5000); // 等待5秒钟 + Thread.sleep(5000); // Wait for 5 seconds } catch (InterruptedException e) {
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
example/src/main/java/example/chat/StreamChatExample.java(1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (4)
- GitHub Check: test (Java 17 on macOS)
- GitHub Check: test (Java 17 on Windows)
- GitHub Check: test (Java 11 on Windows)
- GitHub Check: test (Java 11 on macOS)
🔇 Additional comments (2)
example/src/main/java/example/chat/StreamChatExample.java (2)
61-62: LGTM!The null-safety check correctly addresses the NPE described in the PR. The code now safely verifies that
getMessage()is non-null before accessing its methods.
68-70: LGTM!The DONE event handler correctly shuts down the executor with no null-safety concerns.
|
不知道要怎么做才可以通过 ci |
fix: When chat event type is conversation.chat.completed, a NPE will be thrown BUG;
Error occurred: Cannot invoke "com.coze.openapi.client.connversations.message.model.Message.getType()" because the return value of "com.coze.openapi.client.chat.model.ChatEvent.getMessage()" is null