Fix the NPE in the DependencyModel

git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1497417 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/ipojo/runtime/core-it/ipojo-core-service-dependency-test/src/main/java/org/apache/felix/ipojo/runtime/core/test/components/error/NullPointerExceptionBinder.java b/ipojo/runtime/core-it/ipojo-core-service-dependency-test/src/main/java/org/apache/felix/ipojo/runtime/core/test/components/error/NullPointerExceptionBinder.java
new file mode 100644
index 0000000..3aca79d
--- /dev/null
+++ b/ipojo/runtime/core-it/ipojo-core-service-dependency-test/src/main/java/org/apache/felix/ipojo/runtime/core/test/components/error/NullPointerExceptionBinder.java
@@ -0,0 +1,38 @@
+/*
+ * 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.runtime.core.test.components.error;
+
+import org.apache.felix.ipojo.annotations.*;
+import org.apache.felix.ipojo.architecture.Architecture;
+
+
+
+@Component(immediate=true)
+@Instantiate
+/**
+ * Throws an NPE when binding a service.
+ */
+public class NullPointerExceptionBinder {
+
+  @Bind(id="instances", aggregate=true, optional=true)
+  public void bindInstance(Architecture instance) {
+    throw new NullPointerException("something went terribly wrong");
+  }
+
+}
diff --git a/ipojo/runtime/core-it/ipojo-core-service-dependency-test/src/test/java/org/apache/felix/ipojo/runtime/core/test/dependencies/error/TestNPEInBindMethod.java b/ipojo/runtime/core-it/ipojo-core-service-dependency-test/src/test/java/org/apache/felix/ipojo/runtime/core/test/dependencies/error/TestNPEInBindMethod.java
new file mode 100644
index 0000000..e518d68
--- /dev/null
+++ b/ipojo/runtime/core-it/ipojo-core-service-dependency-test/src/test/java/org/apache/felix/ipojo/runtime/core/test/dependencies/error/TestNPEInBindMethod.java
@@ -0,0 +1,46 @@
+/*
+ * 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.runtime.core.test.dependencies.error;
+
+import org.apache.felix.ipojo.*;
+import org.apache.felix.ipojo.runtime.core.test.dependencies.Common;
+import org.junit.Test;
+
+import static junit.framework.Assert.assertEquals;
+import static junit.framework.Assert.assertNotNull;
+
+/**
+ * Checks what happens when we access a service throwing a NPE in its bind method.
+ */
+public class TestNPEInBindMethod extends Common {
+
+
+    @Test
+    public void testNPEInBindMethod() throws MissingHandlerException, UnacceptableConfiguration, ConfigurationException {
+         Factory factory = ipojoHelper.getFactory("org.apache.felix.ipojo.runtime.core.test.components.error" +
+                 ".NullPointerExceptionBinder");
+
+        assertNotNull(factory);
+
+        ComponentInstance instance = factory.createComponentInstance(null);
+        assertEquals(instance.getState(), ComponentInstance.STOPPED);
+
+    }
+
+}
diff --git a/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/util/DependencyModel.java b/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/util/DependencyModel.java
index 49f62ae..0ff5614 100644
--- a/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/util/DependencyModel.java
+++ b/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/util/DependencyModel.java
@@ -907,6 +907,11 @@
      * @return the service object attached to the given reference

      */

     public Object getService(ServiceReference ref, boolean store) {

+        if (m_tracker == null) {

+            // The tracker is already closed, we can't access the service anymore.

+            return null;

+        }

+

         Object svc = m_tracker.getService(ref);

         IPOJOServiceFactory factory = null;