Added some protection again UiExtensions that return null inclusion streams.

Change-Id: I18545627da38f4c19fc8316d7fd07df44c5c608f
diff --git a/core/api/src/main/java/org/onosproject/ui/UiExtension.java b/core/api/src/main/java/org/onosproject/ui/UiExtension.java
index d4589a4..cc10506 100644
--- a/core/api/src/main/java/org/onosproject/ui/UiExtension.java
+++ b/core/api/src/main/java/org/onosproject/ui/UiExtension.java
@@ -16,6 +16,8 @@
 package org.onosproject.ui;
 
 import com.google.common.collect.ImmutableList;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 import java.io.InputStream;
 import java.util.List;
@@ -27,6 +29,8 @@
  */
 public class UiExtension {
 
+    private final Logger log = LoggerFactory.getLogger(getClass());
+
     private static final String VIEW_PREFIX = "app/view/";
 
     private final String prefix;
@@ -73,7 +77,7 @@
      * @return CSS inclusion statements
      */
     public InputStream css() {
-        return classLoader.getResourceAsStream(prefix + "css.html");
+        return getStream(prefix + "css.html");
     }
 
     /**
@@ -82,7 +86,7 @@
      * @return JavaScript inclusion statements
      */
     public InputStream js() {
-        return classLoader.getResourceAsStream(prefix + "js.html");
+       return getStream(prefix + "js.html");
     }
 
     /**
@@ -102,8 +106,7 @@
      * @return resource input stream
      */
     public InputStream resource(String viewId, String path) {
-        InputStream is = classLoader.getResourceAsStream(VIEW_PREFIX + viewId + "/" + path);
-        return is;
+        return getStream(VIEW_PREFIX + viewId + "/" + path);
     }
 
     /**
@@ -114,4 +117,15 @@
     public UiMessageHandlerFactory messageHandlerFactory() {
         return messageHandlerFactory;
     }
+
+    // Returns the resource input stream from the specified class-loader.
+    private InputStream getStream(String path) {
+        InputStream stream = classLoader.getResourceAsStream(path);
+        if (stream == null) {
+            log.warn("Unable to find resource {}", path);
+        }
+        return stream;
+    }
+
+
 }
diff --git a/web/gui/src/main/java/org/onosproject/ui/impl/MainIndexResource.java b/web/gui/src/main/java/org/onosproject/ui/impl/MainIndexResource.java
index 644378a..9013fed 100644
--- a/web/gui/src/main/java/org/onosproject/ui/impl/MainIndexResource.java
+++ b/web/gui/src/main/java/org/onosproject/ui/impl/MainIndexResource.java
@@ -16,7 +16,7 @@
 package org.onosproject.ui.impl;
 
 import com.google.common.collect.ImmutableList;
-import org.onosproject.ui.UiExtension;
+import com.google.common.collect.ImmutableList.Builder;
 import org.onosproject.ui.UiExtensionService;
 
 import javax.ws.rs.GET;
@@ -70,20 +70,23 @@
 
     // Produces an input stream including CSS injections from all extensions.
     private InputStream includeCss(UiExtensionService service) {
-        ImmutableList.Builder<InputStream> builder = ImmutableList.builder();
-        for (UiExtension extension : service.getExtensions()) {
-            builder.add(extension.css());
-        }
+        Builder<InputStream> builder = ImmutableList.builder();
+        service.getExtensions().forEach(ext -> add(builder, ext.css()));
         return new SequenceInputStream(new StreamEnumeration(builder.build()));
     }
 
     // Produces an input stream including JS injections from all extensions.
     private InputStream includeJs(UiExtensionService service) {
-        ImmutableList.Builder<InputStream> builder = ImmutableList.builder();
-        for (UiExtension extension : service.getExtensions()) {
-            builder.add(extension.js());
-        }
+        Builder<InputStream> builder = ImmutableList.builder();
+        service.getExtensions().forEach(ext -> add(builder, ext.js()));
         return new SequenceInputStream(new StreamEnumeration(builder.build()));
     }
 
+    // Safely adds the stream to the list builder only if stream is not null.
+    private void add(Builder<InputStream> builder, InputStream inputStream) {
+        if (inputStream != null) {
+            builder.add(inputStream);
+        }
+    }
+
 }