You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@felix.apache.org by Anthony Bargnesi <ab...@gmail.com> on 2012/10/16 22:46:35 UTC

(iPOJO) NPE when injecting BundleContext and @Requires in constructor

Hi folks,

I have an iPOJO service component that takes two constructor parameters:
  - BundleContext
  - another service with @Requires

My scenario is similar to the following contrived example:

@Component
@Provides
@Instantiate
public class DefaultUserService implements UserService {
     ...
}

@Component
@Provides
@Instantiate
public class DefaultPersonService extends ObjectService implements
PersonService {

     private final BundleContext ctx;

     public DefaultPersonService(BundleContext ctx,
         @Requires(nullable = false, proxy = false)
UserService userService) {

         super(userService);
         this.ctx = ctx;
     }
}

In my example I require ObjectService to be instantiated with the
UserService so it must
be a constructor parameter.

I found that if I also want BundleContext to be injected then I receive the
following
NullPointerException:

[2012-10-16 16:11:11.886] ERROR iLogServiceListener@65284069
org.osgi.service.log.LogService
Bundle person.impl_0.1.0, [ERROR] person.impl.DefaultPersonService : null
java.lang.NullPointerException: null
         at
org.apache.felix.ipojo.InstanceManager.handleBCInjections(InstanceManager.java:
253)
         at
org.apache.felix.ipojo.InstanceManager.configure(InstanceManager.java:207)
         at
org.apache.felix.ipojo.ComponentFactory.createInstance(ComponentFactory.java:
178)
         at
org.apache.felix.ipojo.IPojoFactory.createComponentInstance(IPojoFactory.java:
310)
         at
org.apache.felix.ipojo.IPojoFactory.createComponentInstance(IPojoFactory.java:
239)
         at
org.apache.felix.ipojo.InstanceCreator$ManagedInstance.create(InstanceCreator.java:
355)
         at
org.apache.felix.ipojo.InstanceCreator.addInstance(InstanceCreator.java:89)
         at org.apache.felix.ipojo.Extender.parse(Extender.java:306)
         at
org.apache.felix.ipojo.Extender.startManagementFor(Extender.java:237)
         at org.apache.felix.ipojo.Extender.access$600(Extender.java:52)
         at org.apache.felix.ipojo.Extender$CreatorThread.run(Extender.java:
769)
         at java.lang.Thread.run(Thread.java:722)

If I remove the BundleContext constructor parameter then the UserService is
injected and the DefaultPersonService
is valid.

I have tested this against the latest trunk code at:
https://svn.apache.org/repos/asf/felix/trunk/ipojo/

I thought it could be related to the following fix:
https://issues.apache.org/jira/browse/FELIX-3576

Could this be a bug?

Thanks!
Anthony Bargnesi

Re: (iPOJO) NPE when injecting BundleContext and @Requires in constructor

Posted by Anthony Bargnesi <ab...@gmail.com>.
Göktürk,

I was watching the issue but I couldn't get to testing until now.  Your fix
seemed to
address my issues so I will update the jira issue.

Thanks!
Anthony Bargnesi

On Wed, Oct 17, 2012 at 2:09 PM, Göktürk Gezer <go...@gmail.com>wrote:

> Hi Anthony,
>
> In case you're not watching the JIRA, It's fixed and I'm waiting for your
> confirmation...
>
>
> *Regards,*
> *Göktürk*
>
> On Wed, Oct 17, 2012 at 3:24 PM, Anthony Bargnesi <abargnesi@gmail.com
> >wrote:
>
> > Thanks Clement.  I couldn't re-open the issue with my account.  At least
> I
> > couldn't find where
> > to re-open the issue.  I did comment
> > https://issues.apache.org/jira/browse/FELIX-3576 with what
> > I am seeing.
> >
> > Thanks!
> > Anthony Bargnesi
> >
> > On Wed, Oct 17, 2012 at 3:08 AM, Clement Escoffier <
> > clement.escoffier@gmail.com> wrote:
> >
> > > Hi,
> > >
> > > It looks definitely related to FELIX-3576. Could you re-open the
> issue. I
> > > will have a look.
> > >
> > > Regards,
> > >
> > > Clement
> > >
> > > On 16 oct. 2012, at 22:46, Anthony Bargnesi <ab...@gmail.com>
> wrote:
> > >
> > > > Hi folks,
> > > >
> > > > I have an iPOJO service component that takes two constructor
> > parameters:
> > > >  - BundleContext
> > > >  - another service with @Requires
> > > >
> > > > My scenario is similar to the following contrived example:
> > > >
> > > > @Component
> > > > @Provides
> > > > @Instantiate
> > > > public class DefaultUserService implements UserService {
> > > >     ...
> > > > }
> > > >
> > > > @Component
> > > > @Provides
> > > > @Instantiate
> > > > public class DefaultPersonService extends ObjectService implements
> > > > PersonService {
> > > >
> > > >     private final BundleContext ctx;
> > > >
> > > >     public DefaultPersonService(BundleContext ctx,
> > > >         @Requires(nullable = false, proxy = false)
> > > > UserService userService) {
> > > >
> > > >         super(userService);
> > > >         this.ctx = ctx;
> > > >     }
> > > > }
> > > >
> > > > In my example I require ObjectService to be instantiated with the
> > > > UserService so it must
> > > > be a constructor parameter.
> > > >
> > > > I found that if I also want BundleContext to be injected then I
> receive
> > > the
> > > > following
> > > > NullPointerException:
> > > >
> > > > [2012-10-16 16:11:11.886] ERROR iLogServiceListener@65284069
> > > > org.osgi.service.log.LogService
> > > > Bundle person.impl_0.1.0, [ERROR] person.impl.DefaultPersonService :
> > null
> > > > java.lang.NullPointerException: null
> > > >         at
> > > >
> > >
> >
> org.apache.felix.ipojo.InstanceManager.handleBCInjections(InstanceManager.java:
> > > > 253)
> > > >         at
> > > >
> > >
> >
> org.apache.felix.ipojo.InstanceManager.configure(InstanceManager.java:207)
> > > >         at
> > > >
> > >
> >
> org.apache.felix.ipojo.ComponentFactory.createInstance(ComponentFactory.java:
> > > > 178)
> > > >         at
> > > >
> > >
> >
> org.apache.felix.ipojo.IPojoFactory.createComponentInstance(IPojoFactory.java:
> > > > 310)
> > > >         at
> > > >
> > >
> >
> org.apache.felix.ipojo.IPojoFactory.createComponentInstance(IPojoFactory.java:
> > > > 239)
> > > >         at
> > > >
> > >
> >
> org.apache.felix.ipojo.InstanceCreator$ManagedInstance.create(InstanceCreator.java:
> > > > 355)
> > > >         at
> > > >
> > >
> >
> org.apache.felix.ipojo.InstanceCreator.addInstance(InstanceCreator.java:89)
> > > >         at org.apache.felix.ipojo.Extender.parse(Extender.java:306)
> > > >         at
> > > > org.apache.felix.ipojo.Extender.startManagementFor(Extender.java:237)
> > > >         at
> org.apache.felix.ipojo.Extender.access$600(Extender.java:52)
> > > >         at
> > > org.apache.felix.ipojo.Extender$CreatorThread.run(Extender.java:
> > > > 769)
> > > >         at java.lang.Thread.run(Thread.java:722)
> > > >
> > > > If I remove the BundleContext constructor parameter then the
> > UserService
> > > is
> > > > injected and the DefaultPersonService
> > > > is valid.
> > > >
> > > > I have tested this against the latest trunk code at:
> > > > https://svn.apache.org/repos/asf/felix/trunk/ipojo/
> > > >
> > > > I thought it could be related to the following fix:
> > > > https://issues.apache.org/jira/browse/FELIX-3576
> > > >
> > > > Could this be a bug?
> > > >
> > > > Thanks!
> > > > Anthony Bargnesi
> > >
> > >
> > > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
> > > For additional commands, e-mail: users-help@felix.apache.org
> > >
> > >
> >
>

Re: (iPOJO) NPE when injecting BundleContext and @Requires in constructor

Posted by Göktürk Gezer <go...@gmail.com>.
Hi Anthony,

In case you're not watching the JIRA, It's fixed and I'm waiting for your
confirmation...


*Regards,*
*Göktürk*

On Wed, Oct 17, 2012 at 3:24 PM, Anthony Bargnesi <ab...@gmail.com>wrote:

> Thanks Clement.  I couldn't re-open the issue with my account.  At least I
> couldn't find where
> to re-open the issue.  I did comment
> https://issues.apache.org/jira/browse/FELIX-3576 with what
> I am seeing.
>
> Thanks!
> Anthony Bargnesi
>
> On Wed, Oct 17, 2012 at 3:08 AM, Clement Escoffier <
> clement.escoffier@gmail.com> wrote:
>
> > Hi,
> >
> > It looks definitely related to FELIX-3576. Could you re-open the issue. I
> > will have a look.
> >
> > Regards,
> >
> > Clement
> >
> > On 16 oct. 2012, at 22:46, Anthony Bargnesi <ab...@gmail.com> wrote:
> >
> > > Hi folks,
> > >
> > > I have an iPOJO service component that takes two constructor
> parameters:
> > >  - BundleContext
> > >  - another service with @Requires
> > >
> > > My scenario is similar to the following contrived example:
> > >
> > > @Component
> > > @Provides
> > > @Instantiate
> > > public class DefaultUserService implements UserService {
> > >     ...
> > > }
> > >
> > > @Component
> > > @Provides
> > > @Instantiate
> > > public class DefaultPersonService extends ObjectService implements
> > > PersonService {
> > >
> > >     private final BundleContext ctx;
> > >
> > >     public DefaultPersonService(BundleContext ctx,
> > >         @Requires(nullable = false, proxy = false)
> > > UserService userService) {
> > >
> > >         super(userService);
> > >         this.ctx = ctx;
> > >     }
> > > }
> > >
> > > In my example I require ObjectService to be instantiated with the
> > > UserService so it must
> > > be a constructor parameter.
> > >
> > > I found that if I also want BundleContext to be injected then I receive
> > the
> > > following
> > > NullPointerException:
> > >
> > > [2012-10-16 16:11:11.886] ERROR iLogServiceListener@65284069
> > > org.osgi.service.log.LogService
> > > Bundle person.impl_0.1.0, [ERROR] person.impl.DefaultPersonService :
> null
> > > java.lang.NullPointerException: null
> > >         at
> > >
> >
> org.apache.felix.ipojo.InstanceManager.handleBCInjections(InstanceManager.java:
> > > 253)
> > >         at
> > >
> >
> org.apache.felix.ipojo.InstanceManager.configure(InstanceManager.java:207)
> > >         at
> > >
> >
> org.apache.felix.ipojo.ComponentFactory.createInstance(ComponentFactory.java:
> > > 178)
> > >         at
> > >
> >
> org.apache.felix.ipojo.IPojoFactory.createComponentInstance(IPojoFactory.java:
> > > 310)
> > >         at
> > >
> >
> org.apache.felix.ipojo.IPojoFactory.createComponentInstance(IPojoFactory.java:
> > > 239)
> > >         at
> > >
> >
> org.apache.felix.ipojo.InstanceCreator$ManagedInstance.create(InstanceCreator.java:
> > > 355)
> > >         at
> > >
> >
> org.apache.felix.ipojo.InstanceCreator.addInstance(InstanceCreator.java:89)
> > >         at org.apache.felix.ipojo.Extender.parse(Extender.java:306)
> > >         at
> > > org.apache.felix.ipojo.Extender.startManagementFor(Extender.java:237)
> > >         at org.apache.felix.ipojo.Extender.access$600(Extender.java:52)
> > >         at
> > org.apache.felix.ipojo.Extender$CreatorThread.run(Extender.java:
> > > 769)
> > >         at java.lang.Thread.run(Thread.java:722)
> > >
> > > If I remove the BundleContext constructor parameter then the
> UserService
> > is
> > > injected and the DefaultPersonService
> > > is valid.
> > >
> > > I have tested this against the latest trunk code at:
> > > https://svn.apache.org/repos/asf/felix/trunk/ipojo/
> > >
> > > I thought it could be related to the following fix:
> > > https://issues.apache.org/jira/browse/FELIX-3576
> > >
> > > Could this be a bug?
> > >
> > > Thanks!
> > > Anthony Bargnesi
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
> > For additional commands, e-mail: users-help@felix.apache.org
> >
> >
>

