-
-
Notifications
You must be signed in to change notification settings - Fork 21.3k
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
Android: Prevent potential NPEs and improve nullability handling #89999
Android: Prevent potential NPEs and improve nullability handling #89999
Conversation
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.
The cleanup looks good!
Added some comments to address and it should be good to go.
Log.v(TAG, "Force quitting Godot instance") | ||
ProcessPhoenix.forceQuit(this) | ||
godotFragment?.let { | ||
if (instance == it.godot) { |
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.
Here the original logic has a triple equal ===
for referential equality; looks like it was inadvertently converted to a double equals ==
.
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.
Ah, good catch, I missed that, thanks! Will fix...
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.
Fixed
Log.v(TAG, "Restarting Godot instance...") | ||
ProcessPhoenix.triggerRebirth(this) | ||
godotFragment?.let { | ||
if (instance == it.godot) { |
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.
Similar comment as above; the original logic has a triple equal ===
for referential equality; looks like it was inadvertently converted to a double equals ==
.
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.
Fixed, thanks
This PR prevents potential NPEs, and follows Kotlin conventions more closely by replacing the unsafe !! operator with safe ?. (or ?.let) (usually !! would only be used very rarely, and with a good reason - there is one place left in this PR where !! makes sense), and by replacing Java style 'if (x != null)' with Kotlin's '?.'
26fbf64
to
70ea3e2
Compare
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.
Looks good!
Thanks for a quick review |
Thanks! And congrats for your first merged Godot contribution 🎉 |
Context
This PR aims to improve nullability handling in Godot's Android
lib
module:!!
operator is used in a few lines, whereas elsewhere the safer?.
is used - this is now replaced with the safe?.
(or?.let
) operator consistently; (usually!!
would only be used very rarely, and with a good reason - there is one place left in this PR where I believe!!
makes sense ->GodotActivity.kt, L79
)if (x != null)
replaced with idiomatic Kotlin's?.
FileAccessHandler.renameFile()
accepted nullable args, (and so its use sites were again having!!
for the args passed to this function), but it can be inferred that the args the function receives are non-nullable, therefore we can get rid of nullability in those args (and so the!!
use)Godot.getRotatedValues()
- this could produce an NPE inonSensorChanged()
in some situations - fixedThere are 2 outcomes from the above: