diff --git a/typo3/sysext/core/Classes/Utility/GeneralUtility.php b/typo3/sysext/core/Classes/Utility/GeneralUtility.php index c0109bbc16021f69b8682c7e231bc45ad5a15364..b4d2624338373932e60f3ea6d131d982dbfc52a6 100644 --- a/typo3/sysext/core/Classes/Utility/GeneralUtility.php +++ b/typo3/sysext/core/Classes/Utility/GeneralUtility.php @@ -3487,6 +3487,9 @@ class GeneralUtility ) { return array_shift(self::$nonSingletonInstances[$finalClassName]); } + if (!class_exists($finalClassName)) { + throw new \InvalidArgumentException('Class "' . $className . '" not found', 1503060454); + } // Create new instance and call constructor with parameters $instance = new $finalClassName(...$constructorArguments); // Register new singleton instance diff --git a/typo3/sysext/core/Tests/Unit/Utility/GeneralUtilityTest.php b/typo3/sysext/core/Tests/Unit/Utility/GeneralUtilityTest.php index 9b35773d1c239bf2e26c6c049f0bab8d9627a4c4..934b8e03449137d2361efbdbbf7eac50bb955efe 100644 --- a/typo3/sysext/core/Tests/Unit/Utility/GeneralUtilityTest.php +++ b/typo3/sysext/core/Tests/Unit/Utility/GeneralUtilityTest.php @@ -3771,6 +3771,31 @@ class GeneralUtilityTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase GeneralUtility::makeInstance(['foo']); } + /** + * @test + */ + public function makeInstanceWithUnknownClassThrowsException() + { + $this->expectException(\InvalidArgumentException::class); + $this->expectExceptionCode(1503060454); + + GeneralUtility::makeInstance('UnknownClass' . time()); + } + + /** + * @test + */ + public function makeInstanceWithUnknownClassImplementationThrowsException() + { + $this->expectException(\InvalidArgumentException::class); + $this->expectExceptionCode(1503060454); + + GeneralUtilityFixture::resetFinalClassNameCache(); + $GLOBALS['TYPO3_CONF_VARS']['SYS']['Objects'][OriginalClassFixture::class] = ['className' => 'UnknownClass' . time()]; + + GeneralUtility::makeInstance(OriginalClassFixture::class); + } + /** * @test */