SpotBugs is touchy about nulls here, all of which are guaranteed
to work out due to verification logic -- but that is not quite
obvious. Fix this up by adding explicit verifies -- which do not
hurn that much.
Change-Id: I92a120c9f8d4fced2bf3e8a859772cf6d41798df
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
}
if (depth == path.size() - 1) {
// Use the parent cache
}
if (depth == path.size() - 1) {
// Use the parent cache
+ return verifyNotNull(getParent());
}
return YangInstanceIdentifier.create(path.subList(0, depth));
}
}
return YangInstanceIdentifier.create(path.subList(0, depth));
}
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Verify.verify;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Verify.verify;
+import static com.google.common.base.Verify.verifyNotNull;
import static java.util.Objects.requireNonNull;
import com.google.common.collect.Iterables;
import static java.util.Objects.requireNonNull;
import com.google.common.collect.Iterables;
final int toWalk = ourDepth - depth;
YangInstanceIdentifier result = this;
for (int i = 0; i < toWalk; ++i) {
final int toWalk = ourDepth - depth;
YangInstanceIdentifier result = this;
for (int i = 0; i < toWalk; ++i) {
- result = result.getParent();
+ result = verifyNotNull(result.getParent());
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertThrows;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.assertThrows;
import static org.junit.Assert.assertTrue;
final YangInstanceIdentifier yangInstanceIdentifier1 = stackedYangInstanceIdentifier.getAncestor(4);
assertEquals(stackedYangInstanceIdentifier, stackedYangInstanceIdentifierClone);
assertEquals(stackedReversePathArguments, yangInstanceIdentifier1.getReversePathArguments());
final YangInstanceIdentifier yangInstanceIdentifier1 = stackedYangInstanceIdentifier.getAncestor(4);
assertEquals(stackedYangInstanceIdentifier, stackedYangInstanceIdentifierClone);
assertEquals(stackedReversePathArguments, yangInstanceIdentifier1.getReversePathArguments());
+ assertSame(stackedYangInstanceIdentifier.getParent(), stackedYangInstanceIdentifier.getAncestor(3));
- assertThrows(IllegalArgumentException.class, () -> stackedYangInstanceIdentifier.getAncestor(12));
+ final IllegalArgumentException thrown = assertThrows(IllegalArgumentException.class,
+ () -> stackedYangInstanceIdentifier.getAncestor(12));
+ assertEquals("Depth 12 exceeds maximum depth 4", thrown.getMessage());