From 80bec1249f3ec95e1af6fad067ffd02f9565e10e Mon Sep 17 00:00:00 2001 From: Stefan Froemken Date: Mon, 23 Nov 2026 14:28:13 +0100 Subject: [PATCH] [BUGFIX] Rebuild proxy class removed by cache flush A concurrent cache flush may delete the proxy file between has() and requireOnce(). Composer then silently loads the base class without the extending classes. Rebuild the entry if requireOnce() returns false. Co-Authored-By: Claude Opus 5.5 --- Classes/Loader/ClassLoader.php | 7 ++++++- Tests/Functional/Loader/ClassLoaderTest.php | 21 +++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/Classes/Loader/ClassLoader.php b/Classes/Loader/ClassLoader.php index 8fe95de..ef67d5c 100644 --- a/Classes/Loader/ClassLoader.php +++ b/Classes/Loader/ClassLoader.php @@ -48,7 +48,12 @@ public function loadClass(string $className): bool $this->classCacheManager->build($cacheEntryIdentifier, $className); } - $this->classCache->requireOnce($cacheEntryIdentifier); + // A concurrent cache flush may remove the cache entry after has() returned true. Without + // the merged file, composer would silently load the base class without the extending classes. + if ($this->classCache->requireOnce($cacheEntryIdentifier) === false) { + $this->classCacheManager->build($cacheEntryIdentifier, $className); + $this->classCache->requireOnce($cacheEntryIdentifier); + } $return = true; } diff --git a/Tests/Functional/Loader/ClassLoaderTest.php b/Tests/Functional/Loader/ClassLoaderTest.php index 9a180b0..339abc1 100644 --- a/Tests/Functional/Loader/ClassLoaderTest.php +++ b/Tests/Functional/Loader/ClassLoaderTest.php @@ -40,6 +40,27 @@ public function loadClass(): void ->getMock(); $cacheMock->expects($this->once())->method('has')->willReturn(true); $cacheMock->expects($this->once())->method('requireOnce')->willReturn(true); + $classCacheManager->expects($this->never())->method('build'); + + $subject = new ClassLoader($cacheMock, $classCacheManager, $classRegister); + + $condition = $subject->loadClass('test'); + + self::assertTrue($condition); + } + + #[Test] + public function loadClassRebuildsCacheEntryRemovedByConcurrentFlush(): void + { + $classRegister = new ClassRegister(['test' => []]); + $classCacheManager = $this->createMock(ClassCacheManager::class); + $cacheBackend = $this->createMock(FileBackend::class); + $cacheMock = $this->getMockBuilder(PhpFrontend::class) + ->setConstructorArgs(['extender', $cacheBackend]) + ->getMock(); + $cacheMock->expects($this->once())->method('has')->willReturn(true); + $cacheMock->expects($this->exactly(2))->method('requireOnce')->willReturnOnConsecutiveCalls(false, true); + $classCacheManager->expects($this->once())->method('build')->with('test', 'test'); $subject = new ClassLoader($cacheMock, $classCacheManager, $classRegister);