Feat/subsonic tests - #985
Merged
Merged
Conversation
## Root Cause
NullPointerException in Subsonic.java at line 149.
### Crash path
MainActivity.onStart()
→ initService() + fragment restored from saved state
→ PlayerBottomSheetFragment.onCreateView()
→ setHeaderBookmarksButton() [line 70]
→ ViewModel.getPlayQueue() [line 286]
→ QueueRepository.getPlayQueue()
→ App.getSubsonicClientInstance(false)
→ Subsonic.getParams()
→ preferences.getAuthentication().getPassword() 💥 NPE
### Why it only started in v4.23.0
The TransactionTooLargeException fix (PR #863) added MainActivity.onSaveInstanceState logic that preserves or clears fragment back-stack state. On upgrade, Android OS can now restore
the full fragment stack from the previous session — including PlayerBottomSheetFragment — before the user logs in or their credentials are re-loaded.
In SubsonicPreferences.java, the authentication field is only set if at least one credential is non-null. If SharedPreferences yields all-null credentials (fresh install scenario,
corrupted prefs after upgrade), authentication stays null — and the old code called .getPassword() on that null reference without a guard.
## The Fix
In Subsonic.java, getParams() now locally captures getAuthentication() and wraps all credential puts in a single auth != null guard:
- if (preferences.getAuthentication().getPassword() != null)
- params.put("p", preferences.getAuthentication().getPassword());
- if (preferences.getAuthentication().getSalt() != null)
- params.put("s", preferences.getAuthentication().getSalt());
- if (preferences.getAuthentication().getToken() != null)
- params.put("t", preferences.getAuthentication().getToken());
+ SubsonicPreferences.SubsonicAuthentication auth = preferences.getAuthentication();
+ if (auth != null) {
+ if (auth.getPassword() != null)
+ params.put("p", auth.getPassword());
+ if (auth.getSalt() != null)
+ params.put("s", auth.getSalt());
+ if (auth.getToken() != null)
+ params.put("t", auth.getToken());
+ }
This also avoids calling getAuthentication() 6 times — the result is captured once. When credentials are missing, getPlayQueue() will gracefully return an empty/null response instead
of crashing the app on startup.
Contributor
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
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.
Adding unit tests for #954 that I stashed because they weren't ready.