Repository: brooklyn-server
Updated Branches:
  refs/heads/master 984a1e18f -> 6571bab4a


Machines.findUniqueElement returns absent when items is null


Project: http://git-wip-us.apache.org/repos/asf/brooklyn-server/repo
Commit: http://git-wip-us.apache.org/repos/asf/brooklyn-server/commit/79977e76
Tree: http://git-wip-us.apache.org/repos/asf/brooklyn-server/tree/79977e76
Diff: http://git-wip-us.apache.org/repos/asf/brooklyn-server/diff/79977e76

Branch: refs/heads/master
Commit: 79977e768a88e6e3b36d59adb63c0ca32ad6ebcc
Parents: 15d6c98
Author: Sam Corbett <sam.corb...@cloudsoftcorp.com>
Authored: Wed Feb 8 12:22:57 2017 +0000
Committer: Sam Corbett <sam.corb...@cloudsoftcorp.com>
Committed: Wed Feb 8 12:29:31 2017 +0000

----------------------------------------------------------------------
 .../main/java/org/apache/brooklyn/core/location/Machines.java | 7 ++++++-
 .../java/org/apache/brooklyn/core/location/MachinesTest.java  | 5 +++++
 2 files changed, 11 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/79977e76/core/src/main/java/org/apache/brooklyn/core/location/Machines.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/location/Machines.java 
b/core/src/main/java/org/apache/brooklyn/core/location/Machines.java
index 9163694..2a2ccba 100644
--- a/core/src/main/java/org/apache/brooklyn/core/location/Machines.java
+++ b/core/src/main/java/org/apache/brooklyn/core/location/Machines.java
@@ -23,6 +23,8 @@ import java.util.Collection;
 import java.util.Iterator;
 import java.util.Set;
 
+import javax.annotation.Nonnull;
+
 import org.apache.brooklyn.api.entity.Entity;
 import org.apache.brooklyn.api.location.Location;
 import org.apache.brooklyn.api.location.MachineLocation;
@@ -83,9 +85,12 @@ public class Machines {
         return Maybe.fromNullable(result);
     }
 
+    @Nonnull
     @SuppressWarnings("unchecked")
     public static <T> Maybe<T> findUniqueElement(Iterable<?> items, Class<T> 
type) {
-        if (items==null) return null;
+        if (items == null) {
+            return Maybe.absent(new NullPointerException("Null iterable"));
+        }
         Iterator<?> i = items.iterator();
         T result = null;
         while (i.hasNext()) {

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/79977e76/core/src/test/java/org/apache/brooklyn/core/location/MachinesTest.java
----------------------------------------------------------------------
diff --git 
a/core/src/test/java/org/apache/brooklyn/core/location/MachinesTest.java 
b/core/src/test/java/org/apache/brooklyn/core/location/MachinesTest.java
index bc578bd..3e36f7a 100644
--- a/core/src/test/java/org/apache/brooklyn/core/location/MachinesTest.java
+++ b/core/src/test/java/org/apache/brooklyn/core/location/MachinesTest.java
@@ -90,6 +90,11 @@ public class MachinesTest extends BrooklynAppUnitTestSupport 
{
     }
 
     @Test
+    public void testFindUniqueElementAbsentWhenItemsNull() throws Exception {
+        assertTrue(Machines.findUniqueElement(null, 
SshMachineLocation.class).isAbsent());
+    }
+
+    @Test
     public void testFindSubnetIpFromAttribute() throws Exception {
         TestEntity entity = app.addChild(EntitySpec.create(TestEntity.class)
                 .location(sshMachineSpec));

Reply via email to