Skip to content

fix: handle missing content-length header in statObject (#108)#110

Open
hammadparveez wants to merge 1 commit intoxtyxtyx:masterfrom
hammadparveez:fix/stat-object-content-length-null-crash
Open

fix: handle missing content-length header in statObject (#108)#110
hammadparveez wants to merge 1 commit intoxtyxtyx:masterfrom
hammadparveez:fix/stat-object-content-length-null-crash

Conversation

@hammadparveez
Copy link

Fixes #108

Replace int.parse with int.tryParse when reading the content-length
response header in statObject. The header is not guaranteed to be
present; the null-check operator caused an unhandled crash. Using
tryParse with a null-coalescing fallback returns null gracefully,
which matches the already-nullable int? size field on StatObjectResult.

Fixes xtyxtyx#108

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings February 24, 2026 18:58
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes a runtime crash in Minio.statObject() when the server’s HEAD response omits the content-length header (issue #108), by making size parsing null-safe.

Changes:

  • Replace int.parse(...!) with int.tryParse(...) for content-length when building StatObjectResult.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 1138 to 1139
lastModified: parseRfc7231Time(resp.headers['last-modified']!),
acl: retrieveAcls ? await getObjectACL(bucket, object) : null,
Copy link

Copilot AI Feb 24, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

StatObjectResult.lastModified is nullable, but statObject() force-unwraps resp.headers['last-modified']!, which will still crash if that header is absent. To align with the model’s nullability (and avoid a similar class of runtime errors), parse it conditionally and pass null when the header is missing.

Copilot uses AI. Check for mistakes.
Comment on lines 1134 to +1136
return StatObjectResult(
etag: etag,
size: int.parse(resp.headers['content-length']!),
size: int.tryParse(resp.headers['content-length'] ?? ''),
Copy link

Copilot AI Feb 24, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are existing tests for statObject() that assert size is non-null, but this change introduces new behavior when content-length is missing (returning null instead of crashing). Please add coverage for the missing-header case; if it’s hard to reproduce against the live MinIO endpoint, consider extracting the header-parsing into a small pure helper that can be unit tested with synthetic header maps.

Copilot uses AI. Check for mistakes.
return StatObjectResult(
etag: etag,
size: int.parse(resp.headers['content-length']!),
size: int.tryParse(resp.headers['content-length'] ?? ''),
Copy link

Copilot AI Feb 24, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

int.tryParse(resp.headers['content-length'] ?? '') changes behavior for malformed content-length values (it will silently return null instead of throwing). Consider handling the two cases separately: return null only when the header is missing, but if it is present and not parseable, surface a clear error so callers aren’t debugging an unexpected null size.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

statObject method is crashing with Error: Null check operator used on a null value

2 participants