Re: (iPOJO) NPE when injecting BundleContext and @Requires in constructor

Posted by Anthony Bargnesi <ab...@gmail.com>.
Thanks Clement.  I couldn't re-open the issue with my account.  At least I
couldn't find where
to re-open the issue.  I did comment
https://issues.apache.org/jira/browse/FELIX-3576 with what
I am seeing.

Thanks!
Anthony Bargnesi

On Wed, Oct 17, 2012 at 3:08 AM, Clement Escoffier <
clement.escoffier@gmail.com> wrote:

> Hi,
>
> It looks definitely related to FELIX-3576. Could you re-open the issue. I
> will have a look.
>
> Regards,
>
> Clement
>
> On 16 oct. 2012, at 22:46, Anthony Bargnesi <ab...@gmail.com> wrote:
>
> > Hi folks,
> >
> > I have an iPOJO service component that takes two constructor parameters:
> >  - BundleContext
> >  - another service with @Requires
> >
> > My scenario is similar to the following contrived example:
> >
> > @Component
> > @Provides
> > @Instantiate
> > public class DefaultUserService implements UserService {
> >     ...
> > }
> >
> > @Component
> > @Provides
> > @Instantiate
> > public class DefaultPersonService extends ObjectService implements
> > PersonService {
> >
> >     private final BundleContext ctx;
> >
> >     public DefaultPersonService(BundleContext ctx,
> >         @Requires(nullable = false, proxy = false)
> > UserService userService) {
> >
> >         super(userService);
> >         this.ctx = ctx;
> >     }
> > }
> >
> > In my example I require ObjectService to be instantiated with the
> > UserService so it must
> > be a constructor parameter.
> >
> > I found that if I also want BundleContext to be injected then I receive
> the
> > following
> > NullPointerException:
> >
> > [2012-10-16 16:11:11.886] ERROR iLogServiceListener@65284069
> > org.osgi.service.log.LogService
> > Bundle person.impl_0.1.0, [ERROR] person.impl.DefaultPersonService : null
> > java.lang.NullPointerException: null
> >         at
> >
> org.apache.felix.ipojo.InstanceManager.handleBCInjections(InstanceManager.java:
> > 253)
> >         at
> >
> org.apache.felix.ipojo.InstanceManager.configure(InstanceManager.java:207)
> >         at
> >
> org.apache.felix.ipojo.ComponentFactory.createInstance(ComponentFactory.java:
> > 178)
> >         at
> >
> org.apache.felix.ipojo.IPojoFactory.createComponentInstance(IPojoFactory.java:
> > 310)
> >         at
> >
> org.apache.felix.ipojo.IPojoFactory.createComponentInstance(IPojoFactory.java:
> > 239)
> >         at
> >
> org.apache.felix.ipojo.InstanceCreator$ManagedInstance.create(InstanceCreator.java:
> > 355)
> >         at
> >
> org.apache.felix.ipojo.InstanceCreator.addInstance(InstanceCreator.java:89)
> >         at org.apache.felix.ipojo.Extender.parse(Extender.java:306)
> >         at
> > org.apache.felix.ipojo.Extender.startManagementFor(Extender.java:237)
> >         at org.apache.felix.ipojo.Extender.access$600(Extender.java:52)
> >         at
> org.apache.felix.ipojo.Extender$CreatorThread.run(Extender.java:
> > 769)
> >         at java.lang.Thread.run(Thread.java:722)
> >
> > If I remove the BundleContext constructor parameter then the UserService
> is
> > injected and the DefaultPersonService
> > is valid.
> >
> > I have tested this against the latest trunk code at:
> > https://svn.apache.org/repos/asf/felix/trunk/ipojo/
> >
> > I thought it could be related to the following fix:
> > https://issues.apache.org/jira/browse/FELIX-3576
> >
> > Could this be a bug?
> >
> > Thanks!
> > Anthony Bargnesi
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
> For additional commands, e-mail: users-help@felix.apache.org
>
>

