Fix FELIX-4490.

git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1592794 13f79535-47bb-0310-9956-ffa450edef68
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 bda9f4f..93f1f3d 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
@@ -86,6 +86,9 @@
     }
 
     public Instance named(String name) {
+        if (name == null || name.isEmpty()) {
+            throw new IllegalArgumentException("The instance name cannot be null or empty");
+        }
         this.name = name;
         return this;
     }
@@ -101,7 +104,7 @@
 
     public Instance nameIfUnnamed(String name) {
         if (this.name == null) {
-            this.name = name;
+            named(name);
         }
         return this;
     }
@@ -123,7 +126,7 @@
         }
     }
 
-    public static class FluentMap<K,T> extends LinkedHashMap<K, T> {
+    public static class FluentMap<K, T> extends LinkedHashMap<K, T> {
 
         public FluentMap() {
             super(new LinkedHashMap<K, T>());
@@ -163,10 +166,18 @@
         private T value;
 
         Property(String name) {
+            if (name == null || name.isEmpty()) {
+                throw new IllegalArgumentException("The property name cannot be null or empty");
+            }
             this.name = name;
         }
 
         public Instance setto(T value) {
+            if ("instance.name".endsWith(name)) {
+                if (value == null || value.toString().isEmpty()) {
+                    throw new IllegalArgumentException("The instance name cannot be null or empty");
+                }
+            }
             this.value = value;
             return Instance.this;
         }
diff --git a/ipojo/runtime/core/src/test/java/org/apache/felix/ipojo/configuration/InstanceDSLTest.java b/ipojo/runtime/core/src/test/java/org/apache/felix/ipojo/configuration/InstanceDSLTest.java
index 9fc2120..5d4c93e 100644
--- a/ipojo/runtime/core/src/test/java/org/apache/felix/ipojo/configuration/InstanceDSLTest.java
+++ b/ipojo/runtime/core/src/test/java/org/apache/felix/ipojo/configuration/InstanceDSLTest.java
@@ -52,4 +52,51 @@
         String cn = ConfigurationProcessor.getClassNameFromResource("/org/apache/felix/ipojo/Pojo.class");
         Assert.assertEquals(cn, "org.apache.felix.ipojo.Pojo");
     }
+
+    /**
+     * Test for FELIX-4490.
+     */
+    public void testInstanceNameNotNullOrEmpty() {
+        try {
+            instance().named(null);
+            Assert.fail("Exception expected");
+        } catch (IllegalArgumentException e) {
+            // OK
+        }
+
+        try {
+            instance().named("");
+            Assert.fail("Exception expected");
+        } catch (IllegalArgumentException e) {
+            // OK
+        }
+
+        try {
+            instance().nameIfUnnamed(null);
+            Assert.fail("Exception expected");
+        } catch (IllegalArgumentException e) {
+            // OK
+        }
+
+        try {
+            instance().nameIfUnnamed("");
+            Assert.fail("Exception expected");
+        } catch (IllegalArgumentException e) {
+            // OK
+        }
+
+        try {
+            instance().with("instance.name").setto(null);
+            Assert.fail("Exception expected");
+        } catch (IllegalArgumentException e) {
+            // OK
+        }
+
+        try {
+            instance().with("instance.name").setto("");
+            Assert.fail("Exception expected");
+        } catch (IllegalArgumentException e) {
+            // OK
+        }
+    }
 }