Resolve the service reference before intantiating proxy for it
[controller.git] / opendaylight / md-sal / sal-binding-broker / src / main / java / org / opendaylight / controller / config / yang / md / sal / binding / impl / RuntimeMappingModule.java
index cef37db684fc6717d28db0ba4f25339a15136fce..51efa9e2e5498ef3e1e5e6296ea61fee9fa0646c 100644 (file)
@@ -80,7 +80,12 @@ public final class RuntimeMappingModule extends
         if(serviceRef == null) {
             return null;
         }
-        return new RuntimeGeneratedMappingServiceProxy(getBundleContext(),serviceRef);
+
+        BindingIndependentMappingService delegate = bundleContext.getService(serviceRef);
+        if (delegate == null) {
+            return null;
+        }
+        return new RuntimeGeneratedMappingServiceProxy(getBundleContext(),serviceRef,delegate);
     }
 
     private BundleContext getBundleContext() {
@@ -101,10 +106,11 @@ public final class RuntimeMappingModule extends
         private BundleContext bundleContext;
 
         public RuntimeGeneratedMappingServiceProxy(BundleContext bundleContext,
-                ServiceReference<BindingIndependentMappingService> serviceRef) {
-            this.bundleContext = bundleContext;
-            this.reference = serviceRef;
-            this.delegate = bundleContext.getService(serviceRef);
+                ServiceReference<BindingIndependentMappingService> serviceRef,
+                BindingIndependentMappingService delegate) {
+            this.bundleContext = Preconditions.checkNotNull(bundleContext);
+            this.reference = Preconditions.checkNotNull(serviceRef);
+            this.delegate = Preconditions.checkNotNull(delegate);
         }
 
         public CodecRegistry getCodecRegistry() {