-
-
Notifications
You must be signed in to change notification settings - Fork 2.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
Fix crash during deck filtering #11880
Fix crash during deck filtering #11880
Conversation
First PR! 🚀 We sincerely appreciate that you have taken the time to propose a change to AnkiDroid! Please have patience with us as we are all volunteers - we will get to this as soon as possible. |
Added basic unit tests to ensure filter does not break again. Could probably use a few more to cover more edge cases but figured this was good enough for now |
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.
I love this, thank you!
Revert the publishResults
change (or discuss if I'm wrong) and it's good to go
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 great, thank you so much
@@ -51,7 +52,13 @@ abstract class TypedFilter<T>(private val getCurrentItems: (() -> List<T>)) : Fi | |||
override fun publishResults(constraint: CharSequence?, results: FilterResults?) { | |||
// this is only ever called from performFiltering so we can guarantee the value is non-null | |||
// and can be cast to List<T> | |||
val list = results!!.values as List<T> | |||
val list = try { |
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.
I think an explicit call to if results == null
would be better. Try are more costly than conditional in general, and anyway clearer.
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.
I've since reverted this code since David said it was better to have it crash
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.
I changed it to use a nullable to avoid an if check
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.
I think I'd prefer a crash here (AKA no change), as it's an assertion which doesn't hold, but I'll leave the final decision to you. Implementer's choice, I'm happy either way =)
I think the answer to the question of 'what do we do if we get a null' is hard to pin down: do we want all results, or no results?
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.
Yea that's a good question. I did no results since that was simpler to implement but it's not necessarily the best UX choice. It would require a sizeable refactor though to return all results.
I think since we're getting a little outside the scope of the PR I'll revert it to original for now and leave it for a non-urgent issue.
This reverts commit 5b617b0.
Hi there @shaiguelman! This is the OpenCollective Notice for PRs merged from 2022-07-01 through 2022-07-31 If you are interested in compensation for this work, the process with details is here: We only post one comment per person per month to avoid spamming you, regardless of the number of PRs merged, but this note applies to all PRs merged for this month Please note that GSoC contributions are okay for this process. Our philosophy is that our users have donated to AnkiDroid for all contributions. The only PRs that will not go through the OpenCollective process are ones directly related to am accepted GSoC project from a selected participant, since those receive a stipend from GSoC itself. Please understand that our monthly budget is never guaranteed to cover all claims - the cap on payments-per-person may be lower, but we try to make our process as fair and transparent as possible, we just need your understanding. Thanks! |
Pull Request template
Purpose / Description
Fixes issue where search bar was not filtering properly and crashing the app.
Fixes
Fixes #11877
Approach
Creates a copy of the list of decks before filtering. The error was caused by using the same list in filtering as in the UI. I also made a small optimization of the containsFilterString method as well as added error catching in TypedFilter in case error happens again.
How Has This Been Tested?
Reproduced error using process described in the issue before and after code changes. Screenshot of results after code changes:
Learning (optional, can help others)
Stack overflow post that helped me narrow the issue
Checklist
Please, go through these checks before submitting the PR.
if
statements)