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

Refactor getContentFromChatResponse method to use Optional for null handling #2013

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

robbyzhaox
Copy link

This commit refactors getContentFromChatResponse to use Java's Optional for null handling. Initially, the method relied on explicit null checks for ChatResponse and its nested properties.

By replacing these with Optional chaining, the code is more streamlined, following Java 8+ best practices for handling nulls. This improves readability and reduces clutter from traditional null - checking.

Now, Optional.ofNullable safely manages the ChatResponse object, and map operations traverse nested objects, gracefully returning null if any link in the chain is null.

@robbyzhaox robbyzhaox changed the title Refactor getContentFromChatResponse method to use Optional for null h… Refactor getContentFromChatResponse method to use Optional for null handling Dec 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant