[JCLOUDS-1088] fix NPE in DeploymentToNodeMetadata.apply

The NPE is caused by passing the value of CloudService.location()
to LocationPredicates.idEquals which throws a NPE when the argument
is null. However, CloudService.location() is @Nullable and is null
when the cloud service is associated with an affinity group.

The solution in this commit checks if CloudService.location() is null
and if it is, the location is obtained from the affinity group.


Project: http://git-wip-us.apache.org/repos/asf/jclouds-labs/repo
Commit: http://git-wip-us.apache.org/repos/asf/jclouds-labs/commit/fe24698d
Tree: http://git-wip-us.apache.org/repos/asf/jclouds-labs/tree/fe24698d
Diff: http://git-wip-us.apache.org/repos/asf/jclouds-labs/diff/fe24698d

Branch: refs/heads/master
Commit: fe24698d81bde3f615dd13bed8a0b33c84ebf865
Parents: 4ff9889
Author: Ladislav Thon <[email protected]>
Authored: Wed Mar 2 15:24:27 2016 +0100
Committer: Ignasi Barrera <[email protected]>
Committed: Tue Mar 8 23:03:01 2016 +0100

----------------------------------------------------------------------
 .../compute/functions/DeploymentToNodeMetadata.java             | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/fe24698d/azurecompute/src/main/java/org/jclouds/azurecompute/compute/functions/DeploymentToNodeMetadata.java
----------------------------------------------------------------------
diff --git 
a/azurecompute/src/main/java/org/jclouds/azurecompute/compute/functions/DeploymentToNodeMetadata.java
 
b/azurecompute/src/main/java/org/jclouds/azurecompute/compute/functions/DeploymentToNodeMetadata.java
index b26532b..622fd9c 100644
--- 
a/azurecompute/src/main/java/org/jclouds/azurecompute/compute/functions/DeploymentToNodeMetadata.java
+++ 
b/azurecompute/src/main/java/org/jclouds/azurecompute/compute/functions/DeploymentToNodeMetadata.java
@@ -117,8 +117,11 @@ public class DeploymentToNodeMetadata implements 
Function<Deployment, NodeMetada
       // TODO: CloudService name is required (see JCLOUDS-849): waiting for 
JCLOUDS-853.
       final CloudService cloudService = 
api.getCloudServiceApi().get(from.name());
       if (cloudService != null) {
+         final String location = cloudService.location() != null
+                 ? cloudService.location()
+                 : 
api.getAffinityGroupApi().get(cloudService.affinityGroup()).location();
          builder.location(FluentIterable.from(locations.get()).
-                 
firstMatch(LocationPredicates.idEquals(cloudService.location())).
+                 firstMatch(LocationPredicates.idEquals(location)).
                  orNull());
       }
 

Reply via email to