refactor: silence optString(name, null) Kotlin warnings#144
Merged
riteshshukla04 merged 2 commits intoJul 17, 2026
Conversation
JSONObject.optString's `fallback` parameter is annotated @nonnull, so passing null produced 23 "Java type mismatch: inferred type is 'Nothing?', but 'String' was expected" warnings across AutoPrefetcher and NitroWebSocketAutoPrewarmer. Add an internal optStringOrNull() extension to each package and use it at all 23 call sites. Behaviour is unchanged. The helper guards on has() rather than the more obvious isNull() because optString coerces the JSONObject.NULL sentinel to the string "null" -- so an explicit `"key": null` returns "null" and only an absent key returns null. Using isNull() would have been a silent behaviour change rather than a warning fix. The helper is duplicated rather than shared because the websockets android module depends only on :react-native-nitro-modules, not on the fetch package. This matches the existing NitroLogger.kt precedent. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
|
@uwayss is attempting to deploy a commit to the Margelo Team on Vercel. A member of the Team first needs to authorize it. |
riteshshukla04
requested changes
Jul 17, 2026
riteshshukla04
left a comment
Collaborator
There was a problem hiding this comment.
Thanks for PR. This is good stuff. I just have 2 issues here
- Lots of AI slop comments (Max 1 line comment)
- The check has an issue . Something like {"foo": null} would return empty string in optString
Guard on isNull() instead of has() so a `"key": null` value returns null rather than a coerced string, and trim the helper comment to one line. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Contributor
Author
|
Both fixed in d4e568e — comments down to one line, and switched to |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Building the Android modules gives 23 compiler warnings, all the same one:
They come from
optString(name, null)—optString'sfallbackparam is@NonNull, so passingnullwarns. 13 inAutoPrefetcher.kt, 10 inNitroWebSocketAutoPrewarmer.kt.This adds an
optStringOrNull()helper to each android package and moves all 23 calls onto it.compileReleaseKotlinon both modules: 23 warnings → 0.isNull()maps both a missing key and an explicit"key": nulltonull.A couple of small things:
NitroWebSocketAutoPrewarmer.kt:206keepsoptString(j, null)— that's theJSONArrayoverload, no@NonNull, never warned.internal(kept out of the published AAR) and duplicated per package, since the websockets module doesn't depend on the fetch one — same asNitroLogger.kt.Test plan
compileReleaseKotlinboth modules — 23 → 0bun lint,bun typecheck,bun test— all pass🤖 Generated with Claude Code