Uncaught exception 'Doctrine\Common\Annotations\AnnotationException'
From @cedrictailly on August 20, 2013 19:45
Hi,
I found a bug on a this call :
$reader = $em->getConfiguration()->getMetadataDriverImpl()->getReader();
(...)
$reader->getClassMetadata($classname)
...were $em is the EntityManager and $classname a string, here is the error :
[Semantical Error] The class "Annotation" is not annotated with @Annotation. Are you sure this class can be used as annotation? If so, then you need to add @Annotation to the class doc comment of "Annotation". If it is indeed no annotation, then you need to add @IgnoreAnnotation("Annotation") to the class doc comment of class @Doctrine\ORM\Mapping\Entity.
The context is too complex to reproduce but after a session of debugging, it seems there is a miss on a condition in class Doctrine\Common\Annotations\DocParser, in :
if (self::$annotationMetadata[$name]['is_annotation'] === false) {
if ($this->ignoreNotImportedAnnotations || isset($this->ignoredAnnotationNames[$originalName])) {
return false;
}
...replacing :
isset($this->ignoredAnnotationNames[$originalName])
...by :
$this->ignoreNotImportedAnnotations || isset($this->ignoredAnnotationNames[$originalName])
...should correct the problem.
Copied from original issue: doctrine/common#292
From @songokas on April 1, 2015 15:28
Is anyone dealing with this ? I have the same issue
use Doctrine\Common\Annotations\DocParser;
require_once 'vendor/autoload.php';
/**
* @Annotation
* @Target({"METHOD"})
*/
class CacheMe {}
class FailMe {}
class ReadMe
{
/**
* @CacheMe
*/
public function testMe1()
{
echo "It works";
}
/**
* @MissMe
*/
public function testMe2()
{
echo "It works";
}
/**
* @FailMe
*/
public function testMe3()
{
echo "It works";
}
}
$parser = new DocParser();
$parser->setIgnoreNotImportedAnnotations(true);
$method1 = new ReflectionMethod('ReadMe', 'testMe1');
$method2 = new ReflectionMethod('ReadMe', 'testMe2');
$method3 = new ReflectionMethod('ReadMe', 'testMe3');
var_dump($parser->parse($method1->getDocComment()));
var_dump($parser->parse($method2->getDocComment()));
var_dump($parser->parse($method3->getDocComment()));
Output:
array(1) {
[0] =>
class CacheMe#11 (0) {
}
}
array(0) {
}
PHP Fatal error: Uncaught exception 'Doctrine\Common\Annotations\AnnotationException' with message '[Semantical Error] The class "FailMe" is not annotated with @Annotation. Are you sure this class can be used as annotation? If so, then you need to add @Annotation to the _class_ doc comment of "FailMe". If it is indeed no annotation, then you need to add @IgnoreAnnotation("FailMe") to the _class_ doc comment of .' in /workspace/vagrant/csms/vendor/doctrine/annotations/lib/Doctrine/Common/Annotations/AnnotationException.php:54
Stack trace:
#0 /workspace/vagrant/csms/vendor/doctrine/annotations/lib/Doctrine/Common/Annotations/DocParser.php(727): Doctrine\Common\Annotations\AnnotationException::semanticalError('The class "Fail...')
#1 /workspace/vagrant/csms/vendor/doctrine/annotations/lib/Doctrine/Common/Annotations/DocParser.php(641): Doctrine\Common\Annotations\DocParser->Annotation()
#2 /workspace/vagrant/csms/vendor/doctrine/annotations/lib/Doctrine/Common/Annotations/DocParser.php(334): Doctrine\Common\Annotations\DocParser in /workspace/vagrant/csms/vendor/doctrine/annotations/lib/Doctrine/Common/Annotations/AnnotationException.php on line 54
Expected behaviour:
var_dump($parser->parse($method3->getDocComment()));
should not throw exception and return empty list
From @Ocramius on April 1, 2015 15:31
Convert it to a test case and it can be debugged/fixed