aboutsummaryrefslogtreecommitdiffstats
path: root/vpp-api/java/jvpp/org
diff options
context:
space:
mode:
authorTibor Sirovatka <tsirovat@cisco.com>2016-05-09 16:41:31 +0200
committerDave Wallace <dwallacelf@gmail.com>2016-05-12 03:15:23 +0000
commitc2880669216f93ad1c709e3e261991bea2999a50 (patch)
tree723141d5cc87aa1bb4677e3af08039330823e723 /vpp-api/java/jvpp/org
parente6250e0a7ff77d421f9d9b01357520cca14288d5 (diff)
JVPP - null checks changed to Objects.requireNonNull usage
Review changes incorporated Change-Id: Ia04b62144a0d3643095b518db538c7eb5137c048 Signed-off-by: Tibor Sirovatka <tsirovat@cisco.com>
Diffstat (limited to 'vpp-api/java/jvpp/org')
-rw-r--r--vpp-api/java/jvpp/org/openvpp/jvpp/VppJNIConnection.java6
-rw-r--r--vpp-api/java/jvpp/org/openvpp/jvpp/future/FutureJVppInvokerFacade.java14
-rw-r--r--vpp-api/java/jvpp/org/openvpp/jvpp/test/FutureApiTest.java25
3 files changed, 18 insertions, 27 deletions
diff --git a/vpp-api/java/jvpp/org/openvpp/jvpp/VppJNIConnection.java b/vpp-api/java/jvpp/org/openvpp/jvpp/VppJNIConnection.java
index 9e07cc768c4..bf18f1289da 100644
--- a/vpp-api/java/jvpp/org/openvpp/jvpp/VppJNIConnection.java
+++ b/vpp-api/java/jvpp/org/openvpp/jvpp/VppJNIConnection.java
@@ -25,6 +25,7 @@ import java.nio.file.attribute.PosixFilePermission;
import java.nio.file.attribute.PosixFilePermissions;
import java.util.HashMap;
import java.util.Map;
+import java.util.Objects;
import java.util.Set;
import java.util.logging.Logger;
import org.openvpp.jvpp.callback.JVppCallback;
@@ -77,10 +78,7 @@ public final class VppJNIConnection implements VppConnection {
private volatile boolean disconnected = false;
private VppJNIConnection(final String clientName) {
- if (clientName == null) {
- throw new NullPointerException("Null clientName");
- }
- this.clientName = clientName;
+ this.clientName = Objects.requireNonNull(clientName,"Null clientName");
}
/**
diff --git a/vpp-api/java/jvpp/org/openvpp/jvpp/future/FutureJVppInvokerFacade.java b/vpp-api/java/jvpp/org/openvpp/jvpp/future/FutureJVppInvokerFacade.java
index ef8b13c5b01..6b63ade2ade 100644
--- a/vpp-api/java/jvpp/org/openvpp/jvpp/future/FutureJVppInvokerFacade.java
+++ b/vpp-api/java/jvpp/org/openvpp/jvpp/future/FutureJVppInvokerFacade.java
@@ -18,6 +18,7 @@ package org.openvpp.jvpp.future;
import java.util.Map;
+import java.util.Objects;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionStage;
import org.openvpp.jvpp.JVpp;
@@ -41,20 +42,11 @@ public class FutureJVppInvokerFacade implements FutureJVppInvoker {
public FutureJVppInvokerFacade(final JVpp jvpp,
final Map<Integer, CompletableFuture<? extends JVppReply<?>>> requestMap) {
- // TODO use guava's preconditions for nonNull and state checks
- // However adding guava as a dependency requires better build system for Java in VPP project
- // Currently it's just invocation of javac
- if(jvpp == null) {
- throw new NullPointerException("Null jvpp");
- }
- this.jvpp = jvpp;
- if(requestMap == null) {
- throw new NullPointerException("Null requestMap");
- }
+ this.jvpp = Objects.requireNonNull(jvpp, "Null jvpp");
// Request map represents the shared state between this facade and it's callback
// where facade puts futures in and callback completes + removes them
// TODO what if the call never completes ?
- this.requests = requestMap;
+ this.requests = Objects.requireNonNull(requestMap, "Null requestMap");
}
// TODO use Optional in Future, java8
diff --git a/vpp-api/java/jvpp/org/openvpp/jvpp/test/FutureApiTest.java b/vpp-api/java/jvpp/org/openvpp/jvpp/test/FutureApiTest.java
index eb28bbc2e4d..fc84c9519d1 100644
--- a/vpp-api/java/jvpp/org/openvpp/jvpp/test/FutureApiTest.java
+++ b/vpp-api/java/jvpp/org/openvpp/jvpp/test/FutureApiTest.java
@@ -18,6 +18,7 @@ package org.openvpp.jvpp.test;
import java.util.HashMap;
import java.util.Map;
+import java.util.Objects;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.Future;
import org.openvpp.jvpp.VppJNIConnection;
@@ -37,8 +38,11 @@ public class FutureApiTest {
private static void testShowVersion(final FutureJVppFacade jvpp) {
System.out.println("Sending ShowVersion request...");
try {
+ Objects.requireNonNull(jvpp,"jvpp is null");
final Future<ShowVersionReply> replyFuture = jvpp.showVersion(new ShowVersion()).toCompletableFuture();
+ Objects.requireNonNull(replyFuture,"replyFuture is null");
final ShowVersionReply reply = replyFuture.get();
+ Objects.requireNonNull(reply,"reply is null");
System.out.printf("Received ShowVersionReply: context=%d, retval=%d, program=%s, " +
"version=%s, buildDate=%s, buildDirectory=%s\n",
reply.context, reply.retval, new String(reply.program), new String(reply.version),
@@ -56,10 +60,13 @@ public class FutureApiTest {
private static void testGetNodeIndex(final FutureJVppFacade jvpp) {
System.out.println("Sending GetNodeIndex request...");
try {
+ Objects.requireNonNull(jvpp,"jvpp is null");
final GetNodeIndex request = new GetNodeIndex();
request.nodeName = "node0".getBytes();
final Future<GetNodeIndexReply> replyFuture = jvpp.getNodeIndex(request).toCompletableFuture();
+ Objects.requireNonNull(replyFuture,"replyFuture is null");
final GetNodeIndexReply reply = replyFuture.get();
+ Objects.requireNonNull(reply,"reply is null");
System.out.printf("Received GetNodeIndexReply: context=%d, retval=%d, nodeIndex=%d\n",
reply.context, reply.retval, reply.nodeIndex);
} catch (Exception e) {
@@ -71,29 +78,23 @@ public class FutureApiTest {
private static void testSwInterfaceDump(final FutureJVppFacade jvpp) {
System.out.println("Sending SwInterfaceDump request...");
try {
+ Objects.requireNonNull(jvpp,"SwInterfaceDetailsReplyDump is null!");
final SwInterfaceDump request = new SwInterfaceDump();
request.nameFilterValid = 0;
request.nameFilter = "".getBytes();
final Future<SwInterfaceDetailsReplyDump> replyFuture = jvpp.swInterfaceDump(request).toCompletableFuture();
+ Objects.requireNonNull(replyFuture,"replyFuture is null");
final SwInterfaceDetailsReplyDump reply = replyFuture.get();
-
- if (reply == null) {
- throw new IllegalStateException("SwInterfaceDetailsReplyDump is null!");
- }
- if (reply.swInterfaceDetails == null) {
- throw new IllegalStateException("SwInterfaceDetailsReplyDump.swInterfaceDetails is null!");
- }
-
+ Objects.requireNonNull(reply.swInterfaceDetails, "SwInterfaceDetailsReplyDump.swInterfaceDetails is null!");
for (SwInterfaceDetails details : reply.swInterfaceDetails) {
- if (details == null) {
- throw new IllegalStateException("reply.swInterfaceDetails contains null element!");
- }
-
+ Objects.requireNonNull(details, "reply.swInterfaceDetails contains null element!");
System.out.printf("Received SwInterfaceDetails: interfaceName=%s, l2AddressLength=%d, adminUpDown=%d, " +
"linkUpDown=%d, linkSpeed=%d, linkMtu=%d\n",
new String(details.interfaceName), details.l2AddressLength, details.adminUpDown,
details.linkUpDown, details.linkSpeed, (int) details.linkMtu);
}
+ } catch(NullPointerException e) {
+ throw new IllegalStateException(e.getMessage());
} catch (Exception e) {
System.err.printf("SwInterfaceDump request failed:\n");
e.printStackTrace();