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

Be more graceful when handing null values #3245

Closed
wants to merge 1 commit into from

Conversation

tikurahul
Copy link
Contributor

Test: Updated golden tests.

…when dealing with mutable types.

Test: Updated golden tests.
@@ -93,7 +93,7 @@ public class MutablePayload(

override fun toString(): String {
val result = mutableListOf<String>()
if (preamble != null) result += """preamble=${sanitize(preamble!!)}"""
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If preamble is not null when would preamble ?: "" make sense?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think doing ?.let would be best, but there's that compiler bug with them...

Copy link
Contributor Author

@tikurahul tikurahul Jan 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was the thought that it's confusing to read ? I guess we are doing more work than we need to strictly speaking.

I considered one other thing which is to make sanitize(...) accept String? but I would have to rename the list variant to sanitizeList to disambiguate. Maybe we should do that instead ?

@oldergod oldergod self-requested a review January 10, 2025 22:34
@oldergod
Copy link
Member

I don't understand the benefit of this. What's different?

image

@tikurahul
Copy link
Contributor Author

Sorry, there is not that much different. I was trying to avoid the use of the !! operator but that might be clearer perhaps.

@oldergod
Copy link
Member

@tikurahul let's use ?.let {} on the whole line? Does that satisfy your case?

@tikurahul
Copy link
Contributor Author

I feel like what's there right now might be okay; and better than then ?.let { ...}. The !! is easier to read than the former.

@tikurahul tikurahul closed this Jan 16, 2025
@JakeWharton
Copy link
Collaborator

?.let produces the same conditional but omits the exception code from !!. It's what we use in other functions like redact already.

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.

3 participants