Skip to content

fix(base): expirationTime on large FileClient.createFile#134

Open
alejandroGM0 wants to merge 1 commit into
hiero-ledger:mainfrom
alejandroGM0:fix/file-client-large-create-expiration
Open

fix(base): expirationTime on large FileClient.createFile#134
alejandroGM0 wants to merge 1 commit into
hiero-ledger:mainfrom
alejandroGM0:fix/file-client-large-create-expiration

Conversation

@alejandroGM0

Copy link
Copy Markdown
Contributor

Problem

FileClientImpl.createFile(byte[], Instant) silently drops the user-provided
expirationTime whenever the payload exceeds FileCreateRequest.FILE_CREATE_MAX_SIZE.

In createFileImpl, the small-file branch correctly picks between
FileCreateRequest.of(contents) and
FileCreateRequest.of(contents, expirationTime)
based on whether an expiration was supplied.

The multi-append branch unconditionally calls the one-arg factory:

final byte[] start = Arrays.copyOf(contents, FileCreateRequest.FILE_CREATE_MAX_SIZE);
final FileCreateRequest request = FileCreateRequest.of(start); // expirationTime dropped

FileCreateRequest.of(byte[]) hardcodes expirationTime = null, and
ProtocolLayerClientImpl.executeFileCreateTransaction only calls
FileCreateTransaction.setExpirationTime(...) when the request's expiration is non-null.

The result is that the underlying SDK transaction never receives the requested expiration,
so the created file falls back to the SDK/network default rather than the caller's value.

The expirationTime parameter is even validated earlier in the method
("must be in the future") before being silently discarded in this branch, which makes
the bug especially misleading.


Fix

Mirror the small-file branching logic in the multi-append branch so the initial
FileCreate transaction carries the caller-supplied expirationTime when present.

No changes to the append path are needed — FileAppend transactions do not accept
an expiration.


Test

Adds testCreateFileWithExpirationForSizeGreaterThanFileCreateMaxSize, which:

  • calls createFile(content, expirationTime) with
    content.length == FILE_CREATE_MAX_SIZE * 2
  • verifies the FileCreateRequest handed to ProtocolLayerClient carries the requested
    expirationTime
    (argThat(request -> expirationTime.equals(request.expirationTime())))
  • verifies the expected number of FileAppend transactions follow

All FileClientImplTest unit tests pass.

The multi-append code path in FileClientImpl.createFileImpl called FileCreateRequest.of(start) without forwarding the user-provided expirationTime, silently dropping it for files larger than FILE_CREATE_MAX_SIZE. Small-file creates already branched on expirationTime; mirror that logic for the large-file path so the initial FileCreate transaction carries the requested expiration.

Adds a regression test covering createFile(byte[], Instant) with content larger than FILE_CREATE_MAX_SIZE.

Signed-off-by: Alejandro <26930485+alejandroGM0@users.noreply.github.com>
@alejandroGM0 alejandroGM0 force-pushed the fix/file-client-large-create-expiration branch from ec05fcc to 22cc419 Compare May 4, 2026 21:57
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.

1 participant