Fix issue FELIX-2014
Inject null instead of the NO_VALUE object to avoid the class cast exception.
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@903739 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/providedservice/ProvidedServiceHandler.java b/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/providedservice/ProvidedServiceHandler.java
index 2b2861a..00cc4d2 100644
--- a/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/providedservice/ProvidedServiceHandler.java
+++ b/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/providedservice/ProvidedServiceHandler.java
@@ -412,8 +412,8 @@
for (int j = 0; j < svc.getProperties().length; j++) {
Property prop = svc.getProperties()[j];
if (fieldName.equals(prop.getField())) {
- // it is the associated property
- return prop.getValue();
+ // Manage the No Value case.
+ return prop.onGet(pojo, fieldName, value);
}
}
}
diff --git a/ipojo/tests/core/service-providing/src/main/java/org/apache/felix/ipojo/test/scenarios/component/NullCheckServiceProvider.java b/ipojo/tests/core/service-providing/src/main/java/org/apache/felix/ipojo/test/scenarios/component/NullCheckServiceProvider.java
new file mode 100644
index 0000000..ee775b3
--- /dev/null
+++ b/ipojo/tests/core/service-providing/src/main/java/org/apache/felix/ipojo/test/scenarios/component/NullCheckServiceProvider.java
@@ -0,0 +1,57 @@
+package org.apache.felix.ipojo.test.scenarios.component;
+
+import java.util.Properties;
+
+import org.apache.felix.ipojo.test.scenarios.ps.service.FooService;
+
+public class NullCheckServiceProvider implements FooService {
+
+ private String prop1;
+ private String prop2;
+
+ public NullCheckServiceProvider() {
+ if (prop1 == null) {
+ prop2= "0";
+ }
+ }
+
+
+ public boolean foo() {
+ if (prop1 == null && prop2 != null) {
+ prop1 = "0";
+ prop2 = null;
+ return true;
+ }
+ if (prop2 == null && prop1 != null) {
+ prop1 = null;
+ prop2 = "0";
+ return true;
+ }
+ return false;
+ }
+
+ public Properties fooProps() {
+ return null;
+ }
+
+ public boolean getBoolean() {
+ return false;
+ }
+
+ public double getDouble() {
+ return 0;
+ }
+
+ public int getInt() {
+ return 0;
+ }
+
+ public long getLong() {
+ return 0;
+ }
+
+ public Boolean getObject() {
+ return null;
+ }
+
+}
diff --git a/ipojo/tests/core/service-providing/src/main/java/org/apache/felix/ipojo/test/scenarios/ps/NullCheck.java b/ipojo/tests/core/service-providing/src/main/java/org/apache/felix/ipojo/test/scenarios/ps/NullCheck.java
new file mode 100644
index 0000000..9466f33
--- /dev/null
+++ b/ipojo/tests/core/service-providing/src/main/java/org/apache/felix/ipojo/test/scenarios/ps/NullCheck.java
@@ -0,0 +1,77 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.ipojo.test.scenarios.ps;
+
+import org.apache.felix.ipojo.Factory;
+import org.apache.felix.ipojo.junit4osgi.OSGiTestCase;
+import org.apache.felix.ipojo.junit4osgi.helpers.IPOJOHelper;
+import org.apache.felix.ipojo.test.scenarios.ps.service.FooService;
+import org.osgi.framework.ServiceReference;
+
+public class NullCheck extends OSGiTestCase {
+
+ public void testNull() {
+ IPOJOHelper helper = new IPOJOHelper(this);
+
+ String factName = "PS-Null";
+ String compName = "NullCheck";
+ ServiceReference ref = null;
+
+ // Check that no Foo Service are available
+ ref = getServiceReference(FooService.class.getName());
+ assertNull("FS already available", ref);
+
+ // Get the factory to create a component instance
+ Factory fact = helper.getFactory(factName);
+ assertNotNull("Cannot find the factory FooProvider-1", fact);
+
+ // Don't give any configuration so, properties are null.
+ helper.createComponentInstance(factName, compName);
+
+ // Get a FooService provider
+ ref = getServiceReference(FooService.class.getName(), "(" + "instance.name" + "=" + compName + ")");
+
+ assertNotNull("FS not available", ref);
+
+ // Check service properties
+ assertNull(ref.getProperty("prop1"));
+ assertNotNull(ref.getProperty("prop2"));
+
+ // Test foo invocation
+ FooService fs = (FooService) getServiceObject(ref);
+ assertTrue("FooService invocation failed", fs.foo());
+
+ ref = getServiceReference(FooService.class.getName(), "(" + "instance.name" + "=" + compName + ")");
+ // Check service properties
+ assertNotNull(ref.getProperty("prop1"));
+ assertNull(ref.getProperty("prop2"));
+
+
+ helper.dispose();
+
+
+ // Check that there is no more FooService
+ ref = getServiceReference(FooService.class.getName(), null);
+
+
+ assertNull("FS available, but component instance stopped", ref);
+
+ }
+
+}
diff --git a/ipojo/tests/core/service-providing/src/main/java/org/apache/felix/ipojo/test/scenarios/ps/ProvidedServiceTestSuite.java b/ipojo/tests/core/service-providing/src/main/java/org/apache/felix/ipojo/test/scenarios/ps/ProvidedServiceTestSuite.java
index fc7f83f..720c46a 100644
--- a/ipojo/tests/core/service-providing/src/main/java/org/apache/felix/ipojo/test/scenarios/ps/ProvidedServiceTestSuite.java
+++ b/ipojo/tests/core/service-providing/src/main/java/org/apache/felix/ipojo/test/scenarios/ps/ProvidedServiceTestSuite.java
@@ -38,6 +38,7 @@
ots.addTestSuite(ProvidedServiceArchitectureTest.class);
ots.addTestSuite(ClassTest.class);
ots.addTestSuite(OSGiPropertiesTest.class);
+ ots.addTestSuite(NullCheck.class);
return ots;
}
diff --git a/ipojo/tests/core/service-providing/src/main/resources/metadata.xml b/ipojo/tests/core/service-providing/src/main/resources/metadata.xml
index 3e7c026..50c458d 100644
--- a/ipojo/tests/core/service-providing/src/main/resources/metadata.xml
+++ b/ipojo/tests/core/service-providing/src/main/resources/metadata.xml
@@ -3,160 +3,169 @@
xsi:schemaLocation="org.apache.felix.ipojo http://felix.apache.org/ipojo/schemas/SNAPSHOT/core.xsd"
xmlns="org.apache.felix.ipojo"
>
- <!-- Simple provider -->
- <component
- classname="org.apache.felix.ipojo.test.scenarios.component.FooProviderType1"
- name="PS-FooProviderType-1" architecture="true">
- <provides />
- </component>
-
- <component
- classname="org.apache.felix.ipojo.test.scenarios.component.FooProviderType1"
- name="PS-FooProviderType-itf" architecture="true">
- <provides
- specifications="org.apache.felix.ipojo.test.scenarios.ps.service.FooService" />
- </component>
-
- <component
- classname="org.apache.felix.ipojo.test.scenarios.component.FooProviderType1"
- name="PS-FooProviderType-3" architecture="true">
- <provides>
- <property name="foo" field="m_foo" />
- <property name="bar" field="m_bar" />
- <property name="baz" type="java.lang.String" />
- </provides>
- <properties propagation="true">
- <property name="foo" field="m_foo" />
- <property name="bar" field="m_bar" />
- </properties>
- </component>
-
- <!-- Providers providing 2 services -->
- <component
- classname="org.apache.felix.ipojo.test.scenarios.component.FooBarProviderType1"
- name="PS-FooBarProviderType-1" architecture="true">
- <provides />
- </component>
- <component
- classname="org.apache.felix.ipojo.test.scenarios.component.FooBarProviderType1"
- name="PS-FooBarProviderType-2" architecture="true">
- <provides
- specifications="{org.apache.felix.ipojo.test.scenarios.ps.service.FooService, org.apache.felix.ipojo.test.scenarios.ps.service.BarService }" />
- </component>
- <component
- classname="org.apache.felix.ipojo.test.scenarios.component.FooBarProviderType1"
- name="PS-FooBarProviderType-3" architecture="true">
- <provides
- specifications="{org.apache.felix.ipojo.test.scenarios.ps.service.FooService}">
- <property name="baz" type="java.lang.String" value="foo" />
- </provides>
- <provides
- specifications="{org.apache.felix.ipojo.test.scenarios.ps.service.BarService}">
- <property name="baz" type="java.lang.String" value="bar" />
- </provides>
- </component>
-
+ <!-- Simple provider -->
+ <component
+ classname="org.apache.felix.ipojo.test.scenarios.component.FooProviderType1"
+ name="PS-FooProviderType-1" architecture="true">
+ <provides />
+ </component>
+
+ <component
+ classname="org.apache.felix.ipojo.test.scenarios.component.FooProviderType1"
+ name="PS-FooProviderType-itf" architecture="true">
+ <provides
+ specifications="org.apache.felix.ipojo.test.scenarios.ps.service.FooService" />
+ </component>
+
+ <component
+ classname="org.apache.felix.ipojo.test.scenarios.component.FooProviderType1"
+ name="PS-FooProviderType-3" architecture="true">
+ <provides>
+ <property name="foo" field="m_foo" />
+ <property name="bar" field="m_bar" />
+ <property name="baz" type="java.lang.String" />
+ </provides>
+ <properties propagation="true">
+ <property name="foo" field="m_foo" />
+ <property name="bar" field="m_bar" />
+ </properties>
+ </component>
+
+ <!-- Providers providing 2 services -->
+ <component
+ classname="org.apache.felix.ipojo.test.scenarios.component.FooBarProviderType1"
+ name="PS-FooBarProviderType-1" architecture="true">
+ <provides />
+ </component>
+ <component
+ classname="org.apache.felix.ipojo.test.scenarios.component.FooBarProviderType1"
+ name="PS-FooBarProviderType-2" architecture="true">
+ <provides
+ specifications="{org.apache.felix.ipojo.test.scenarios.ps.service.FooService, org.apache.felix.ipojo.test.scenarios.ps.service.BarService }" />
+ </component>
+ <component
+ classname="org.apache.felix.ipojo.test.scenarios.component.FooBarProviderType1"
+ name="PS-FooBarProviderType-3" architecture="true">
+ <provides
+ specifications="{org.apache.felix.ipojo.test.scenarios.ps.service.FooService}">
+ <property name="baz" type="java.lang.String" value="foo" />
+ </provides>
+ <provides
+ specifications="{org.apache.felix.ipojo.test.scenarios.ps.service.BarService}">
+ <property name="baz" type="java.lang.String" value="bar" />
+ </provides>
+ </component>
+
- <!-- Provider with dynamic property -->
- <component
- classname="org.apache.felix.ipojo.test.scenarios.component.FooProviderTypeDyn"
- name="PS-FooProviderType-Dyn" architecture="true">
- <provides>
- <property name="int" field="intProp" value="2" />
- <property name="boolean" field="boolProp" value="false" />
- <property name="string" field="strProp" value="foo" />
- <property name="strAProp" field="strAProp"
- value="{foo, bar}" />
- <property name="intAProp" field="intAProp" value="{ 1,2,3}" />
- </provides>
- </component>
-
- <component
- classname="org.apache.felix.ipojo.test.scenarios.component.FooProviderType1"
- name="PS-FooProviderType-2" architecture="true">
- <provides>
- <property name="int" type="int" value="2" />
- <property name="long" type="long" value="40" />
- <property name="string" type="java.lang.String" value="foo" />
- <property name="strAProp" type="java.lang.String[]"
- value="{foo, bar}" />
- <property name="intAProp" type="int[]" value="{1,2,3}" />
- </provides>
- </component>
-
- <component
- classname="org.apache.felix.ipojo.test.scenarios.component.FooProviderTypeDyn2"
- name="PS-FooProviderType-Dyn2" architecture="true">
- <provides>
- <property name="int" field="intProp" value="4" />
- <property name="boolean" field="boolProp" />
- <property name="string" field="strProp" />
- <property name="strAProp" field="strAProp" />
- <property name="intAProp" field="intAProp"
- value="{1, 2,3 }" />
- </provides>
- </component>
-
- <!-- Inherited Provides -->
- <component
- classname="org.apache.felix.ipojo.test.scenarios.component.inherited.ProcessImplementation1"
- name="PS-PI1" architecture="true">
- <provides />
- </component>
+ <!-- Provider with dynamic property -->
+ <component
+ classname="org.apache.felix.ipojo.test.scenarios.component.FooProviderTypeDyn"
+ name="PS-FooProviderType-Dyn" architecture="true">
+ <provides>
+ <property name="int" field="intProp" value="2" />
+ <property name="boolean" field="boolProp" value="false" />
+ <property name="string" field="strProp" value="foo" />
+ <property name="strAProp" field="strAProp"
+ value="{foo, bar}" />
+ <property name="intAProp" field="intAProp" value="{1,2,3}" />
+ </provides>
+ </component>
+
+ <component
+ classname="org.apache.felix.ipojo.test.scenarios.component.FooProviderType1"
+ name="PS-FooProviderType-2" architecture="true">
+ <provides>
+ <property name="int" type="int" value="2" />
+ <property name="long" type="long" value="40" />
+ <property name="string" type="java.lang.String" value="foo" />
+ <property name="strAProp" type="java.lang.String[]"
+ value="{foo, bar}" />
+ <property name="intAProp" type="int[]" value="{1,2,3}" />
+ </provides>
+ </component>
+
+ <component
+ classname="org.apache.felix.ipojo.test.scenarios.component.FooProviderTypeDyn2"
+ name="PS-FooProviderType-Dyn2" architecture="true">
+ <provides>
+ <property name="int" field="intProp" value="4" />
+ <property name="boolean" field="boolProp" />
+ <property name="string" field="strProp" />
+ <property name="strAProp" field="strAProp" />
+ <property name="intAProp" field="intAProp"
+ value="{1, 2,3 }" />
+ </provides>
+ </component>
+
+ <!-- Inherited Provides -->
+ <component
+ classname="org.apache.felix.ipojo.test.scenarios.component.inherited.ProcessImplementation1"
+ name="PS-PI1" architecture="true">
+ <provides />
+ </component>
- <component
- classname="org.apache.felix.ipojo.test.scenarios.component.inherited.ProcessImplementation1"
- name="PS-PI1-1" architecture="true">
- <provides
- specifications="org.apache.felix.ipojo.test.scenarios.ps.service.ParentParentInterface" />
- </component>
+ <component
+ classname="org.apache.felix.ipojo.test.scenarios.component.inherited.ProcessImplementation1"
+ name="PS-PI1-1" architecture="true">
+ <provides
+ specifications="org.apache.felix.ipojo.test.scenarios.ps.service.ParentParentInterface" />
+ </component>
- <component
- classname="org.apache.felix.ipojo.test.scenarios.component.inherited.ProcessImplementation1"
- name="PS-PI1-2" architecture="true">
- <provides
- specifications="{org.apache.felix.ipojo.test.scenarios.ps.service.ParentParentInterface, org.apache.felix.ipojo.test.scenarios.ps.service.ParentInterface2}" />
- </component>
+ <component
+ classname="org.apache.felix.ipojo.test.scenarios.component.inherited.ProcessImplementation1"
+ name="PS-PI1-2" architecture="true">
+ <provides
+ specifications="{org.apache.felix.ipojo.test.scenarios.ps.service.ParentParentInterface, org.apache.felix.ipojo.test.scenarios.ps.service.ParentInterface2}" />
+ </component>
- <component
- classname="org.apache.felix.ipojo.test.scenarios.component.inherited.ProcessImplementation2"
- name="PS-PI2" architecture="true">
- <provides />
- </component>
+ <component
+ classname="org.apache.felix.ipojo.test.scenarios.component.inherited.ProcessImplementation2"
+ name="PS-PI2" architecture="true">
+ <provides />
+ </component>
- <component
- classname="org.apache.felix.ipojo.test.scenarios.component.inherited.ProcessImplementation2"
- name="PS-PI2-1" architecture="true">
- <provides
- specifications="org.apache.felix.ipojo.test.scenarios.ps.service.ParentParentInterface" />
- </component>
+ <component
+ classname="org.apache.felix.ipojo.test.scenarios.component.inherited.ProcessImplementation2"
+ name="PS-PI2-1" architecture="true">
+ <provides
+ specifications="org.apache.felix.ipojo.test.scenarios.ps.service.ParentParentInterface" />
+ </component>
- <component
- classname="org.apache.felix.ipojo.test.scenarios.component.inherited.ProcessImplementation3"
- name="PS-PI3" architecture="true">
- <provides />
- </component>
-
- <!-- Concrete and abstract class -->
- <component
- classname="org.apache.felix.ipojo.test.scenarios.component.inherited.ProcessParentImplementation"
- name="PS-PI4" architecture="true">
- <provides specifications="org.apache.felix.ipojo.test.scenarios.component.inherited.ProcessParentImplementation"/>
- </component>
- <component
- classname="org.apache.felix.ipojo.test.scenarios.component.inherited.ProcessImplementation2"
- name="PS-PI5" architecture="true">
- <provides specifications="org.apache.felix.ipojo.test.scenarios.component.inherited.ProcessParentImplementation"/>
- </component>
- <component
- classname="org.apache.felix.ipojo.test.scenarios.component.inherited.ProcessImplementation4"
- name="PS-PI6" architecture="true">
- <provides specifications="org.apache.felix.ipojo.test.scenarios.component.inherited.ProcessParentImplementation"/>
- </component>
- <component
- classname="org.apache.felix.ipojo.test.scenarios.component.inherited.ProcessImplementation3"
- name="PS-PI7" architecture="true">
- <provides specifications="[org.apache.felix.ipojo.test.scenarios.component.inherited.ProcessParentImplementation,
- org.apache.felix.ipojo.test.scenarios.ps.service.FooService]"/>
- </component>
+ <component
+ classname="org.apache.felix.ipojo.test.scenarios.component.inherited.ProcessImplementation3"
+ name="PS-PI3" architecture="true">
+ <provides />
+ </component>
+
+ <!-- Concrete and abstract class -->
+ <component
+ classname="org.apache.felix.ipojo.test.scenarios.component.inherited.ProcessParentImplementation"
+ name="PS-PI4" architecture="true">
+ <provides specifications="org.apache.felix.ipojo.test.scenarios.component.inherited.ProcessParentImplementation"/>
+ </component>
+ <component
+ classname="org.apache.felix.ipojo.test.scenarios.component.inherited.ProcessImplementation2"
+ name="PS-PI5" architecture="true">
+ <provides specifications="org.apache.felix.ipojo.test.scenarios.component.inherited.ProcessParentImplementation"/>
+ </component>
+ <component
+ classname="org.apache.felix.ipojo.test.scenarios.component.inherited.ProcessImplementation4"
+ name="PS-PI6" architecture="true">
+ <provides specifications="org.apache.felix.ipojo.test.scenarios.component.inherited.ProcessParentImplementation"/>
+ </component>
+ <component
+ classname="org.apache.felix.ipojo.test.scenarios.component.inherited.ProcessImplementation3"
+ name="PS-PI7" architecture="true">
+ <provides specifications="[org.apache.felix.ipojo.test.scenarios.component.inherited.ProcessParentImplementation,
+ org.apache.felix.ipojo.test.scenarios.ps.service.FooService]"/>
+ </component>
+
+ <!-- Null Check -->
+ <component classname="org.apache.felix.ipojo.test.scenarios.component.NullCheckServiceProvider" immediate="true"
+ name="PS-Null">
+ <provides>
+ <property field="prop1"/>
+ <property field="prop2"/>
+ </provides>
+ </component>
</ipojo>