-
Notifications
You must be signed in to change notification settings - Fork 90
fix: When chat event type is conversation.chat.completed, a NPE will … #132
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
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 a null check for Changes
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~3 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 (1)
example/src/main/java/example/chat/StreamChatExample.java (1)
57-59: Add null check to prevent NPE.The same NPE risk that was fixed for
CONVERSATION_CHAT_COMPLETEDexists here. Ifevent.getMessage()returns null forCONVERSATION_MESSAGE_DELTAevents, this will throw a NullPointerException.Apply this diff to add a null guard:
if (ChatEventType.CONVERSATION_MESSAGE_DELTA.equals(event.getEvent())) { - System.out.print(event.getMessage().getContent()); + if (event.getMessage() != null) { + System.out.print(event.getMessage().getContent()); + } }
🧹 Nitpick comments (2)
example/src/main/java/example/chat/StreamChatExample.java (2)
38-38: Remove stray semicolon.There's an unnecessary semicolon after the builder pattern that should be removed for cleaner code.
.build(); - ;
79-81: Translate Chinese comments to English for consistency.The comments are in Chinese while the rest of the codebase uses English. Consider translating for consistency.
- // 为了防止程序立即退出,添加一个简单的等待 + // 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)
🔇 Additional comments (2)
example/src/main/java/example/chat/StreamChatExample.java (2)
61-62: LGTM! Null check correctly prevents NPE.The null guard properly addresses the reported NullPointerException when
event.getMessage()returns null forCONVERSATION_CHAT_COMPLETEDevents. The logic flow is correct.
65-65: Add null checks before accessingevent.getChat().getUsage().getTokenCount().The method chain at line 65 lacks defensive null checks. Testing patterns in the codebase (e.g.,
WorkFlowRunServiceTest.javaline 109) show developers explicitly verifygetUsage() != nullbefore accessing it, indicating these methods can return null. Consider:if (event.getChat() != null && event.getChat().getUsage() != null) { System.out.println("Token usage:" + event.getChat().getUsage().getTokenCount()); }
|
@CLAassistant add labels fix |
fix: When chat event type is conversation.chat.completed, a NPE will 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