Re: (iPOJO) NPE when injecting BundleContext and @Requires in constructor

Posted by Clement Escoffier <cl...@gmail.com>.
Hi,

It looks definitely related to FELIX-3576. Could you re-open the issue. I will have a look.

Regards,

Clement

On 16 oct. 2012, at 22:46, Anthony Bargnesi <ab...@gmail.com> wrote:

> Hi folks,
> 
> I have an iPOJO service component that takes two constructor parameters:
>  - BundleContext
>  - another service with @Requires
> 
> My scenario is similar to the following contrived example:
> 
> @Component
> @Provides
> @Instantiate
> public class DefaultUserService implements UserService {
>     ...
> }
> 
> @Component
> @Provides
> @Instantiate
> public class DefaultPersonService extends ObjectService implements
> PersonService {
> 
>     private final BundleContext ctx;
> 
>     public DefaultPersonService(BundleContext ctx,
>         @Requires(nullable = false, proxy = false)
> UserService userService) {
> 
>         super(userService);
>         this.ctx = ctx;
>     }
> }
> 
> In my example I require ObjectService to be instantiated with the
> UserService so it must
> be a constructor parameter.
> 
> I found that if I also want BundleContext to be injected then I receive the
> following
> NullPointerException:
> 
> [2012-10-16 16:11:11.886] ERROR iLogServiceListener@65284069
> org.osgi.service.log.LogService
> Bundle person.impl_0.1.0, [ERROR] person.impl.DefaultPersonService : null
> java.lang.NullPointerException: null
>         at
> org.apache.felix.ipojo.InstanceManager.handleBCInjections(InstanceManager.java:
> 253)
>         at
> org.apache.felix.ipojo.InstanceManager.configure(InstanceManager.java:207)
>         at
> org.apache.felix.ipojo.ComponentFactory.createInstance(ComponentFactory.java:
> 178)
>         at
> org.apache.felix.ipojo.IPojoFactory.createComponentInstance(IPojoFactory.java:
> 310)
>         at
> org.apache.felix.ipojo.IPojoFactory.createComponentInstance(IPojoFactory.java:
> 239)
>         at
> org.apache.felix.ipojo.InstanceCreator$ManagedInstance.create(InstanceCreator.java:
> 355)
>         at
> org.apache.felix.ipojo.InstanceCreator.addInstance(InstanceCreator.java:89)
>         at org.apache.felix.ipojo.Extender.parse(Extender.java:306)
>         at
> org.apache.felix.ipojo.Extender.startManagementFor(Extender.java:237)
>         at org.apache.felix.ipojo.Extender.access$600(Extender.java:52)
>         at org.apache.felix.ipojo.Extender$CreatorThread.run(Extender.java:
> 769)
>         at java.lang.Thread.run(Thread.java:722)
> 
> If I remove the BundleContext constructor parameter then the UserService is
> injected and the DefaultPersonService
> is valid.
> 
> I have tested this against the latest trunk code at:
> https://svn.apache.org/repos/asf/felix/trunk/ipojo/
> 
> I thought it could be related to the following fix:
> https://issues.apache.org/jira/browse/FELIX-3576
> 
> Could this be a bug?
> 
> Thanks!
> Anthony Bargnesi


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
For additional commands, e-mail: users-help@felix.apache.org