Prohibit null for resources field in Intent

Change-Id: I128c6e63ccccaf817e83ff1c440a731fb98b42f7
diff --git a/cli/src/main/java/org/onosproject/cli/net/IntentsListCommand.java b/cli/src/main/java/org/onosproject/cli/net/IntentsListCommand.java
index 59473ca..77a8bd6 100644
--- a/cli/src/main/java/org/onosproject/cli/net/IntentsListCommand.java
+++ b/cli/src/main/java/org/onosproject/cli/net/IntentsListCommand.java
@@ -328,7 +328,7 @@
     }
 
     private void printDetails(IntentService service, Intent intent) {
-        if (intent.resources() != null && !intent.resources().isEmpty()) {
+        if (!intent.resources().isEmpty()) {
             print("    resources=%s", intent.resources());
         }
         if (intent instanceof ConnectivityIntent) {
@@ -392,7 +392,7 @@
             result.put("state", state.toString());
         }
 
-        if (intent.resources() != null && !intent.resources().isEmpty()) {
+        if (!intent.resources().isEmpty()) {
             ArrayNode rnode = mapper.createArrayNode();
             for (NetworkResource resource : intent.resources()) {
                 rnode.add(resource.toString());
diff --git a/core/api/src/main/java/org/onosproject/net/intent/HostToHostIntent.java b/core/api/src/main/java/org/onosproject/net/intent/HostToHostIntent.java
index e78d78c..7e6eed8 100644
--- a/core/api/src/main/java/org/onosproject/net/intent/HostToHostIntent.java
+++ b/core/api/src/main/java/org/onosproject/net/intent/HostToHostIntent.java
@@ -26,6 +26,7 @@
 import org.onosproject.net.flow.TrafficTreatment;
 import org.onosproject.net.intent.constraint.LinkTypeConstraint;
 
+import java.util.Collections;
 import java.util.List;
 
 import static com.google.common.base.Preconditions.checkNotNull;
@@ -86,7 +87,7 @@
                             TrafficSelector selector,
                             TrafficTreatment treatment,
                             List<Constraint> constraints) {
-        super(appId, null, selector, treatment, constraints);
+        super(appId, Collections.emptyList(), selector, treatment, constraints);
 
         // TODO: consider whether the case one and two are same is allowed
         this.one = checkNotNull(one);
diff --git a/core/api/src/main/java/org/onosproject/net/intent/Intent.java b/core/api/src/main/java/org/onosproject/net/intent/Intent.java
index 0d0955f..6043995 100644
--- a/core/api/src/main/java/org/onosproject/net/intent/Intent.java
+++ b/core/api/src/main/java/org/onosproject/net/intent/Intent.java
@@ -60,7 +60,7 @@
         checkState(idGenerator != null, "Id generator is not bound.");
         this.id = IntentId.valueOf(idGenerator.getNewId());
         this.appId = checkNotNull(appId, "Application ID cannot be null");
-        this.resources = resources;
+        this.resources = checkNotNull(resources);
     }
 
     /**
diff --git a/core/api/src/main/java/org/onosproject/net/intent/MultiPointToSinglePointIntent.java b/core/api/src/main/java/org/onosproject/net/intent/MultiPointToSinglePointIntent.java
index 1c751b9..1df961f 100644
--- a/core/api/src/main/java/org/onosproject/net/intent/MultiPointToSinglePointIntent.java
+++ b/core/api/src/main/java/org/onosproject/net/intent/MultiPointToSinglePointIntent.java
@@ -80,7 +80,7 @@
                                          Set<ConnectPoint> ingressPoints,
                                          ConnectPoint egressPoint,
                                          List<Constraint> constraints) {
-        super(appId, null, selector, treatment, constraints);
+        super(appId, Collections.emptyList(), selector, treatment, constraints);
 
         checkNotNull(ingressPoints);
         checkArgument(!ingressPoints.isEmpty(), "Ingress point set cannot be empty");
diff --git a/core/api/src/main/java/org/onosproject/net/intent/OpticalConnectivityIntent.java b/core/api/src/main/java/org/onosproject/net/intent/OpticalConnectivityIntent.java
index 9e12510..332f430 100644
--- a/core/api/src/main/java/org/onosproject/net/intent/OpticalConnectivityIntent.java
+++ b/core/api/src/main/java/org/onosproject/net/intent/OpticalConnectivityIntent.java
@@ -18,6 +18,8 @@
 import org.onosproject.core.ApplicationId;
 import org.onosproject.net.ConnectPoint;
 
+import java.util.Collections;
+
 /**
  * An optical layer intent for connectivity from one transponder port to another
  * transponder port. No traffic selector or traffic treatment are needed.
@@ -36,7 +38,7 @@
      */
     public OpticalConnectivityIntent(ApplicationId appId,
                                      ConnectPoint src, ConnectPoint dst) {
-        super(appId, null);
+        super(appId, Collections.emptyList());
         this.src = src;
         this.dst = dst;
     }
diff --git a/core/api/src/main/java/org/onosproject/net/intent/PointToPointIntent.java b/core/api/src/main/java/org/onosproject/net/intent/PointToPointIntent.java
index 4a725f6..c4c53c7 100644
--- a/core/api/src/main/java/org/onosproject/net/intent/PointToPointIntent.java
+++ b/core/api/src/main/java/org/onosproject/net/intent/PointToPointIntent.java
@@ -24,6 +24,7 @@
 import org.onosproject.net.flow.TrafficTreatment;
 import org.onosproject.net.intent.constraint.LinkTypeConstraint;
 
+import java.util.Collections;
 import java.util.List;
 
 import static com.google.common.base.Preconditions.checkArgument;
@@ -73,7 +74,7 @@
                               ConnectPoint ingressPoint,
                               ConnectPoint egressPoint,
                               List<Constraint> constraints) {
-        super(appId, null, selector, treatment, constraints);
+        super(appId, Collections.emptyList(), selector, treatment, constraints);
 
         checkNotNull(ingressPoint);
         checkNotNull(egressPoint);
diff --git a/core/api/src/main/java/org/onosproject/net/intent/SinglePointToMultiPointIntent.java b/core/api/src/main/java/org/onosproject/net/intent/SinglePointToMultiPointIntent.java
index 8752c4a..7b86f25 100644
--- a/core/api/src/main/java/org/onosproject/net/intent/SinglePointToMultiPointIntent.java
+++ b/core/api/src/main/java/org/onosproject/net/intent/SinglePointToMultiPointIntent.java
@@ -75,7 +75,7 @@
             TrafficSelector selector, TrafficTreatment treatment,
             ConnectPoint ingressPoint, Set<ConnectPoint> egressPoints,
             List<Constraint> constraints) {
-        super(appId, null, selector, treatment, constraints);
+        super(appId, Collections.emptyList(), selector, treatment, constraints);
         checkNotNull(egressPoints);
         checkNotNull(ingressPoint);
         checkArgument(!egressPoints.isEmpty(), "Egress point set cannot be empty");
diff --git a/core/api/src/test/java/org/onosproject/net/intent/TestInstallableIntent.java b/core/api/src/test/java/org/onosproject/net/intent/TestInstallableIntent.java
index 4c69bf3..32e5c90 100644
--- a/core/api/src/test/java/org/onosproject/net/intent/TestInstallableIntent.java
+++ b/core/api/src/test/java/org/onosproject/net/intent/TestInstallableIntent.java
@@ -17,6 +17,8 @@
 
 import org.onosproject.TestApplicationId;
 
+import java.util.Collections;
+
 /**
  * An installable intent used in the unit test.
  */
@@ -30,7 +32,7 @@
      * @param value intent ID
      */
     public TestInstallableIntent(int value) { // FIXME
-        super(new TestApplicationId("foo"), null);
+        super(new TestApplicationId("foo"), Collections.emptyList());
         this.value = value;
     }
 
diff --git a/core/api/src/test/java/org/onosproject/net/intent/TestIntent.java b/core/api/src/test/java/org/onosproject/net/intent/TestIntent.java
index 5cdc187..b3a8679 100644
--- a/core/api/src/test/java/org/onosproject/net/intent/TestIntent.java
+++ b/core/api/src/test/java/org/onosproject/net/intent/TestIntent.java
@@ -17,6 +17,8 @@
 
 import org.onosproject.TestApplicationId;
 
+import java.util.Collections;
+
 /**
  * An intent used in the unit test.
  */
@@ -30,7 +32,7 @@
      * @param value intent ID
      */
     public TestIntent(int value) { // FIXME
-        super(new TestApplicationId("foo"), null);
+        super(new TestApplicationId("foo"), Collections.emptyList());
         this.value = value;
     }
 
diff --git a/core/net/src/test/java/org/onosproject/net/intent/impl/IntentManagerTest.java b/core/net/src/test/java/org/onosproject/net/intent/impl/IntentManagerTest.java
index fe509dd..0554ae0 100644
--- a/core/net/src/test/java/org/onosproject/net/intent/impl/IntentManagerTest.java
+++ b/core/net/src/test/java/org/onosproject/net/intent/impl/IntentManagerTest.java
@@ -16,6 +16,7 @@
 package org.onosproject.net.intent.impl;
 
 import java.util.Collection;
+import java.util.Collections;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
@@ -154,7 +155,7 @@
         private final Long number;
         // Nothing new here
         public MockIntent(Long number) {
-            super(APPID, null);
+            super(APPID, Collections.emptyList());
             this.number = number;
         }
 
@@ -507,7 +508,7 @@
     public void intentWithoutCompiler() {
         class IntentNoCompiler extends Intent {
             IntentNoCompiler() {
-                super(APPID, null);
+                super(APPID, Collections.emptyList());
             }
         }
 
diff --git a/web/api/src/main/java/org/onosproject/codec/impl/IntentCodec.java b/web/api/src/main/java/org/onosproject/codec/impl/IntentCodec.java
index c999757..a03acfc 100644
--- a/web/api/src/main/java/org/onosproject/codec/impl/IntentCodec.java
+++ b/web/api/src/main/java/org/onosproject/codec/impl/IntentCodec.java
@@ -41,10 +41,8 @@
 
         final ArrayNode jsonResources = result.putArray("resources");
 
-        if (intent.resources() != null) {
-            for (final NetworkResource resource : intent.resources()) {
-                jsonResources.add(resource.toString());
-            }
+        for (final NetworkResource resource : intent.resources()) {
+            jsonResources.add(resource.toString());
         }
         return result;
     }
diff --git a/web/api/src/test/java/org/onosproject/rest/IntentsResourceTest.java b/web/api/src/test/java/org/onosproject/rest/IntentsResourceTest.java
index 087d8ab..4a6c2e5 100644
--- a/web/api/src/test/java/org/onosproject/rest/IntentsResourceTest.java
+++ b/web/api/src/test/java/org/onosproject/rest/IntentsResourceTest.java
@@ -16,6 +16,7 @@
 package org.onosproject.rest;
 
 import java.util.Collection;
+import java.util.Collections;
 import java.util.HashSet;
 import java.util.concurrent.atomic.AtomicLong;
 
@@ -300,7 +301,7 @@
     public void testIntentsArray() {
         replay(mockIntentService);
 
-        final Intent intent1 = new MockIntent(null);
+        final Intent intent1 = new MockIntent(Collections.emptyList());
         final HashSet<NetworkResource> resources = new HashSet<>();
         resources.add(new MockResource(1));
         resources.add(new MockResource(2));