I am new to iPOJO. As part of learning the iPOJO framework I found the following problem.
I am publishing a service 'ServicePropertiesExample' with service property 'when' with initial/default value set to 0. This service property is attached to the field 'count'. When the filed 'count' is set to null, the service property 'when' is unpublished (as in the iPOJO Documentation at http://felix.apache.org/documentation/subprojects/apache-felix-ipojo/apache-felix-ipojo-userguide/describing-components/providing-osgi-services.html)
But I am getting a NullPointerException
when a re-assignment is made to the field 'count' from value null
. I want re-publish this service property. How can this be done ?
@ServiceProperty(name = "when", value = "0")
private String count;
public ServicePropertiesExample() {
try {
SwingUtilities
.invokeAndWait(() -> {
panel = new JPanel();
JButton setPropertyValueTo1 = new JButton(
"Update Service Properties");
setPropertyValueTo1.addActionListener((e) -> {
count = String.valueOf(1);
});
JButton setPropertyValueToNull = new JButton("Set Property value to null");
setPropertyValueToNull.addActionListener((e)->{
System.out.println("Setting property value to null");
count = null;
});
panel.add(setPropertyValueTo1);
panel.add(setPropertyValueToNull);
});
} catch (InvocationTargetException | InterruptedException e) {
e.printStackTrace();
}
}
Here's the exception:
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at org.apache.felix.ipojo.handlers.providedservice.ProvidedServiceHandler.__M_onSet(ProvidedServiceHandler.java:417)
at org.apache.felix.ipojo.handlers.providedservice.ProvidedServiceHandler.onSet(ProvidedServiceHandler.java)
at org.apache.felix.ipojo.InstanceManager.onSet(InstanceManager.java:1401)
at com.steve.swing.components.ServicePropertiesExample.__setcount(ServicePropertiesExample.java)
at com.steve.swing.components.ServicePropertiesExample.__M_lambda$1(ServicePropertiesExample.java:49)
at com.steve.swing.components.ServicePropertiesExample.lambda$1(ServicePropertiesExample.java)
at com.steve.swing.components.ServicePropertiesExample$$Lambda$3/2135247888.actionPerformed(Unknown Source)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2022)
....