This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.
Summary: | InjectionPoint parameters on @ApplicationScoped bean methods flagged as ERR_WrongQualifierInjectionPointMeta | ||
---|---|---|---|
Product: | javaee | Reporter: | chrisjr |
Component: | CDI | Assignee: | Sergey Petrov <sj-nb> |
Status: | NEW --- | ||
Severity: | normal | ||
Priority: | P3 | ||
Version: | 8.2 | ||
Hardware: | All | ||
OS: | All | ||
Issue Type: | DEFECT | Exception Reporter: |
Description
chrisjr
2014-04-29 13:38:51 UTC
Integrated into 'main-silver', will be available in build *201407120001* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress) Changeset: http://hg.netbeans.org/main-silver/rev/44b70bf46802 User: Sergey B. Petrov <sj-nb@netbeans.org> Log: #244173 fix message from what I can see from http://docs.jboss.org/weld/reference/1.0.0/en-US/html/producermethods.html and InjectionPoint http://docs.jboss.org/weld/reference/latest/en-US/html/injection.html it may not be an issue, but it's not yet completely clear to me as I'm not very experienced in cdi. Are you sure this way is allowed? (In reply to Sergey Petrov from comment #2) > Are you sure this way is allowed? According to: http://docs.jboss.org/cdi/api/1.0/javax/enterprise/inject/spi/InjectionPoint.html "May represent an injected field or a parameter of a bean constructor, initializer method, producer method, disposer method or observer method." The crucial requirement seems to be: "Only dependent objects, may obtain information about the injection point to which they belong." And my @Produces method is indeed (correctly) creating a @Dependent object. My code also works fine in both WELD 1.1.2.Final (i.e. JBoss 6.1.0) and WELD 2.1.2.Final, which I take to mean that it is legal in CDI 1.0 and 1.1. I'm referring to next text "Wait, what if CreditCardPaymentStrategy is a request-scoped bean? Then the producer method has the effect of "promoting" the current request scoped instance into session scope. This is almost certainly a bug!" it doesn't mean this code will not work, but there may be some issues. I suppose this warning was created based on: "Only dependent objects, may obtain information about the injection point to which they belong." But may be in case of producer methods, parent bean should be considers as bean created by producer with scope of producer itself. (In reply to Sergey Petrov from comment #4) > I'm referring to next text > "Wait, what if CreditCardPaymentStrategy is a request-scoped bean? Then the > producer method has the effect of "promoting" the current request scoped > instance into session scope. This is almost certainly a bug!" That text is referring to the following code: @Produces @Preferred @SessionScoped public PaymentStrategy getPaymentStrategy(CreditCardPaymentStrategy ccps, CheckPaymentStrategy cps, PayPalPaymentStrategy ppps) { switch (paymentStrategy) { case CREDIT_CARD: return ccps; case CHEQUE: return cps; case PAYPAL: return ppps; default: return null; } } i.e. a @Produces *method* that receives a CreditCardPaymentStrategy bean as an argument, and then returns it as a @SessionScoped bean. However, my @Produces method is returning a @Dependent scoped bean. And the fact that my @Produces method also lives on an @ApplicationScoped bean doesn't change that at all. (In reply to Sergey Petrov from comment #4) > I suppose this warning was created based on: "Only dependent objects, may > obtain information about the injection point to which they belong." I agree. However, my @Produces method *is* creating a @Dependent scoped object. The scope of the method's parent bean is irrelevant here. > But may be in case of producer methods, parent bean should be considers as > bean created by producer with scope of producer itself. I think you need to reexamine the code example in section 8.2 "Injection into producer methods". That's no bean - that's a *method*. If your quote is: "Only dependent objects, may obtain information about the injection point to which they belong." And then: "I agree. However, my @Produces method *is* creating a @Dependent scoped object. The scope of the method's parent bean is irrelevant here." Well, the scope of the bean you "are producing" I believe is irrelevant. It is Dependent scoped in this bean, it could be request scoped or any scope you would like to produce. The choice is immaterial since according to the first quote: it would appear to me that the producer bean, which is the only bean that has access "obtain information about the injection" it is associated to is the one that has to be made Dependent scoped. The produced Bean will be in no condition to obtain information about its injection point, but the producer does. Do Producers need to always be made dependent scoped to respect the specification? (In reply to 99sono from comment #7) > Do Producers need to always be made dependent scoped to respect the > specification? As I understand it, a @Produces method cannot use InjectionPoint unless it is creating a @Dependent bean. The InjectionPoint is itself an implicit CDI bean that belongs to the @Dependent bean being produced. I should probably mention that my example code works as expected in WELD 1.1.x, 2.0.x, 2.1.x, 2.2.x and 2.3.x despite the NetBeans warning, and that WELD is the reference CDI implementation. This bug still exists in NetBeans 8.1. I have also confirmed with the WELD developers that this is indeed a NetBeans bug: https://developer.jboss.org/message/946125#946125 "[Y]ou are correct and it's a NetBeans bug. In your case, SampleBean.getValue() is a producer method with @Dependent scope and so it is possible to use the injection point metadata. It wouldn't be possible for any other scope because we couldn't guarantee there's only one injection point per bean instance. See also http://docs.jboss.org/cdi/spec/1.2/cdi-spec.html#injection_point" This bug still exists in NetBeans 8.1, but the error message has changed to "An injection point has type InjectionPoint and qualifier @Default but bean declares not @Dependent scope." I'm not sure why having a @Default qualifier is deemed relevant here - this message doesn't change even if I remove the @Default qualifier by adding @Any - but the misunderstanding about requiring @Dependent scope remains. To be clear: InjectionPoint is a built-in CDI bean that provides metadata about where a @Dependent-scoped bean is being injected. And only a @Dependent-scoped bean can have InjectionPoint metadata because these are the only beans that have unique and unambiguous injection points for the metadata to describe. NetBeans is confusing the @Produces method case: @Dependent @Produces MyBean getBean(InjectionPoint injection) { // Create a @Dependent scoped bean for injection; // InjectionPoint describes where MyBean is being // injected. return new MyBean(); } with this case: // Another @Dependent scoped bean for injection; // InjectionPoint describes where OtherBean is // being injected. @Dependent public class OtherBean { @Inject OtherBean(InjectionPoint injection) { ... } } Here I can confirm here about the most important topic which is related about the https://computernamewindows10.com how do i change account name in windows 10. |