Fix FELIX-4261 NPE when an instance is declared without a configuration using the @ConfigurationTracker


git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1528105 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/ipojo/runtime/core-it/ipojo-core-configuration-processor-test/src/main/java/org/apache/felix/ipojo/runtime/core/components/SimpleConfiguration.java b/ipojo/runtime/core-it/ipojo-core-configuration-processor-test/src/main/java/org/apache/felix/ipojo/runtime/core/components/SimpleConfiguration.java
new file mode 100644
index 0000000..314fb8c
--- /dev/null
+++ b/ipojo/runtime/core-it/ipojo-core-configuration-processor-test/src/main/java/org/apache/felix/ipojo/runtime/core/components/SimpleConfiguration.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.components;
+
+import org.apache.felix.ipojo.configuration.Configuration;
+import org.apache.felix.ipojo.configuration.Instance;
+
+import java.util.Properties;
+
+import static org.apache.felix.ipojo.configuration.Instance.instance;
+
+/**
+ * Simple configuration
+ */
+@Configuration
+public class SimpleConfiguration {
+
+    // Declare an instance of MyComponent named myInstance
+    Instance myInstance = instance().of(MyComponent.class)
+            .named("foo");
+}
diff --git a/ipojo/runtime/core-it/ipojo-core-configuration-processor-test/src/test/java/org/apache/felix/ipojo/runtime/core/TestSimpleConfiguration.java b/ipojo/runtime/core-it/ipojo-core-configuration-processor-test/src/test/java/org/apache/felix/ipojo/runtime/core/TestSimpleConfiguration.java
new file mode 100644
index 0000000..1888d97
--- /dev/null
+++ b/ipojo/runtime/core-it/ipojo-core-configuration-processor-test/src/test/java/org/apache/felix/ipojo/runtime/core/TestSimpleConfiguration.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.runtime.core;
+
+import junit.framework.Assert;
+import org.apache.felix.ipojo.runtime.core.components.MyComponent;
+import org.apache.felix.ipojo.runtime.core.components.SimpleConfiguration;
+import org.apache.felix.ipojo.runtime.core.services.FooService;
+import org.junit.Test;
+import org.ops4j.pax.exam.Configuration;
+import org.ops4j.pax.exam.Option;
+import org.ops4j.pax.exam.OptionUtils;
+import org.ops4j.pax.tinybundles.core.TinyBundles;
+import org.osgi.framework.Constants;
+import org.ow2.chameleon.testing.helpers.TimeUtils;
+import org.ow2.chameleon.testing.tinybundles.ipojo.IPOJOStrategy;
+
+import java.io.IOException;
+
+import static org.ops4j.pax.exam.CoreOptions.streamBundle;
+import static org.ops4j.pax.tinybundles.core.TinyBundles.withBnd;
+
+/**
+ * Check a simple @Configuration
+ */
+public class TestSimpleConfiguration extends Common {
+
+    @Configuration
+    public Option[] config() throws IOException {
+
+        Option[] options = super.config();
+
+        // Build a service bundle
+        return OptionUtils.combine(options,
+                streamBundle(
+                        TinyBundles.bundle()
+                                .add(FooService.class)
+                                .set(Constants.BUNDLE_SYMBOLICNAME, "ServiceInterface")
+                                .set(Constants.EXPORT_PACKAGE, "org.apache.felix.ipojo.runtime.core.services")
+                                .build(withBnd())
+                ),
+                streamBundle(
+                        TinyBundles.bundle()
+                                .add(MyComponent.class)
+                                .add(SimpleConfiguration.class)
+                                .set(Constants.BUNDLE_SYMBOLICNAME, "MyComponent")
+                                .build(IPOJOStrategy.withiPOJO())
+                )
+        );
+    }
+
+    @Test
+    public void testConfiguration() throws InterruptedException {
+        TimeUtils.grace(1000);
+        // Check configuration
+        Assert.assertNotNull(osgiHelper.getServiceReference(FooService.class));
+    }
+
+
+}
diff --git a/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/configuration/Instance.java b/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/configuration/Instance.java
index 8e9d90c..bda9f4f 100644
--- a/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/configuration/Instance.java
+++ b/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/configuration/Instance.java
@@ -62,8 +62,10 @@
 
     public Dictionary<String, Object> configuration() {
         Hashtable<String, Object> configuration = new Hashtable<String, Object>();
-        for (Property property : this.configuration) {
-            configuration.put(property.name, property.value);
+        if (this.configuration != null) {
+            for (Property property : this.configuration) {
+                configuration.put(property.name, property.value);
+            }
         }
 
         if (name != null) {