You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@felix.apache.org by "Robert Lillack (Reopened) (JIRA)" <ji...@apache.org> on 2011/10/06 17:39:30 UTC

[jira] [Reopened] (FELIX-2981) Unable to remove configuration properties using iPOJO's configuration handler

     [ https://issues.apache.org/jira/browse/FELIX-2981?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Robert Lillack reopened FELIX-2981:
-----------------------------------


It seems like I introduced a bug here, upon creation of an instance without configuration an unnecessary REconfiguration takes place, which breaks:

[ERROR]  : Cannot call the updated method : null 
java.lang.NullPointerException
        at java.util.Hashtable.put(Hashtable.java:394)
        at org.apache.felix.ipojo.handlers.configuration.ConfigurationHandler.__notifyUpdated(ConfigurationHandler.java:551)
        at org.apache.felix.ipojo.handlers.configuration.ConfigurationHandler.notifyUpdated(ConfigurationHandler.java)
        at org.apache.felix.ipojo.handlers.configuration.ConfigurationHandler.__onCreation(ConfigurationHandler.java:510)
        at org.apache.felix.ipojo.handlers.configuration.ConfigurationHandler.onCreation(ConfigurationHandler.java)

The culprit is, that defaultValue() will return a real _injectable_ value which in turn is then fed into setValue() because equality cannot be checked anymore in reconfigureProperty(). I therefore propose the application of a second patch which fixes this behavior.
                
> Unable to remove configuration properties using iPOJO's configuration handler
> -----------------------------------------------------------------------------
>
>                 Key: FELIX-2981
>                 URL: https://issues.apache.org/jira/browse/FELIX-2981
>             Project: Felix
>          Issue Type: Bug
>          Components: iPOJO
>    Affects Versions: iPOJO-1.8.0
>         Environment: * Apache Felix Bundle Repository (1.6.0)
> * Apache Felix Configuration Admin Service (1.2.8)
> * Apache Felix Gogo Runtime (0.8.0)
> * Apache Felix iPOJO (1.8.0)
> * Apache Felix iPOJO Annotations (1.8.0)
> * iPOJO Metadata (1.4.0)
> * Apache Felix Preferences Service (1.0.4)
>            Reporter: Robert Lillack
>            Assignee: Clement Escoffier
>            Priority: Minor
>             Fix For: ipojo-core-1.8.2
>
>         Attachments: felix-2981-2.patch, felix-2981.patch
>
>
> Hi,
> using iPOJO's _very nice_ OSGi Configuration Admin integration I sadly seem unable to remove any properties from a configuration to "reset" this property back to it's default value. Comparing the following two classes---one using iPOJO the other one directly implementing the ManagedService interface ...
> @Component(managedservice = "example1")
> @Instantiate
> public class Example1 {
>     
>     @Property
>     private String key;
>     
>     @Updated
>     private void updated() {
>         System.out.format("example1 = %s\n", key);
>     }
> }
> @Component
> @Instantiate
> public class Example2 implements ManagedService {
>     BundleContext ctx;
>     
>     public Example2(BundleContext c) {
>         ctx = c;
>     }
>     
>     @Validate
>     public void start() {
>         ctx.registerService(ManagedService.class.getName(), this, getDefaults());
>     }
>     private Hashtable getDefaults() {
>         Hashtable defaults = new Hashtable();
>         defaults.put(Constants.SERVICE_PID, "example2");
>         return defaults;
>     }
>     @Override
>     public void updated(Dictionary properties) throws ConfigurationException {
>         System.out.format("example2 = %s\n", properties == null ? null : properties.get("key"));
>     }
> }
> ... with the code setting the properties looking like this ...
>     public void set(String value) throws Exception {
>         setProperty("example1", value);
>         setProperty("example2", value);
>     }
>     
>     public void unset() throws Exception {
>         setProperty("example1", null);
>         setProperty("example2", null);
>     }
>     
>     private void setProperty(String srv, String value) throws IOException {
>         Configuration cfg = configAdmin.getConfiguration(srv, null); 
>         Dictionary p = cfg.getProperties();
>         if (p == null) {
>             p = new Properties();
>         }
>         
>         if (value == null) {
>             p.remove("key");
>         } else {
>             p.put("key", value);
>         }
>         cfg.update(p);
>     }
> ... these are the results after calling set("qsdasdasd") followed by unset():
> example1 = qsdasdasd
> example2 = qsdasdasd
> example1 = qsdasdasd
> example2 = null
> Am I using iPOJO the wrong way here? Thanks!

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira