You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by da...@apache.org on 2015/04/09 16:35:29 UTC
svn commit: r1672365 - in /felix/trunk/framework/src:
main/java/org/apache/felix/framework/DTOFactory.java
test/java/org/apache/felix/framework/DTOFactoryTest.java
Author: davidb
Date: Thu Apr 9 14:35:28 2015
New Revision: 1672365
URL: http://svn.apache.org/r1672365
Log:
Core spec compliance: fix Bundle.adapt(ServiceReferenceDTO[].class)
The new behaviour is spec compliant, but will cause a known OSGi R6 CT failure:
testArrayServiceReferenceDTO
ServiceReferenceDTO[] for stopped bundle is null
This is known deviation and is documented here:
http://felix.apache.org/documentation/development/using-the-osgi-compliance-tests.html
Modified:
felix/trunk/framework/src/main/java/org/apache/felix/framework/DTOFactory.java
felix/trunk/framework/src/test/java/org/apache/felix/framework/DTOFactoryTest.java
Modified: felix/trunk/framework/src/main/java/org/apache/felix/framework/DTOFactory.java
URL: http://svn.apache.org/viewvc/felix/trunk/framework/src/main/java/org/apache/felix/framework/DTOFactory.java?rev=1672365&r1=1672364&r2=1672365&view=diff
==============================================================================
--- felix/trunk/framework/src/main/java/org/apache/felix/framework/DTOFactory.java (original)
+++ felix/trunk/framework/src/main/java/org/apache/felix/framework/DTOFactory.java Thu Apr 9 14:35:28 2015
@@ -27,6 +27,7 @@ import java.util.Set;
import org.osgi.dto.DTO;
import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
import org.osgi.framework.Constants;
import org.osgi.framework.InvalidSyntaxException;
import org.osgi.framework.ServiceReference;
@@ -313,6 +314,10 @@ public class DTOFactory
private static ServiceReferenceDTO[] createServiceReferenceDTOArray(Bundle bundle)
{
+ BundleContext ctx = bundle.getBundleContext();
+ if (ctx == null)
+ return null;
+
ServiceReference<?>[] svcs = bundle.getRegisteredServices();
if (svcs == null)
return new ServiceReferenceDTO[0];
Modified: felix/trunk/framework/src/test/java/org/apache/felix/framework/DTOFactoryTest.java
URL: http://svn.apache.org/viewvc/felix/trunk/framework/src/test/java/org/apache/felix/framework/DTOFactoryTest.java?rev=1672365&r1=1672364&r2=1672365&view=diff
==============================================================================
--- felix/trunk/framework/src/test/java/org/apache/felix/framework/DTOFactoryTest.java (original)
+++ felix/trunk/framework/src/test/java/org/apache/felix/framework/DTOFactoryTest.java Thu Apr 9 14:35:28 2015
@@ -19,6 +19,7 @@
package org.apache.felix.framework;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import java.io.ByteArrayInputStream;
@@ -31,7 +32,6 @@ import java.util.Map;
import java.util.jar.JarOutputStream;
import java.util.jar.Manifest;
-import org.apache.felix.framework.Felix;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@@ -130,6 +130,24 @@ public class DTOFactoryTest
}
@Test
+ public void testServiceReferenceDTOArrayStoppedBundle() throws Exception
+ {
+ String mf = "Bundle-SymbolicName: tb2\n"
+ + "Bundle-Version: 1.2.3\n"
+ + "Bundle-ManifestVersion: 2\n"
+ + "Import-Package: org.osgi.framework;version=\"[1.1,2)\"";
+ File bf = createBundle(mf);
+ Bundle bundle = framework.getBundleContext().installBundle(bf.toURI().toURL().toExternalForm());
+
+ assertNull("Precondition", bundle.getBundleContext());
+ ServiceReferenceDTO[] dtos = bundle.adapt(ServiceReferenceDTO[].class);
+
+ // Note this is incorrectly tested by the Core Framework R6 CT, which expects an
+ // empty array. However this is not correct and recorded as a deviation.
+ assertNull("As the bundle is not started, the dtos should be null", dtos);
+ }
+
+ @Test
public void testBundleRevisionDTO() throws Exception
{
String mf = "Bundle-SymbolicName: tb2\n"