Repository: incubator-brooklyn
Updated Branches:
  refs/heads/master ae0efe34c -> bc226c692


JcloudsLocation: avoid NPE on user-creation

If jclouds node doesn’t know its operatingSystem, then was
getting NPE. Guard against that, and default to unix.

Project: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/repo
Commit: 
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/commit/2915b77a
Tree: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/tree/2915b77a
Diff: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/diff/2915b77a

Branch: refs/heads/master
Commit: 2915b77a66dbf438c5c28b2028113453517a2c79
Parents: ecc62b0
Author: Aled Sage <[email protected]>
Authored: Thu Jan 29 10:35:40 2015 +0000
Committer: Aled Sage <[email protected]>
Committed: Thu Jan 29 10:35:40 2015 +0000

----------------------------------------------------------------------
 .../brooklyn/location/jclouds/JcloudsLocation.java     | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/2915b77a/locations/jclouds/src/main/java/brooklyn/location/jclouds/JcloudsLocation.java
----------------------------------------------------------------------
diff --git 
a/locations/jclouds/src/main/java/brooklyn/location/jclouds/JcloudsLocation.java
 
b/locations/jclouds/src/main/java/brooklyn/location/jclouds/JcloudsLocation.java
index 054ce93..cafe1c7 100644
--- 
a/locations/jclouds/src/main/java/brooklyn/location/jclouds/JcloudsLocation.java
+++ 
b/locations/jclouds/src/main/java/brooklyn/location/jclouds/JcloudsLocation.java
@@ -1242,10 +1242,15 @@ public class JcloudsLocation extends 
AbstractCloudMachineProvisioningLocation im
         UserCreation userCreation = createUserStatements(image, config);
         
         if (!userCreation.statements.isEmpty()) {
-            org.jclouds.compute.domain.OsFamily osFamily = 
node.getOperatingSystem().getFamily();
-            org.jclouds.scriptbuilder.domain.OsFamily scriptOsFamily = 
(osFamily == org.jclouds.compute.domain.OsFamily.WINDOWS) 
-                    ? org.jclouds.scriptbuilder.domain.OsFamily.WINDOWS
-                    : org.jclouds.scriptbuilder.domain.OsFamily.UNIX;
+            // If unsure of OS family, default to unix for rendering 
statements.
+            org.jclouds.scriptbuilder.domain.OsFamily scriptOsFamily;
+            if (node.getOperatingSystem() == null) {
+                scriptOsFamily = 
org.jclouds.scriptbuilder.domain.OsFamily.UNIX;
+            } else {
+                scriptOsFamily = (node.getOperatingSystem().getFamily() == 
org.jclouds.compute.domain.OsFamily.WINDOWS) 
+                        ? org.jclouds.scriptbuilder.domain.OsFamily.WINDOWS
+                        : org.jclouds.scriptbuilder.domain.OsFamily.UNIX;
+            }
             
             List<String> commands = Lists.newArrayList();
             for (Statement statement : userCreation.statements) {

Reply via email to