fix(android): Prevent potential crash in checkPowerServiceSaveMode#3664
Closed
Darkx-dev wants to merge 1 commit intofluttercommunity:mainfrom
Closed
fix(android): Prevent potential crash in checkPowerServiceSaveMode#3664Darkx-dev wants to merge 1 commit intofluttercommunity:mainfrom
Darkx-dev wants to merge 1 commit intofluttercommunity:mainfrom
Conversation
The checkPowerServiceSaveMode method used a non-null assertion (!!) on applicationContext. This could potentially lead to a NullPointerException in rare edge cases. This change replaces the assertion with a safe-call block (`?.let`), ensuring the method safely returns `false` if the context is null, thereby improving the plugin's robustness.
Collaborator
|
Could you list at least one case when it will be null? Reading the description I clearly see some AI generated text. Looks like the change is the same vibe coded thing. |
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.
Description
This PR improves the null safety of the
checkPowerServiceSaveModemethod on the Android platform to prevent a potential crash.The Problem
Currently, the
checkPowerServiceSaveModemethod uses a non-null assertion (!!) onapplicationContext. While the context is very unlikely to be null in normal operation, a library should be as resilient as possible against rare edge cases (e.g., race conditions during plugin detachment). ANullPointerExceptionhere would crash the entire host application.The Solution
I have replaced the
!!operator with a safe-call (?.let) block. IfapplicationContexthappens to be null, the method will now safely return a default value offalseinstead of crashing.This is a small, targeted change that increases the stability of the plugin without altering its core logic.