0
0
mirror of https://github.com/ankidroid/Anki-Android.git synced 2024-09-19 19:42:17 +02:00

Fixes null pointer exception

After reproducing #16702, I discovered that actually, the part of the
code where the NPE occurred should not have been reached.

newModel and oldModel are two distinct objects representing the same
note type. And JSonObject's equality is defined as pointer
equality. Using id instead of actual note type repair the bug.

Since, in AnkiDroid, editing the note type through the reviewer, can't
lead to adding or removing field, this is safe to consider that if the
id is equal, the objects are equal as far as the list of field is concerned.

I fear I don't see how to test it easily. It seems it require
AndroidTest and not unit tests, and I can't find example of note editor
test. Furthermore note editor will be replaced soon, so I don't expect
it's such a big deal.

* Fixed #16702
This commit is contained in:
Arthur Milchior 2024-07-14 02:45:23 +02:00 committed by lukstbit
parent 93c2f68429
commit dbf737a647

View File

@ -1055,8 +1055,8 @@ class NoteEditor : AnkiActivity(), DeckSelectionListener, SubtitleListener, Tags
} else {
// Check whether note type has been changed
val newModel = currentlySelectedNotetype
val oldModel = if (currentEditedCard == null) null else currentEditedCard!!.noteType(getColUnsafe)
if (newModel != oldModel) {
val oldModel = currentEditedCard?.noteType(getColUnsafe)
if (newModel?.id != oldModel?.id) {
reloadRequired = true
if (modelChangeCardMap!!.size < editorNote!!.numberOfCards(getColUnsafe) || modelChangeCardMap!!.containsValue(
null