[weld-dev] Validating for fields that are annotated with both EJB and Inject
Matej Novotny
manovotn at redhat.com
Wed Apr 15 06:59:38 EDT 2020
+1 to what Martin says, I've seen similar scenarios.
Matej
----- Original Message -----
> From: "Martin Kouba" <mkouba at redhat.com>
> To: "Emily Jiang" <emijiang6 at googlemail.com>, "Benjamin Confino" <BENJAMIC at uk.ibm.com>
> Cc: "Weld-Dev List" <weld-dev at lists.jboss.org>
> Sent: Wednesday, April 15, 2020 12:53:16 PM
> Subject: Re: [weld-dev] Validating for fields that are annotated with both EJB and Inject
>
> Dne 15. 04. 20 v 12:42 Emily Jiang napsal(a):
> > Matej,
> >
> > Since @Inject can only work with a qualifier annotation not anything
> > other annotations,
>
> That's not correct. You can add any annotation to an injection point.
> I've seen it several times where a framework inspected the
> InjectionPoint to find certain annotations that have no meaning in CDI.
>
>
> > do you think adding a validation criteria to assert
> > that is acceptable?
> > For IDE validation, it is quite limited because a lot of work needs to
> > be done via runtime to figure out whether the 2nd annotation is a CDI
> > qualifier or not.
> >
> > Thanks
> > Emily
> >
> > On Tue, Apr 14, 2020 at 3:28 PM Benjamin Confino <BENJAMIC at uk.ibm.com
> > <mailto:BENJAMIC at uk.ibm.com>> wrote:
> >
> > Hello weld
> >
> > I had a customer with an issue that I believe occurred because they
> > annotated a field with both @Inject and @EJB. This has given me two
> > questions:
> >
> > 1) Should weld throw an error when a field is annotated with both
> > annotations?
> >
> > 2) If so is the correct way to add something like
> >
> > if (ij.getAnnotated().isAnnotationPresent(Inject.class) &&
> > ij.getAnnotated().isAnnotationPresent(EJB.class)) {
> > throw ...
> > }
> >
> > to Validator.validateInjectionPointForDefinitionErrors()
> >
> > If so I'm willing to create a pull request, all I'd need is for you
> > to tell me what the error message should say and please point me to
> > which test I should expand to cover this case.
> >
> > Regards
> > Benjamin
> > Unless stated otherwise above:
> > IBM United Kingdom Limited - Registered in England and Wales with
> > number 741598.
> > Registered office: PO Box 41, North Harbour, Portsmouth, Hampshire
> > PO6 3AU
> > _______________________________________________
> > weld-dev mailing list
> > weld-dev at lists.jboss.org <mailto:weld-dev at lists.jboss.org>
> > https://lists.jboss.org/mailman/listinfo/weld-dev
> >
> >
> >
> > --
> > Thanks
> > Emily
> >
> >
> > _______________________________________________
> > weld-dev mailing list
> > weld-dev at lists.jboss.org
> > https://lists.jboss.org/mailman/listinfo/weld-dev
> >
>
> --
> Martin Kouba
> Senior Software Engineer
> Red Hat, Czech Republic
>
>
> _______________________________________________
> weld-dev mailing list
> weld-dev at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/weld-dev
More information about the weld-dev
mailing list