karaf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jbono...@apache.org
Subject karaf git commit: [KARAF-4174] Prevent NPE in obr:info command if resource is not complete
Date Mon, 24 Jul 2017 16:16:30 GMT
Repository: karaf
Updated Branches:
  refs/heads/karaf-4.0.x 254b40fee -> 14cb98647


[KARAF-4174] Prevent NPE in obr:info command if resource is not complete


Project: http://git-wip-us.apache.org/repos/asf/karaf/repo
Commit: http://git-wip-us.apache.org/repos/asf/karaf/commit/14cb9864
Tree: http://git-wip-us.apache.org/repos/asf/karaf/tree/14cb9864
Diff: http://git-wip-us.apache.org/repos/asf/karaf/diff/14cb9864

Branch: refs/heads/karaf-4.0.x
Commit: 14cb98647a02eca1c8ee0265bc7a61935415d7d6
Parents: 254b40f
Author: Jean-Baptiste Onofré <jbonofre@apache.org>
Authored: Mon Jul 24 18:16:06 2017 +0200
Committer: Jean-Baptiste Onofré <jbonofre@apache.org>
Committed: Mon Jul 24 18:16:06 2017 +0200

----------------------------------------------------------------------
 .../apache/karaf/obr/command/InfoCommand.java   | 63 +++++++++-----------
 1 file changed, 28 insertions(+), 35 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/karaf/blob/14cb9864/obr/src/main/java/org/apache/karaf/obr/command/InfoCommand.java
----------------------------------------------------------------------
diff --git a/obr/src/main/java/org/apache/karaf/obr/command/InfoCommand.java b/obr/src/main/java/org/apache/karaf/obr/command/InfoCommand.java
index 616e8cb..7b576a8 100644
--- a/obr/src/main/java/org/apache/karaf/obr/command/InfoCommand.java
+++ b/obr/src/main/java/org/apache/karaf/obr/command/InfoCommand.java
@@ -62,48 +62,41 @@ public class InfoCommand extends ObrCommandSupport {
 
     private void printResource(PrintStream out, Resource resource)
     {
-        // OBR R5 per Spec has no presentation name
-        String resourceId = getResourceId(resource);
+        if (out != null && resource != null) {
+            // OBR R5 per Spec has no presentation name
+            String resourceId = getResourceId(resource);
 
-        printUnderline(out, resourceId.length());
-        out.println(resourceId);
-        printUnderline(out, resourceId.length());
+            printUnderline(out, resourceId.length());
+            out.println(resourceId);
+            printUnderline(out, resourceId.length());
 
-        Map map = resource.getProperties();
-        for (Iterator iter = map.entrySet().iterator(); iter.hasNext(); )
-        {
-            Map.Entry entry = (Map.Entry) iter.next();
-            if (entry.getValue().getClass().isArray())
-            {
-                out.println(entry.getKey() + ":");
-                for (int j = 0; j < Array.getLength(entry.getValue()); j++)
-                {
-                    out.println("   " + Array.get(entry.getValue(), j));
+            Map map = resource.getProperties();
+            for (Iterator iter = map.entrySet().iterator(); iter.hasNext(); ) {
+                Map.Entry entry = (Map.Entry) iter.next();
+                if (entry.getValue().getClass().isArray()) {
+                    out.println(entry.getKey() + ":");
+                    for (int j = 0; j < Array.getLength(entry.getValue()); j++) {
+                        out.println("   " + Array.get(entry.getValue(), j));
+                    }
+                } else {
+                    out.println(entry.getKey() + ": " + entry.getValue());
                 }
             }
-            else
-            {
-                out.println(entry.getKey() + ": " + entry.getValue());
-            }
-        }
 
-        Requirement[] reqs = resource.getRequirements();
-        if ((reqs != null) && (reqs.length > 0))
-        {
-            out.println("Requires:");
-            for (int i = 0; i < reqs.length; i++)
-            {
-                out.println("   " + reqs[i].getName() + ":" + reqs[i].getFilter());
+            Requirement[] reqs = resource.getRequirements();
+            if ((reqs != null) && (reqs.length > 0)) {
+                out.println("Requires:");
+                for (int i = 0; i < reqs.length; i++) {
+                    out.println("   " + reqs[i].getName() + ":" + reqs[i].getFilter());
+                }
             }
-        }
 
-        Capability[] caps = resource.getCapabilities();
-        if ((caps != null) && (caps.length > 0))
-        {
-            out.println("Capabilities:");
-            for (int i = 0; i < caps.length; i++)
-            {
-                out.println("   " + caps[i].getName() + ":" + caps[i].getPropertiesAsMap());
+            Capability[] caps = resource.getCapabilities();
+            if ((caps != null) && (caps.length > 0)) {
+                out.println("Capabilities:");
+                for (int i = 0; i < caps.length; i++) {
+                    out.println("   " + caps[i].getName() + ":" + caps[i].getPropertiesAsMap());
+                }
             }
         }
     }


Mime
View raw message