Skip to content

Accept null file_size in AttachmentDto#6463

Merged
gpunto merged 3 commits into
v6from
null-file-size-v6
May 22, 2026
Merged

Accept null file_size in AttachmentDto#6463
gpunto merged 3 commits into
v6from
null-file-size-v6

Conversation

@gpunto
Copy link
Copy Markdown
Contributor

@gpunto gpunto commented May 21, 2026

Goal

Backport of #6462 to v6.

It seems that backend can return null for file_size on attachments, but AttachmentDto.file_size was non-nullable so explicit nulls in the JSON caused deserialization to fail.

This also aligns with iOS, where AttachmentFile decodes a missing or non-decodable file_size as 0.

Closes #6428

Implementation

  • AttachmentDto.file_size is now Int?, so an explicit null from the API deserializes cleanly.
  • DomainMapping maps null to 0 when mapping to the domain Attachment.fileSize.

Testing

  • New unit test Deserialize JSON attachment with null file_size covers the parser path.
  • Existing attachment parser and mapping tests continue to pass.

Summary by CodeRabbit

  • Bug Fixes
    • Improved handling of attachments with missing file size information. The system now gracefully defaults file size to 0 when the value is unavailable, enhancing robustness and preventing potential issues during attachment processing.

Review Change Stack

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 21, 2026

PR checklist ✅

All required conditions are satisfied:

  • Title length is OK (or ignored by label).
  • At least one pr: label exists.
  • Sections ### Goal, ### Implementation, and ### Testing are filled (or ignored for dependabot PRs).

🎉 Great job! This PR is ready for review.

@gpunto gpunto added the pr:bug Bug fix label May 21, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 21, 2026

SDK Size Comparison 📏

SDK Before After Difference Status
stream-chat-android-client 5.26 MB 5.29 MB 0.03 MB 🟢
stream-chat-android-offline 5.49 MB 5.50 MB 0.01 MB 🟢
stream-chat-android-ui-components 10.64 MB 10.68 MB 0.04 MB 🟢
stream-chat-android-compose 12.87 MB 12.89 MB 0.03 MB 🟢

@gpunto gpunto force-pushed the null-file-size-v6 branch from 00ab665 to c3ef230 Compare May 21, 2026 15:50
@gpunto gpunto marked this pull request as ready for review May 22, 2026 09:57
@gpunto gpunto requested a review from a team as a code owner May 22, 2026 09:57
@gpunto gpunto changed the title Accept null file_size in AttachmentDto (v6 backport) Accept null file_size in AttachmentDto May 22, 2026
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 22, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 922011e8-142f-4913-9400-8b5daf2b9d01

📥 Commits

Reviewing files that changed from the base of the PR and between 23b37d6 and 6e0a9ce.

📒 Files selected for processing (7)
  • stream-chat-android-client/src/main/java/io/getstream/chat/android/client/api2/mapping/DomainMapping.kt
  • stream-chat-android-client/src/main/java/io/getstream/chat/android/client/api2/model/dto/AttachmentDto.kt
  • stream-chat-android-client/src/main/java/io/getstream/chat/android/client/parser2/direct/AttachmentAdapter.kt
  • stream-chat-android-client/src/test/java/io/getstream/chat/android/client/api2/mapping/DomainMappingTest.kt
  • stream-chat-android-client/src/test/java/io/getstream/chat/android/client/parser2/AttachmentDtoAdapterTest.kt
  • stream-chat-android-client/src/test/java/io/getstream/chat/android/client/parser2/AttachmentParsingTest.kt
  • stream-chat-android-client/src/test/java/io/getstream/chat/android/client/parser2/testdata/AttachmentDtoTestData.kt

Walkthrough

The PR makes AttachmentDto.file_size nullable and updates deserialization, domain mapping, and tests to coalesce null values to 0. This allows the Android SDK to gracefully handle API responses where file_size is explicitly null instead of failing during JSON parsing.

Changes

Attachment file_size null-safety handling

Layer / File(s) Summary
Attachment DTO nullable contract and JSON parsing
stream-chat-android-client/src/main/java/io/getstream/chat/android/client/api2/model/dto/AttachmentDto.kt, stream-chat-android-client/src/main/java/io/getstream/chat/android/client/parser2/direct/AttachmentAdapter.kt, stream-chat-android-client/src/test/java/io/getstream/chat/android/client/parser2/AttachmentDtoAdapterTest.kt
AttachmentDto.file_size changes from non-null Int = 0 to nullable Int? = 0. AttachmentAdapter.fromJson now parses file_size using readNullableInt(...) ?: 0 instead of unconditional nextInt(), allowing null JSON values to coalesce to 0. A new unit test validates deserialization of attachments with file_size: null.
Domain mapping with null-safety coalescing
stream-chat-android-client/src/main/java/io/getstream/chat/android/client/api2/mapping/DomainMapping.kt, stream-chat-android-client/src/test/java/io/getstream/chat/android/client/api2/mapping/DomainMappingTest.kt
DomainMapping.toDomain() applies the null-safe operator (file_size ?: 0) when converting AttachmentDto to domain Attachment. Test expectations updated to verify null file_size becomes 0 in the mapped domain model.
Integration test coverage and fixtures
stream-chat-android-client/src/test/java/io/getstream/chat/android/client/parser2/AttachmentParsingTest.kt, stream-chat-android-client/src/test/java/io/getstream/chat/android/client/parser2/testdata/AttachmentDtoTestData.kt
AttachmentParsingTest removes exception expectations and instead asserts both DTO and direct parsing paths coalesce null file_size to 0. New test fixtures (jsonWithNullFileSize, attachmentWithNullFileSize) added. Unused exception-related imports removed.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 A null once broke the parsing chain,
Now defaults smooth the Android rain,
Where file_size was cruel and strict,
We coalesce with graceful trick—
Zero fills the void with care! 🎉

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 28.57% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main change: accepting null file_size in AttachmentDto, which directly reflects the core purpose of the PR.
Description check ✅ Passed The PR description provides Goal, Implementation, and Testing sections matching the template. However, several optional sections (UI Changes, Contributor/Reviewer Checklists) remain uncompleted.
Linked Issues check ✅ Passed The PR fully addresses issue #6428 by accepting null file_size in the DTO and safely mapping it to 0 in domain models, preventing deserialization failures and misleading NETWORK_FAILED errors.
Out of Scope Changes check ✅ Passed All code changes directly support the objective of handling null file_size: DTO nullability, domain mapping, parser adapter updates, and corresponding test additions are in scope.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch null-file-size-v6

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@gpunto gpunto force-pushed the null-file-size-v6 branch from 6e0a9ce to 8dde594 Compare May 22, 2026 14:00
@sonarqubecloud
Copy link
Copy Markdown

@gpunto gpunto enabled auto-merge (squash) May 22, 2026 14:30
@gpunto gpunto merged commit 82ccae3 into v6 May 22, 2026
20 of 21 checks passed
@gpunto gpunto deleted the null-file-size-v6 branch May 22, 2026 14:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr:bug Bug fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants