common icon indicating copy to clipboard operation
common copied to clipboard

AnnotationReader may incorrectly throw exceptions

Open arnaud-lb opened this issue 14 years ago • 4 comments

The AnnotationReader pre-parses classes' doc block with a PreParser that doesn't have import (use) informations.

Due to this, it can happen that an annotation resolves to a wrong class.

The parser will then attempt to validate the class and fail (no @Annotation, cannot be used on classes, etc).

Here is a test case: https://github.com/doctrine/common/pull/161

The ArrayObject annotation is resolved as \ArrayObject, which is not a valid annotation. This results in the following exception:

Doctrine\Common\Annotations\AnnotationException: [Semantical Error] The class "ArrayObject" 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 "ArrayObject". If it is indeed no annotation, then you need to add @IgnoreAnnotation("ArrayObject") to the _class_ doc comment of class Doctrine\Tests\Common\Annotations\Issue159\ParseMe.

arnaud-lb avatar Jul 06 '12 17:07 arnaud-lb

could you create a pull request instead of pasting a diff ? It will be easier for us

stof avatar Jul 06 '12 17:07 stof

@stof done

arnaud-lb avatar Jul 06 '12 17:07 arnaud-lb

I have a similar error on a Symfony 2.1 project :

[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 @Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter.

How can i fix it, get around ?

popofr13 avatar Oct 12 '12 09:10 popofr13

This issue was moved to doctrine/annotations#79

guilhermeblanco avatar Mar 27 '16 03:03 guilhermeblanco