Result.toJSON is annotated @NonNull, but can return null

Description

If the Result contains illegal UTF-8 characters, the conversion from UTF-8 to UTF-16 in NativeFLEncoder_finishJSON will fail and return null and, thus, toJSON will return null.

I believe that the correct solution to this is that toJSON (and, by extension Array and Dictionary) should throw exception on failure. This would be an API change.

Currently these functions wrap the LiteCoreException thrown by LiteCore in an unchecked IllegalStateException.

Activity

Show:

CB robot March 4, 2024 at 4:18 PM

Build couchbase-lite-java-3.2.0-63 contains couchbase-lite-java-common commit 948c233 with commit message:
https://couchbasecloud.atlassian.net/browse/CBL-5455#icft=CBL-5455: Handle UTF8ToJstring encoding failure (#255)

CB robot March 4, 2024 at 4:13 PM

Build couchbase-lite-android-3.2.0-71 contains couchbase-lite-java-common commit 948c233 with commit message:
https://couchbasecloud.atlassian.net/browse/CBL-5455#icft=CBL-5455: Handle UTF8ToJstring encoding failure (#255)

Blake Meike March 1, 2024 at 4:20 PM

Failure to encode a string will now cause Array, Dictionary and Result .toJSON to throw IllegalStateException

Blake Meike March 1, 2024 at 4:19 PM

Fixed
Pinned fields
Click on the next to a field label to start pinning.

Details

Assignee

Reporter

Story Points

Fix versions

Affects versions

Priority

Instabug

Open Instabug

PagerDuty

Sentry

Zendesk Support

Created February 29, 2024 at 5:55 PM
Updated March 4, 2024 at 4:38 PM
Resolved March 1, 2024 at 4:19 PM
Instabug