[jira] [Commented] (FELIX-4455) Missing default constructor creates invalid class instances
[ https://issues.apache.org/jira/browse/FELIX-4455?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanelfocusedCommentId=13933001#comment-13933001 ] Benjamin Debeerst commented on FELIX-4455: -- Yes, I recompiled with {{mvn clean package}} each time. I used manipulator version 1.11.1 (maven plugin), but the same also happenend for 1.10.1. The project on GitHub is a proper maven project, so it should be possible to simply build and run it. Missing default constructor creates invalid class instances --- Key: FELIX-4455 URL: https://issues.apache.org/jira/browse/FELIX-4455 Project: Felix Issue Type: Bug Components: iPOJO Affects Versions: ipojo-manipulator-1.10.1, ipojo-manipulator-1.11.1 Reporter: Benjamin Debeerst Consider the following component definition: @Component @Instantiate public class ComponentWithoutDefaultConstructor { private Object internal = new Object(); @Property private String property; /* Constructor for unit tests */ public ComponentWithoutDefaultConstructor(String property) { System.out.println(Non-default constructor call!); this.property = property; } @Validate public void activate() { System.out.println(ComponentWithoutDefaultConstructor: activating!); System.out.println(this.internal); } } As per definition, I would expect every instance of this class to have a non-null member {{internal}} at class creation. This is all fine for my unit tests in a non-OSGi environment. However, having this processes by iPOJO and putting this in an OSGi container, the component outputs ComponentWithoutDefaultConstructor: activating! null The existing non-default constructor is not called, while it seems that a separate constructor has been created that does non instantiate the member variable. If I extend the code by an empty default constructor, that one is called and all works perfectly fine. I have no idea how iPOJO creates the object instance anyways, as it should not be possible to create such an invalid object instance. I don't know much about the reflection APIs or byte code manipulation though. I have put a sample maven project on GitHub[1], which can be built and droppped into a fresh Karaf container + iPOJO, which shows the problem. If there is no constructor iPOJO can use, I would expect iPOJO to either A) throw a warning/error (and build or runtime) and fail to instantiate the component or B) synthesize the default constructor properly, including the implicit instantiation of member variables. I encountered this problem both with iPOJO 1.10.1 and 1.11.1. [1] https://github.com/BenjaminDebeerst/ipojo-component-constructor-sample -- This message was sent by Atlassian JIRA (v6.2#6252)
[jira] [Commented] (FELIX-4455) Missing default constructor creates invalid class instances
[ https://issues.apache.org/jira/browse/FELIX-4455?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanelfocusedCommentId=13933018#comment-13933018 ] Guillaume Sauthier commented on FELIX-4455: --- Hi Benjamin, what do you expect from iPOJO ? * A clean error message stating that you need a manageable (callable from the container) constructor ? * iPOJO to work with this constructor scheme ? AFAICT, option 2 is not workable (except if you use the {{{@Property}}} on the parameter): any container (not only iPOJO) will have the same issue. What you could try is to have a default constructor (no params) that call the parametered constructor. Missing default constructor creates invalid class instances --- Key: FELIX-4455 URL: https://issues.apache.org/jira/browse/FELIX-4455 Project: Felix Issue Type: Bug Components: iPOJO Affects Versions: ipojo-manipulator-1.10.1, ipojo-manipulator-1.11.1 Reporter: Benjamin Debeerst Consider the following component definition: @Component @Instantiate public class ComponentWithoutDefaultConstructor { private Object internal = new Object(); @Property private String property; /* Constructor for unit tests */ public ComponentWithoutDefaultConstructor(String property) { System.out.println(Non-default constructor call!); this.property = property; } @Validate public void activate() { System.out.println(ComponentWithoutDefaultConstructor: activating!); System.out.println(this.internal); } } As per definition, I would expect every instance of this class to have a non-null member {{internal}} at class creation. This is all fine for my unit tests in a non-OSGi environment. However, having this processes by iPOJO and putting this in an OSGi container, the component outputs ComponentWithoutDefaultConstructor: activating! null The existing non-default constructor is not called, while it seems that a separate constructor has been created that does non instantiate the member variable. If I extend the code by an empty default constructor, that one is called and all works perfectly fine. I have no idea how iPOJO creates the object instance anyways, as it should not be possible to create such an invalid object instance. I don't know much about the reflection APIs or byte code manipulation though. I have put a sample maven project on GitHub[1], which can be built and droppped into a fresh Karaf container + iPOJO, which shows the problem. If there is no constructor iPOJO can use, I would expect iPOJO to either A) throw a warning/error (and build or runtime) and fail to instantiate the component or B) synthesize the default constructor properly, including the implicit instantiation of member variables. I encountered this problem both with iPOJO 1.10.1 and 1.11.1. [1] https://github.com/BenjaminDebeerst/ipojo-component-constructor-sample -- This message was sent by Atlassian JIRA (v6.2#6252)
[jira] [Commented] (FELIX-4455) Missing default constructor creates invalid class instances
[ https://issues.apache.org/jira/browse/FELIX-4455?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanelfocusedCommentId=13933073#comment-13933073 ] Benjamin Debeerst commented on FELIX-4455: -- I would expected iPOJO to do either of the following: # Raise an error (preferrably at manipulation/compile time), that a required (default) constructor is missing to perform field injection of properties and referenced services # Generate the default constructor, but _without skipping field instantiation_. The last part is the most important thing. I implemented a component with an internal field, carefully making sure that field can never be null - among others by instantiating at declaration. But then I throw the component into the runtime and at once get unexpected NPEs, because in some unknown way, iPOJO instantiated the class but not it's fields. If I define a class like this: {code} @Component public class MyClass { private String internal = Default; } {code} I expect that any fresh class instance has a non-null {{internal}} field - provided the constructor does not overwrite the default value. Missing default constructor creates invalid class instances --- Key: FELIX-4455 URL: https://issues.apache.org/jira/browse/FELIX-4455 Project: Felix Issue Type: Bug Components: iPOJO Affects Versions: ipojo-manipulator-1.10.1, ipojo-manipulator-1.11.1 Reporter: Benjamin Debeerst Consider the following component definition: @Component @Instantiate public class ComponentWithoutDefaultConstructor { private Object internal = new Object(); @Property private String property; /* Constructor for unit tests */ public ComponentWithoutDefaultConstructor(String property) { System.out.println(Non-default constructor call!); this.property = property; } @Validate public void activate() { System.out.println(ComponentWithoutDefaultConstructor: activating!); System.out.println(this.internal); } } As per definition, I would expect every instance of this class to have a non-null member {{internal}} at class creation. This is all fine for my unit tests in a non-OSGi environment. However, having this processes by iPOJO and putting this in an OSGi container, the component outputs ComponentWithoutDefaultConstructor: activating! null The existing non-default constructor is not called, while it seems that a separate constructor has been created that does non instantiate the member variable. If I extend the code by an empty default constructor, that one is called and all works perfectly fine. I have no idea how iPOJO creates the object instance anyways, as it should not be possible to create such an invalid object instance. I don't know much about the reflection APIs or byte code manipulation though. I have put a sample maven project on GitHub[1], which can be built and droppped into a fresh Karaf container + iPOJO, which shows the problem. If there is no constructor iPOJO can use, I would expect iPOJO to either A) throw a warning/error (and build or runtime) and fail to instantiate the component or B) synthesize the default constructor properly, including the implicit instantiation of member variables. I encountered this problem both with iPOJO 1.10.1 and 1.11.1. [1] https://github.com/BenjaminDebeerst/ipojo-component-constructor-sample -- This message was sent by Atlassian JIRA (v6.2#6252)
[jira] [Commented] (FELIX-4455) Missing default constructor creates invalid class instances
[ https://issues.apache.org/jira/browse/FELIX-4455?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanelfocusedCommentId=13933101#comment-13933101 ] Guillaume Sauthier commented on FELIX-4455: --- Ok understood From the iPOJO point of view, your component is invalid because it miss a manageable constructor. I think that iPOJO should complain with an understandable error message :) I'm not sure it's a good practice to generate a default constructor for the user if he (maybe intentionally) omit it. It make things harder to debug because, you'll assume that what is executed is your code where in fact, iPOJO is doing its own stuff. What you see is a side effect of the ipojo manipulation: because it does not stop if no manageable constructor is found, it process the class as usual: build a new default constructor from scratch, and doing this, it miss the assignment. This is because, in bytecode, the assignment is done in the constructor, so if you generate one (instead of modifying one that contains the instruction), you won't have the assignment for free... Missing default constructor creates invalid class instances --- Key: FELIX-4455 URL: https://issues.apache.org/jira/browse/FELIX-4455 Project: Felix Issue Type: Bug Components: iPOJO Affects Versions: ipojo-manipulator-1.10.1, ipojo-manipulator-1.11.1 Reporter: Benjamin Debeerst Consider the following component definition: @Component @Instantiate public class ComponentWithoutDefaultConstructor { private Object internal = new Object(); @Property private String property; /* Constructor for unit tests */ public ComponentWithoutDefaultConstructor(String property) { System.out.println(Non-default constructor call!); this.property = property; } @Validate public void activate() { System.out.println(ComponentWithoutDefaultConstructor: activating!); System.out.println(this.internal); } } As per definition, I would expect every instance of this class to have a non-null member {{internal}} at class creation. This is all fine for my unit tests in a non-OSGi environment. However, having this processes by iPOJO and putting this in an OSGi container, the component outputs ComponentWithoutDefaultConstructor: activating! null The existing non-default constructor is not called, while it seems that a separate constructor has been created that does non instantiate the member variable. If I extend the code by an empty default constructor, that one is called and all works perfectly fine. I have no idea how iPOJO creates the object instance anyways, as it should not be possible to create such an invalid object instance. I don't know much about the reflection APIs or byte code manipulation though. I have put a sample maven project on GitHub[1], which can be built and droppped into a fresh Karaf container + iPOJO, which shows the problem. If there is no constructor iPOJO can use, I would expect iPOJO to either A) throw a warning/error (and build or runtime) and fail to instantiate the component or B) synthesize the default constructor properly, including the implicit instantiation of member variables. I encountered this problem both with iPOJO 1.10.1 and 1.11.1. [1] https://github.com/BenjaminDebeerst/ipojo-component-constructor-sample -- This message was sent by Atlassian JIRA (v6.2#6252)
[jira] [Commented] (FELIX-4455) Missing default constructor creates invalid class instances
[ https://issues.apache.org/jira/browse/FELIX-4455?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanelfocusedCommentId=13933190#comment-13933190 ] Benjamin Debeerst commented on FELIX-4455: -- I'm good with both solutions. But: {quote} it processes the class as usual: build a new default constructor from scratch, and doing this, it misses the assignment {quote} Isn't this wrong for the usual case as well? I think it should definitely consider default assignments of fields whenever constructors are generated. Missing default constructor creates invalid class instances --- Key: FELIX-4455 URL: https://issues.apache.org/jira/browse/FELIX-4455 Project: Felix Issue Type: Bug Components: iPOJO Affects Versions: ipojo-manipulator-1.10.1, ipojo-manipulator-1.11.1 Reporter: Benjamin Debeerst Consider the following component definition: @Component @Instantiate public class ComponentWithoutDefaultConstructor { private Object internal = new Object(); @Property private String property; /* Constructor for unit tests */ public ComponentWithoutDefaultConstructor(String property) { System.out.println(Non-default constructor call!); this.property = property; } @Validate public void activate() { System.out.println(ComponentWithoutDefaultConstructor: activating!); System.out.println(this.internal); } } As per definition, I would expect every instance of this class to have a non-null member {{internal}} at class creation. This is all fine for my unit tests in a non-OSGi environment. However, having this processes by iPOJO and putting this in an OSGi container, the component outputs ComponentWithoutDefaultConstructor: activating! null The existing non-default constructor is not called, while it seems that a separate constructor has been created that does non instantiate the member variable. If I extend the code by an empty default constructor, that one is called and all works perfectly fine. I have no idea how iPOJO creates the object instance anyways, as it should not be possible to create such an invalid object instance. I don't know much about the reflection APIs or byte code manipulation though. I have put a sample maven project on GitHub[1], which can be built and droppped into a fresh Karaf container + iPOJO, which shows the problem. If there is no constructor iPOJO can use, I would expect iPOJO to either A) throw a warning/error (and build or runtime) and fail to instantiate the component or B) synthesize the default constructor properly, including the implicit instantiation of member variables. I encountered this problem both with iPOJO 1.10.1 and 1.11.1. [1] https://github.com/BenjaminDebeerst/ipojo-component-constructor-sample -- This message was sent by Atlassian JIRA (v6.2#6252)
[jira] [Commented] (FELIX-4455) Missing default constructor creates invalid class instances
[ https://issues.apache.org/jira/browse/FELIX-4455?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanelfocusedCommentId=13933211#comment-13933211 ] Guillaume Sauthier commented on FELIX-4455: --- As I said, default field assignment is done in the constructor, not outside of it in the bytecode. That means that for your component example, the compiled bytecode looks like this: {code:java} @Component public class MyClass { private String internal; public MyClass() { internal = Default; } }{code} So, in this case, iPOJO modifies a correct constructor. What you miss is that, once you defined your own constructor, there is no more the default one available in the bytecode. Missing default constructor creates invalid class instances --- Key: FELIX-4455 URL: https://issues.apache.org/jira/browse/FELIX-4455 Project: Felix Issue Type: Bug Components: iPOJO Affects Versions: ipojo-manipulator-1.10.1, ipojo-manipulator-1.11.1 Reporter: Benjamin Debeerst Consider the following component definition: @Component @Instantiate public class ComponentWithoutDefaultConstructor { private Object internal = new Object(); @Property private String property; /* Constructor for unit tests */ public ComponentWithoutDefaultConstructor(String property) { System.out.println(Non-default constructor call!); this.property = property; } @Validate public void activate() { System.out.println(ComponentWithoutDefaultConstructor: activating!); System.out.println(this.internal); } } As per definition, I would expect every instance of this class to have a non-null member {{internal}} at class creation. This is all fine for my unit tests in a non-OSGi environment. However, having this processes by iPOJO and putting this in an OSGi container, the component outputs ComponentWithoutDefaultConstructor: activating! null The existing non-default constructor is not called, while it seems that a separate constructor has been created that does non instantiate the member variable. If I extend the code by an empty default constructor, that one is called and all works perfectly fine. I have no idea how iPOJO creates the object instance anyways, as it should not be possible to create such an invalid object instance. I don't know much about the reflection APIs or byte code manipulation though. I have put a sample maven project on GitHub[1], which can be built and droppped into a fresh Karaf container + iPOJO, which shows the problem. If there is no constructor iPOJO can use, I would expect iPOJO to either A) throw a warning/error (and build or runtime) and fail to instantiate the component or B) synthesize the default constructor properly, including the implicit instantiation of member variables. I encountered this problem both with iPOJO 1.10.1 and 1.11.1. [1] https://github.com/BenjaminDebeerst/ipojo-component-constructor-sample -- This message was sent by Atlassian JIRA (v6.2#6252)
[jira] [Commented] (FELIX-4455) Missing default constructor creates invalid class instances
[ https://issues.apache.org/jira/browse/FELIX-4455?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanelfocusedCommentId=13933359#comment-13933359 ] Benjamin Debeerst commented on FELIX-4455: -- Okay, I understand. Missing default constructor creates invalid class instances --- Key: FELIX-4455 URL: https://issues.apache.org/jira/browse/FELIX-4455 Project: Felix Issue Type: Bug Components: iPOJO Affects Versions: ipojo-manipulator-1.10.1, ipojo-manipulator-1.11.1 Reporter: Benjamin Debeerst Consider the following component definition: @Component @Instantiate public class ComponentWithoutDefaultConstructor { private Object internal = new Object(); @Property private String property; /* Constructor for unit tests */ public ComponentWithoutDefaultConstructor(String property) { System.out.println(Non-default constructor call!); this.property = property; } @Validate public void activate() { System.out.println(ComponentWithoutDefaultConstructor: activating!); System.out.println(this.internal); } } As per definition, I would expect every instance of this class to have a non-null member {{internal}} at class creation. This is all fine for my unit tests in a non-OSGi environment. However, having this processes by iPOJO and putting this in an OSGi container, the component outputs ComponentWithoutDefaultConstructor: activating! null The existing non-default constructor is not called, while it seems that a separate constructor has been created that does non instantiate the member variable. If I extend the code by an empty default constructor, that one is called and all works perfectly fine. I have no idea how iPOJO creates the object instance anyways, as it should not be possible to create such an invalid object instance. I don't know much about the reflection APIs or byte code manipulation though. I have put a sample maven project on GitHub[1], which can be built and droppped into a fresh Karaf container + iPOJO, which shows the problem. If there is no constructor iPOJO can use, I would expect iPOJO to either A) throw a warning/error (and build or runtime) and fail to instantiate the component or B) synthesize the default constructor properly, including the implicit instantiation of member variables. I encountered this problem both with iPOJO 1.10.1 and 1.11.1. [1] https://github.com/BenjaminDebeerst/ipojo-component-constructor-sample -- This message was sent by Atlassian JIRA (v6.2#6252)
[jira] [Commented] (FELIX-4455) Missing default constructor creates invalid class instances
[ https://issues.apache.org/jira/browse/FELIX-4455?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanelfocusedCommentId=13931583#comment-13931583 ] Benjamin Debeerst commented on FELIX-4455: -- Then I get {{createInstance - Cannot invoke the constructor (method not found)}} and {{Cannot create a POJO instance, the POJO constructor cannot be found}}. Full stack: {code} 2014-03-12 10:38:51,156 | ERROR | pool-1-thread-1 | ipojo-constructor | 91 - com.example.ipojo-constructor - 1.0.0.SNAPSHOT | [ERROR] : [com.example.ComponentWithoutDefaultConstructor-0] createInstance - Cannot invoke the constructor (method not found) : com.example.ComponentWithoutDefaultConstructor.init(org.apache.felix.ipojo.InstanceManager, null) java.lang.NoSuchMethodException: com.example.ComponentWithoutDefaultConstructor.init(org.apache.felix.ipojo.InstanceManager, null) at java.lang.Class.getConstructor0(Class.java:2800)[:1.7.0_25] at java.lang.Class.getDeclaredConstructor(Class.java:2043)[:1.7.0_25] at org.apache.felix.ipojo.InstanceManager.createObject(InstanceManager.java:703)[84:org.apache.felix.ipojo:1.11.1] at org.apache.felix.ipojo.InstanceManager.getPojoObject(InstanceManager.java:923)[84:org.apache.felix.ipojo:1.11.1] at org.apache.felix.ipojo.handlers.lifecycle.callback.LifecycleCallbackHandler.__M_stateChanged(LifecycleCallbackHandler.java:156)[84:org.apache.felix.ipojo:1.11.1] at org.apache.felix.ipojo.handlers.lifecycle.callback.LifecycleCallbackHandler.stateChanged(LifecycleCallbackHandler.java)[84:org.apache.felix.ipojo:1.11.1] at org.apache.felix.ipojo.InstanceManager.setState(InstanceManager.java:536)[84:org.apache.felix.ipojo:1.11.1] at org.apache.felix.ipojo.InstanceManager.start(InstanceManager.java:418)[84:org.apache.felix.ipojo:1.11.1] at org.apache.felix.ipojo.ComponentFactory.createInstance(ComponentFactory.java:179)[84:org.apache.felix.ipojo:1.11.1] at org.apache.felix.ipojo.IPojoFactory.createComponentInstance(IPojoFactory.java:319)[84:org.apache.felix.ipojo:1.11.1] at org.apache.felix.ipojo.IPojoFactory.createComponentInstance(IPojoFactory.java:240)[84:org.apache.felix.ipojo:1.11.1] at org.apache.felix.ipojo.extender.internal.linker.ManagedType$InstanceSupport$1.call(ManagedType.java:312)[84:org.apache.felix.ipojo:1.11.1] at org.apache.felix.ipojo.extender.internal.linker.ManagedType$InstanceSupport$1.call(ManagedType.java:306)[84:org.apache.felix.ipojo:1.11.1] at org.apache.felix.ipojo.extender.internal.queue.JobInfoCallable.call(JobInfoCallable.java:114 [84:org.apache.felix.ipojo:1.11.1] at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)[:1.7.0_25] at java.util.concurrent.FutureTask.run(FutureTask.java:166)[:1.7.0_25] at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)[:1.7.0_25] at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)[:1.7.0_25] at java.lang.Thread.run(Thread.java:724)[:1.7.0_25] 2014-03-12 10:38:51,156 | ERROR | pool-1-thread-1 | ipojo-constructor | 91 - com.example.ipojo-constructor -1.0.0.SNAPSHOT | [ERROR] com.example.ComponentWithoutDefaultConstructor : Cannot create a POJO instance, the POJO constructor cannot be found {code} Missing default constructor creates invalid class instances --- Key: FELIX-4455 URL: https://issues.apache.org/jira/browse/FELIX-4455 Project: Felix Issue Type: Bug Components: iPOJO Affects Versions: ipojo-manipulator-1.10.1, ipojo-manipulator-1.11.1 Reporter: Benjamin Debeerst Consider the following component definition: @Component @Instantiate public class ComponentWithoutDefaultConstructor { private Object internal = new Object(); @Property private String property; /* Constructor for unit tests */ public ComponentWithoutDefaultConstructor(String property) { System.out.println(Non-default constructor call!); this.property = property; } @Validate public void activate() { System.out.println(ComponentWithoutDefaultConstructor: activating!); System.out.println(this.internal); } } As per definition, I would expect every instance of this class to have a non-null member {{internal}} at class creation. This is all fine for my unit tests in a non-OSGi environment. However, having this processes by iPOJO and putting this in an OSGi container, the component outputs ComponentWithoutDefaultConstructor: activating! null The existing non-default constructor is not called, while it seems that a separate constructor has been created that does non instantiate the member
[jira] [Commented] (FELIX-4455) Missing default constructor creates invalid class instances
[ https://issues.apache.org/jira/browse/FELIX-4455?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanelfocusedCommentId=13932169#comment-13932169 ] Clement Escoffier commented on FELIX-4455: -- Did you recompile the bundle in between ? Could you also tell me which version of the manipulator (ant task or maven plugin) are you using ? Missing default constructor creates invalid class instances --- Key: FELIX-4455 URL: https://issues.apache.org/jira/browse/FELIX-4455 Project: Felix Issue Type: Bug Components: iPOJO Affects Versions: ipojo-manipulator-1.10.1, ipojo-manipulator-1.11.1 Reporter: Benjamin Debeerst Consider the following component definition: @Component @Instantiate public class ComponentWithoutDefaultConstructor { private Object internal = new Object(); @Property private String property; /* Constructor for unit tests */ public ComponentWithoutDefaultConstructor(String property) { System.out.println(Non-default constructor call!); this.property = property; } @Validate public void activate() { System.out.println(ComponentWithoutDefaultConstructor: activating!); System.out.println(this.internal); } } As per definition, I would expect every instance of this class to have a non-null member {{internal}} at class creation. This is all fine for my unit tests in a non-OSGi environment. However, having this processes by iPOJO and putting this in an OSGi container, the component outputs ComponentWithoutDefaultConstructor: activating! null The existing non-default constructor is not called, while it seems that a separate constructor has been created that does non instantiate the member variable. If I extend the code by an empty default constructor, that one is called and all works perfectly fine. I have no idea how iPOJO creates the object instance anyways, as it should not be possible to create such an invalid object instance. I don't know much about the reflection APIs or byte code manipulation though. I have put a sample maven project on GitHub[1], which can be built and droppped into a fresh Karaf container + iPOJO, which shows the problem. If there is no constructor iPOJO can use, I would expect iPOJO to either A) throw a warning/error (and build or runtime) and fail to instantiate the component or B) synthesize the default constructor properly, including the implicit instantiation of member variables. I encountered this problem both with iPOJO 1.10.1 and 1.11.1. [1] https://github.com/BenjaminDebeerst/ipojo-component-constructor-sample -- This message was sent by Atlassian JIRA (v6.2#6252)
[jira] [Commented] (FELIX-4455) Missing default constructor creates invalid class instances
[ https://issues.apache.org/jira/browse/FELIX-4455?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanelfocusedCommentId=13930181#comment-13930181 ] Clement Escoffier commented on FELIX-4455: -- Could you try with: {code} public ComponentWithoutDefaultConstructor(@Property(name=property) String property) { System.out.println(Non-default constructor call!); this.property = property; } {code} Missing default constructor creates invalid class instances --- Key: FELIX-4455 URL: https://issues.apache.org/jira/browse/FELIX-4455 Project: Felix Issue Type: Bug Components: iPOJO Affects Versions: ipojo-manipulator-1.10.1, ipojo-manipulator-1.11.1 Reporter: Benjamin Debeerst Consider the following component definition: @Component @Instantiate public class ComponentWithoutDefaultConstructor { private Object internal = new Object(); @Property private String property; /* Constructor for unit tests */ public ComponentWithoutDefaultConstructor(String property) { System.out.println(Non-default constructor call!); this.property = property; } @Validate public void activate() { System.out.println(ComponentWithoutDefaultConstructor: activating!); System.out.println(this.internal); } } As per definition, I would expect every instance of this class to have a non-null member {{internal}} at class creation. This is all fine for my unit tests in a non-OSGi environment. However, having this processes by iPOJO and putting this in an OSGi container, the component outputs ComponentWithoutDefaultConstructor: activating! null The existing non-default constructor is not called, while it seems that a separate constructor has been created that does non instantiate the member variable. If I extend the code by an empty default constructor, that one is called and all works perfectly fine. I have no idea how iPOJO creates the object instance anyways, as it should not be possible to create such an invalid object instance. I don't know much about the reflection APIs or byte code manipulation though. I have put a sample maven project on GitHub[1], which can be built and droppped into a fresh Karaf container + iPOJO, which shows the problem. If there is no constructor iPOJO can use, I would expect iPOJO to either A) throw a warning/error (and build or runtime) and fail to instantiate the component or B) synthesize the default constructor properly, including the implicit instantiation of member variables. I encountered this problem both with iPOJO 1.10.1 and 1.11.1. [1] https://github.com/BenjaminDebeerst/ipojo-component-constructor-sample -- This message was sent by Atlassian JIRA (v6.2#6252)