Android: Prevent potential NPEs and improve nullability handling #89999
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.
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: