Description
Symfony version(s) affected
4.4.39+, 5.4.6+
Description
ca56620 changed the way the cached annotation reader is managed in the late compiler pass AddAnnotationsCachedReaderPass
But making the annotations.cached_reader
service public during optimizations and turning it private after them breaks the expectations of the optimizations themselves (a public alias pointing to a public service does not get optimized the same than a public alias pointing to a private service).
The annotation_reader
service is the only service for which we do such weird thing to allow using that service (without caching) while the container is being built.
But we should really have a functional test ensuring that the logic does not break the public access to the service.
How to reproduce
Put that in a WebTestCase (or change the way to get a booted kernel):
self::bootKernel();
$annotationReader = self::$kernel->getContainer()->get('annotation_reader');
This is producing an error because the compiled container optimized the annotation_reader
alias in a way relying on the fact that annotations.cached_reader
would be public, but this changed after.
Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException: The "annotations.cached_reader" service or alias has been removed or inlined when the container was compiled. You should either make it public, or stop using the container directly and use dependency injection instead.
Possible Solution
No response
Additional Context
No response