#110480FileUpload TypeError: buildResourcePointerInput(): Argument #1 ($index) must be of type int, null given when redisplaying a multi-file upload
Description
When a FileUpload form element is configured with multiple: true (i.e. its value is an ObjectStorage<filereference>) and the form is redisplayed with previously-submitted files still present (e.g. a validation error on another field triggers redisplay, or the user navigates back/forward on a multi-page form), rendering crashes with:</filereference>
TypeError
TYPO3\CMS\Form\ViewHelpers\Form\UploadedResourceViewHelper::buildResource
PointerInput():
Argument #1 ($index) must be of type int, null given, called in …/vendor/typo3/cms-form/Classes/ViewHelpers/Form/UploadedResourceViewHelper.php on line 86
Root cause:
In Classes/ViewHelpers/Form/UploadedResourceViewHelper.php, render() does:
} elseif ($resource instanceof ObjectStorage) {
foreach ($resource as $file) {
$index = $resource->getPosition($file);
$resourcePointerValue = $file->getUid() ?? ('file:' .
$file->getOriginalResource()->getOriginalFile()->getUid());
$output .= $this->buildResourcePointerInput(
$index,
(string)$resourcePointerValue,
$this->buildResourcePointerIdAttribute('-' . $index),
);
}
}
TYPO3\CMS\Extbase\Persistence\ObjectStorage::getPosition(object $object): ?int has a nullable return type — it returns null whenever spl_object_hash($object) is not found in its internal addedObjectsPositions map (see Classes/Persistence/ObjectStorage.php). That can legitimately happen for an object that is present in the
storage’s iteration ($storage array) but was never registered via attach()/offsetSet() into addedObjectsPositions — for example when the ObjectStorage is reconstructed/repopulated for a previously-uploaded file across a multi-step form redisplay.
buildResourcePointerInput(int $index, string $resourcePointerValue, string $idAttribute): string, however, declares a non-nullable int $index parameter — so passing the null result straight through raises a TypeError.
This is a plain type-contract mismatch between ObjectStorage::getPosition()’s own declared return type (?int) and its consumer here, independent of exactly which upstream code path fails to populate addedObjectsPositions.
Suggested fix:
The $index value is only used to build a unique per-file index into the hidden name=”…[__submittedFiles][$index][submittedFile][resourcePointer]” field (and a matching id suffix) — it doesn’t need to reflect ObjectStorage’s internal insertion-order bookkeeping. A simple loop counter is sufficient and avoids the getPosition() null case entirely:
} elseif ($resource instanceof ObjectStorage) {
+ $index = 0;
foreach ($resource as $file) {
- $index = $resource->getPosition($file);
$resourcePointerValue = $file->getUid() ?? ('file:'
. $file->getOriginalResource()->getOriginalFile()->getUid());
$output .= $this->buildResourcePointerInput(
$index,
(string)$resourcePointerValue,
$this->buildResourcePointerIdAttribute('-' .
$index),
);
+ $index++;
}
}
Steps to reproduce:
1. Create a form with a FileUpload element configured for multiple files (properties.multiple: true).
2. Upload two or more files.
3. Trigger a redisplay of the page containing that element (e.g. a validation error on a sibling field on the same page, or navigating back to a previous page and forward again on a multi-page form).
4. Observe the TypeError above instead of the form re-rendering with the previously uploaded files retained.
Reviews 2
History 26
-
Gerrit Code Review pushed patch set 1 for main to change 95820 status
NewUnder Review <span data-processor="relativetime" data-value="2026-09-14T20:01:39+00:00" > 09/14/26, 20:01 </span> -
Gerrit Code Review pushed patch set 1 for 14.3 to change 96038 <span data-processor="relativetime" data-value="2026-09-24T14:14:05+00:00" > 09/24/26, 14:14 </span>
-
Georg Ringer commented and changed status
Under ReviewResolved done0 %100 % <span data-processor="relativetime" data-value="2026-09-24T14:20:12+00:00" > 09/24/26, 14:20 </span> -
Gerrit Code Review pushed patch set 2 for 14.3 to change 96038 status
ResolvedUnder Review <span data-processor="relativetime" data-value="2026-09-24T17:40:26+00:00" > 09/24/26, 17:40 </span> -
Gerrit Code Review pushed patch set 3 for 14.3 to change 96038 <span data-processor="relativetime" data-value="2026-09-26T01:11:30+00:00" > 09/26/26, 01:11 </span>
-
Georg Ringer commented and changed status
Under ReviewResolved <span data-processor="relativetime" data-value="2026-09-26T01:45:15+00:00" > 09/26/26, 01:45 </span>Applied in changeset commit:0a9c5d76b1fee5eed4666e8d74a81680f56021cc.
Applied in changeset commit:d88a7c4b815ef026496ad2834294652dd2821f5d.