Actions
Bug #86857
closedLinkvalidator task crashes with an isMissing Called on Null error
Status:
Closed
Priority:
Should have
Assignee:
-
Category:
Linkvalidator
Target version:
-
Start date:
2018-11-05
Due date:
% Done:
100%
Estimated time:
TYPO3 Version:
8
PHP Version:
Tags:
Complexity:
Is Regression:
Sprint Focus:
Description
The Following Code in TYPO3\CMS\Linkvalidator\Linktype\FileLinktype does not handle the possible return value of $resourceFactory->retrieveFileOrFolderObject which returns null in certain cases.
It also seems like the documentation of retrieveFileOrFolderObject does not hint the possibility that a null value can be returned.
public function checkLink($url, $softRefEntry, $reference)
{
$resourceFactory = GeneralUtility::makeInstance(ResourceFactory::class);
try {
$file = $resourceFactory->retrieveFileOrFolderObject($url);
} catch (FileDoesNotExistException $e) {
return false;
} catch (FolderDoesNotExistException $e) {
return false;
}
return !$file->isMissing();
}
I would propose something like this:
public function checkLink($url, $softRefEntry, $reference)
{
$resourceFactory = GeneralUtility::makeInstance(ResourceFactory::class);
try {
$file = $resourceFactory->retrieveFileOrFolderObject($url);
} catch (FileDoesNotExistException $e) {
return false;
} catch (FolderDoesNotExistException $e) {
return false;
}
if (!is_null($file) {
return !$file->isMissing();
} else {
return false;
}
}
Actions