From f6482c5a87e3436bcccc2a36b5e141ef52155930 Mon Sep 17 00:00:00 2001
From: Daniel Gultsch <daniel@gultsch.de>
Date: Tue, 31 Oct 2023 11:03:59 +0100
Subject: [PATCH] fix caps hash calculation for empty form fields

---
 .../entities/ServiceDiscoveryResult.java       | 18 ++++++++++--------
 1 file changed, 10 insertions(+), 8 deletions(-)

diff --git a/src/main/java/eu/siacs/conversations/entities/ServiceDiscoveryResult.java b/src/main/java/eu/siacs/conversations/entities/ServiceDiscoveryResult.java
index 8eccbe141..6c3787b61 100644
--- a/src/main/java/eu/siacs/conversations/entities/ServiceDiscoveryResult.java
+++ b/src/main/java/eu/siacs/conversations/entities/ServiceDiscoveryResult.java
@@ -17,6 +17,7 @@ import java.security.MessageDigest;
 import java.security.NoSuchAlgorithmException;
 import java.util.ArrayList;
 import java.util.Collections;
+import java.util.Comparator;
 import java.util.List;
 
 import eu.siacs.conversations.xml.Element;
@@ -100,9 +101,9 @@ public class ServiceDiscoveryResult {
 
 	public ServiceDiscoveryResult(Cursor cursor) throws JSONException {
 		this(
-				cursor.getString(cursor.getColumnIndex(HASH)),
-				Base64.decode(cursor.getString(cursor.getColumnIndex(VER)), Base64.DEFAULT),
-				new JSONObject(cursor.getString(cursor.getColumnIndex(RESULT)))
+				cursor.getString(cursor.getColumnIndexOrThrow(HASH)),
+				Base64.decode(cursor.getString(cursor.getColumnIndexOrThrow(VER)), Base64.DEFAULT),
+				new JSONObject(cursor.getString(cursor.getColumnIndexOrThrow(RESULT)))
 		);
 	}
 
@@ -216,17 +217,18 @@ public class ServiceDiscoveryResult {
 			s.append(clean(feature)).append("<");
 		}
 
-		Collections.sort(forms, (lhs, rhs) -> lhs.getFormType().compareTo(rhs.getFormType()));
+        Collections.sort(forms, Comparator.comparing(Data::getFormType));
 
 		for (Data form : forms) {
 			s.append(clean(form.getFormType())).append("<");
 			List<Field> fields = form.getFields();
-			Collections.sort(fields, (lhs, rhs) -> Strings.nullToEmpty(lhs.getFieldName()).compareTo(Strings.nullToEmpty(rhs.getFieldName())));
+            Collections.sort(
+                    fields, Comparator.comparing(lhs -> Strings.nullToEmpty(lhs.getFieldName())));
 			for (Field field : fields) {
 				s.append(Strings.nullToEmpty(field.getFieldName())).append("<");
-				List<String> values = field.getValues();
-				Collections.sort(values);
-				for (String value : values) {
+				final List<String> values = field.getValues();
+				Collections.sort(values, Comparator.comparing(ServiceDiscoveryResult::blankNull));
+				for (final String value : values) {
 					s.append(blankNull(value)).append("<");
 				}
 			}