Dans l'implémentation Contexts and Dependency Injection (CDI) 1.0, la méthode getAnnotated sur une classe qui implémente l'interface
javax.enterprise.inject.spi.InjectionPoint peut renvoyer une instance de javax.enterprise.inject.spi.Annotated.
Dans l'implémentation
CDI 1.2, la méthode getAnnotated doit renvoyer une instance de AnnotatedField ou de AnnotatedParameter, selon que le
point d'injection représente une zone injectée ou un paramètre sur un constructeur ou une méthode.
Cette règle signale les appels au constructeur Annotated dans une méthode getAnnotated sur une classe
qui implémente l'interface javax.enterprise.inject.spi.InjectionPoint. Par exemple, l'appel suivant à new
Annotated() est signalé :
< code> public class MyInjectionPoint implémente InjectionPoint {
public annoté getAnnotated() {
renvoyer une nouvelle () annotée () {
public Set < Annotation> getAnnotations() {
return null;
}
...
} ;
}
...
} < /code>
Le scanner d'application binaire signale toutes les méthodes getAnnotated sur des classes implémentant l'interface
javax.enterprise.inject.spi.InjectionPoint. Si la méthode getAnnotated marquée renvoie une instance de AnnotatedParameter ou de AnnotatedField, cette règle peut être ignorée. Si la méthode getAnnotated renvoie une instance de
Annotated, le code doit être modifié.
Dans l'implémentation CDI 1.2, l'application contenant la classe MyInjectionPoint ne démarre pas et renvoie l'exception suivante :
org.jboss.weld.exceptions.IllegalArgumentException: WELD-001521: InjectionPoint.getAnnotated() doit renvoyer soit AnnotatedParameter, soit
AnnotatedField
Pour résoudre ce problème, remplacez l'appel à new Annotated() par new AnnotatedField() ou par new AnnotatedParameter(), selon que le
point d'injection représente une zone injectée ou un paramètre sur un constructeur ou une méthode.
Pour plus d'informations sur l'implémentation Java EE 7 CDI 1.2, voir Changements de comportement dans Contexts and Dependency Injection 1.2.