Issue Bug Resolved

#110480FileUpload TypeError: buildResourcePointerInput(): Argument #1 ($index) must be of type int, null given when redisplaying a multi-file upload

Steffen Matthes 08/13/26, 17:03 updated 09/26/26, 01:45

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

  1. Georg Ringer commented and changed status Under Review Resolved done 0 % 100 % <span data-processor="relativetime" data-value="2026-09-24T14:20:12+00:00" > 09/24/26, 14:20 </span>

    Applied in changeset commit:d88a7c4b815ef026496ad2834294652dd2821f5d.

  2. Gerrit Code Review pushed patch set 2 for 14.3 to change 96038 status Resolved Under Review <span data-processor="relativetime" data-value="2026-09-24T17:40:26+00:00" > 09/24/26, 17:40 </span>

  3. Georg Ringer commented and changed status Under Review Resolved <span data-processor="relativetime" data-value="2026-09-26T01:45:15+00:00" > 09/26/26, 01:45 </span>

    Applied in changeset commit:0a9c5d76b1fee5eed4666e8d74a81680f56021cc.