Issue 1567: Handle failure to fetch card count.#5
Conversation
|
This is a fix for: The import was actually successful, but without the updated counts, the deck picker will not show the right counts. What do you think? |
|
It might just be that when it reaches that point the collection is not loaded. The linked triage crash doesn't seem correct (it points to DeckPicker.java:L1664 where nullpointerexception seems unlikely). Do you remember how to replicate the issue, what was the state of your collection before you imported, did it exist? was it open? |
|
The transition diagram for the upgrade wizard is hard to follow, not sure how to simplify it, because the transition diagram around the deckpicker is already complicated. In general, there's an ongoing (as far as I remember ankidroid's code) anti-pattern that generates many nullpointerexceptions, when we try to do something with a collection that is null. Maybe the problem is that we treat it as global variable whose state can change in dozens of places and threads. But what is a good way to handle this? |
|
This is the line where the NPE happens: This is my understanding of what happens. The result of TASK_TYPE_IMPORT_REPLACE is true, but info is null. The result is coming from https://github.com/nobnago/Anki-Android/blob/v2.0/src/com/ichi2/async/DeckTask.java#L832, specifically from: https://github.com/nobnago/Anki-Android/blob/v2.0/src/com/ichi2/async/DeckTask.java#L890. The code there checks that result from https://github.com/nobnago/Anki-Android/blob/v2.0/src/com/ichi2/async/DeckTask.java#L475 is not null and returns null as the object array if it is null. However, that means that the calling code will NPE. The way null can come back is either that the collection passed in is null (https://github.com/nobnago/Anki-Android/blob/v2.0/src/com/ichi2/async/DeckTask.java#L479) or there was a RuntimeException (https://github.com/nobnago/Anki-Android/blob/v2.0/src/com/ichi2/async/DeckTask.java#L486). I was not able to replicate so far, but one of these two seems to be happening. Yes, I think we have lots of NPEs in the code because the assumptions we make on the code are very clear. Mostly we should avoid nulls as much as possible, as a way to avoid NPEs. In a way this is just a stopgap solution: it avoids the NPE when something fails at the inner level, but I am not sure what the underlying problem actually is... I will try further to reproduce. |
|
Did I submit the right pull request to you? Please try the one in branch v2.0.1-dev, which looks different for the line you mention: |
|
I based this on the crash reports for 2.0 and therefore I am looking at the 2.0 code. Maybe this is already fixed in 2.0.1? |
|
I hope so, I surely fixed some instances of this in the wizard work |
|
I understand now, you were testing 2.0. The stopgap is useful, but we should implement it also in the DeckTask.doInBackgroundImportAdd() method, since the same piece of code exists there. |
If the card count is not fetched correctly, we should fail the import.
|
Thanks Kostas. I updated to have the same stopgap in the other method. |
|
Thank you! |
Issue 1567: Handle failure to fetch card count.
If the card count is not fetched correctly, we should fail the import.