[ 
https://issues.apache.org/jira/browse/FELIX-4384?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13903036#comment-13903036
 ] 

Sander Mak edited comment on FELIX-4384 at 2/17/14 8:04 AM:
------------------------------------------------------------

Indeed, non-static inner-classes have a constructor that takes a reference to 
the outer class. Therefore the behavior in Jago's code seems correct and 
expected to me. Changing the A and S1 class to static inner-classes should 
solve this, right?

Special-casing the post-hoc instantiation of non-static inner-classes within DM 
sounds like a hack to me. Especially since DM already offers component 
registration based on an instance rather than by reflection like Marcel pointed 
out.


was (Author: sandermak):
Indeed, non-static inner-classes have a constructor that takes a reference to 
the outer class. Therefore the behavior in Jago's code seems correct and 
expected to me. Changing the A and S1 class to static inner-classes should 
solve this, right? 

> Difference between inner class and normal class service
> -------------------------------------------------------
>
>                 Key: FELIX-4384
>                 URL: https://issues.apache.org/jira/browse/FELIX-4384
>             Project: Felix
>          Issue Type: Bug
>          Components: Dependency Manager
>    Affects Versions: dependencymanager-3.1.0
>            Reporter: Jago de Vreede
>            Priority: Minor
>
> Given the following code:
> package org.example;
> import org.apache.felix.dm.DependencyActivatorBase;
> import org.apache.felix.dm.DependencyManager;
> import org.osgi.framework.BundleContext;
> public class Activator extends DependencyActivatorBase {
>     @Override
>     public synchronized void init(BundleContext context, DependencyManager 
> manager) throws Exception {
>         manager.add(createComponent()
>             .setInterface(A.class.getName(), null)
>             .setImplementation(A.class)
>             
> .add(createServiceDependency().setService(S.class).setRequired(true)));
>         
>         manager.add(createComponent()
>             .setInterface(S.class.getName(), null)
>             .setImplementation(S1.class));
>     }
>     @Override
>     public synchronized void destroy(BundleContext context, DependencyManager 
> manager) throws Exception {}
>     
>     interface S {}
>     class A {}
>     class S1 implements S {}
> }
> dm will print out:
> g! dm
> [8] mytest
>  [0] org.example.Activator$A unregistered
>     org.example.Activator$S service required unavailable
>  [1] org.example.Activator$S registered
> But when the class S1 is promoted to a real class, dm will print out:
> g! dm
> [8] mytest
>  [0] org.example.Activator$A registered
>     org.example.Activator$S service required available
>  [1] org.example.Activator$S registered
> So the service class S1 is not available if its an inner class but is 
> available if its a normal class.



--
This message was sent by Atlassian JIRA
(v6.1.5#6160)

Reply via email to