Sho SHIMIZU
Committed by Gerrit Code Review

Add precondition check to guarantee non-null

Change-Id: I2691fb980ee57befce14a870a2a9f7317e06ea18
...@@ -21,6 +21,8 @@ import com.google.common.base.MoreObjects; ...@@ -21,6 +21,8 @@ import com.google.common.base.MoreObjects;
21 import java.util.Objects; 21 import java.util.Objects;
22 import java.util.Optional; 22 import java.util.Optional;
23 23
24 +import static com.google.common.base.Preconditions.checkNotNull;
25 +
24 /** 26 /**
25 * Represents a resource path which specifies a resource which can be measured 27 * Represents a resource path which specifies a resource which can be measured
26 * as continuous value. Bandwidth of a link is an example of the resource. 28 * as continuous value. Bandwidth of a link is an example of the resource.
...@@ -74,6 +76,8 @@ public final class ContinuousResource implements Resource { ...@@ -74,6 +76,8 @@ public final class ContinuousResource implements Resource {
74 76
75 @Override 77 @Override
76 public boolean isSubTypeOf(Class<?> ancestor) { 78 public boolean isSubTypeOf(Class<?> ancestor) {
79 + checkNotNull(ancestor);
80 +
77 String typeName = (String) id.components().get(id.components().size() - 1); 81 String typeName = (String) id.components().get(id.components().size() - 1);
78 boolean foundInLeaf = typeName.equals(ancestor.getCanonicalName()); 82 boolean foundInLeaf = typeName.equals(ancestor.getCanonicalName());
79 boolean foundInAncestor = id.components().subList(0, id.components().size()).stream() 83 boolean foundInAncestor = id.components().subList(0, id.components().size()).stream()
......
...@@ -22,6 +22,7 @@ import java.util.Objects; ...@@ -22,6 +22,7 @@ import java.util.Objects;
22 import java.util.Optional; 22 import java.util.Optional;
23 23
24 import static com.google.common.base.Preconditions.checkArgument; 24 import static com.google.common.base.Preconditions.checkArgument;
25 +import static com.google.common.base.Preconditions.checkNotNull;
25 26
26 /** 27 /**
27 * Represents a resource path which specifies a resource which can be measured 28 * Represents a resource path which specifies a resource which can be measured
...@@ -64,6 +65,8 @@ public final class DiscreteResource implements Resource { ...@@ -64,6 +65,8 @@ public final class DiscreteResource implements Resource {
64 65
65 @Override 66 @Override
66 public boolean isSubTypeOf(Class<?> ancestor) { 67 public boolean isSubTypeOf(Class<?> ancestor) {
68 + checkNotNull(ancestor);
69 +
67 return id.components().stream() 70 return id.components().stream()
68 .map(Object::getClass) 71 .map(Object::getClass)
69 .filter(x -> x.equals(ancestor)) 72 .filter(x -> x.equals(ancestor))
......