You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by cl...@apache.org on 2014/05/06 18:16:18 UTC
svn commit: r1592794 - in /felix/trunk/ipojo/runtime/core/src:
main/java/org/apache/felix/ipojo/configuration/Instance.java
test/java/org/apache/felix/ipojo/configuration/InstanceDSLTest.java
Author: clement
Date: Tue May 6 16:16:18 2014
New Revision: 1592794
URL: http://svn.apache.org/r1592794
Log:
Fix FELIX-4490.
Modified:
felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/configuration/Instance.java
felix/trunk/ipojo/runtime/core/src/test/java/org/apache/felix/ipojo/configuration/InstanceDSLTest.java
Modified: felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/configuration/Instance.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/configuration/Instance.java?rev=1592794&r1=1592793&r2=1592794&view=diff
==============================================================================
--- felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/configuration/Instance.java (original)
+++ felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/configuration/Instance.java Tue May 6 16:16:18 2014
@@ -86,6 +86,9 @@ public class Instance {
}
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 class Instance {
public Instance nameIfUnnamed(String name) {
if (this.name == null) {
- this.name = name;
+ named(name);
}
return this;
}
@@ -123,7 +126,7 @@ public class Instance {
}
}
- 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 @@ public class Instance {
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;
}
Modified: felix/trunk/ipojo/runtime/core/src/test/java/org/apache/felix/ipojo/configuration/InstanceDSLTest.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/runtime/core/src/test/java/org/apache/felix/ipojo/configuration/InstanceDSLTest.java?rev=1592794&r1=1592793&r2=1592794&view=diff
==============================================================================
--- felix/trunk/ipojo/runtime/core/src/test/java/org/apache/felix/ipojo/configuration/InstanceDSLTest.java (original)
+++ felix/trunk/ipojo/runtime/core/src/test/java/org/apache/felix/ipojo/configuration/InstanceDSLTest.java Tue May 6 16:16:18 2014
@@ -52,4 +52,51 @@ public class InstanceDSLTest extends Tes
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
+ }
+ }
}