From a17a7a7938b09de9b14f1d65fa4ab42e0aabcfbf Mon Sep 17 00:00:00 2001 From: Stephen Paul Weber Date: Wed, 21 Feb 2024 19:24:48 -0500 Subject: [PATCH] No more viewType=-1 Crashing on unknown input was a useful debugging tool for awhile, but it's not really acceptable in a production app being used for so many different things. If we get send nonsense, at least show the user an error. --- .../eu/siacs/conversations/entities/Conversation.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/main/java/eu/siacs/conversations/entities/Conversation.java b/src/main/java/eu/siacs/conversations/entities/Conversation.java index e33f7cee25ac10159c1b00f9321f8b6c1df1900a..8abc920fe970b14ddf23a2947bfb4e6d42005b77 100644 --- a/src/main/java/eu/siacs/conversations/entities/Conversation.java +++ b/src/main/java/eu/siacs/conversations/entities/Conversation.java @@ -1833,8 +1833,12 @@ public class Conversation extends AbstractEntity implements Blockable, Comparabl public void bind(Item iq) { binding.errorIcon.setVisibility(View.VISIBLE); + if (iq == null || iq.el == null) return; Element error = iq.el.findChild("error"); - if (error == null) return; + if (error == null) { + binding.message.setText("Unexpected response: " + iq); + return; + } String text = error.findChildContent("text", "urn:ietf:params:xml:ns:xmpp-stanzas"); if (text == null || text.equals("")) { text = error.getChildren().get(0).getName(); @@ -2691,7 +2695,7 @@ public class Conversation extends AbstractEntity implements Blockable, Comparabl } protected Item mkItem(Element el, int pos) { - int viewType = -1; + int viewType = TYPE_ERROR; if (response != null && response.getType() == IqPacket.TYPE.RESULT) { if (el.getName().equals("note")) { @@ -2707,8 +2711,6 @@ public class Conversation extends AbstractEntity implements Blockable, Comparabl return field; } } - } else if (response != null) { - viewType = TYPE_ERROR; } Item item = new Item(el, viewType);