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.

Bug 244173 - InjectionPoint parameters on @ApplicationScoped bean methods flagged as ERR_WrongQualifierInjectionPointMeta
Summary: InjectionPoint parameters on @ApplicationScoped bean methods flagged as ERR_W...
Status: NEW
Alias: None
Product: javaee
Classification: Unclassified
Component: CDI (show other bugs)
Version: 8.2
Hardware: All All
: P3 normal with 3 votes (vote)
Assignee: Sergey Petrov
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-04-29 13:38 UTC by chrisjr
Modified: 2019-07-16 14:21 UTC (History)
0 users

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description chrisjr 2014-04-29 13:38:51 UTC
I have an @ApplicationScoped bean that exposes a @Produces method, something like this:

@ApplicationScoped
public class SampleBean {

    @Produces
    public String getValue(InjectionPoint injection) {
        return "foo";
    }

}

However, NetBeans flags this @Produces method as "ERR_WrongQualifierInjectionPointMeta". My (real) bean is intended to inject configuration parameter data into other beans, which means that I really do only want one instance of the bean to exist. Having said that, I will mention that removing @ApplicationScoped does make the error disappear.
Comment 1 Quality Engineering 2014-07-12 05:11:04 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
Comment 2 Sergey Petrov 2014-07-21 11:30:22 UTC
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?
Comment 3 chrisjr 2014-07-21 11:56:06 UTC
(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.
Comment 4 Sergey Petrov 2014-07-21 12:30:41 UTC
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.
Comment 5 chrisjr 2014-07-21 12:45:11 UTC
(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.
Comment 6 chrisjr 2014-07-21 12:51:26 UTC
(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*.
Comment 7 99sono 2015-11-15 13:08:49 UTC
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?
Comment 8 chrisjr 2015-11-15 22:10:52 UTC
(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.
Comment 9 chrisjr 2015-11-18 08:50:05 UTC
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"
Comment 10 chrisjr 2015-12-07 16:40:12 UTC
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) {
       ...
    }

}
Comment 11 arun6 2019-07-16 14:21:10 UTC
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.