Fix crash when changing username on Android API < 24.

Basically, the crash was caused by using `Collections.unmodifiableList()`, which creates an `UnmodifiableCollection` wrapper around the original `List`.

That `UnmodifiableCollection` wrapper contains methods that return `java.util.stream.Stream` – which was added in Java 8, but can be used on Android API < 24 through [desugaring](https://developer.android.com/studio/write/java8-support-table). 

_However_, it appears that when Jackson is using reflection to serialize `ReserveUsernameRequest`, it examines all of the methods of that class. This results in a `java.lang.NoClassDefFoundError: java.util.stream.Stream`, because the reflection is looking at the actual runtime `UnmodifiableCollection` class and not desugared code.

As far as I can tell, that behavior is unavoidable and the only way to avoid this issue is to avoid using `Collections.unmodifiableList()` in classes that are serialized by Jackson on Android API < 24.
This commit is contained in:
Jeffrey Starke
2025-03-25 19:32:43 -04:00
committed by Cody Henthorne
parent dc66da0667
commit 0dfe71ca8f

View File

@@ -2,7 +2,6 @@ package org.whispersystems.signalservice.internal.push;
import com.fasterxml.jackson.annotation.JsonProperty;
import java.util.Collections;
import java.util.List;
public class ReserveUsernameRequest {
@@ -10,7 +9,7 @@ public class ReserveUsernameRequest {
private List<String> usernameHashes;
public ReserveUsernameRequest(List<String> usernameHashes) {
this.usernameHashes = Collections.unmodifiableList(usernameHashes);
this.usernameHashes = usernameHashes;
}
List<String> getUsernameHashes() {