summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--vpp-api/java/jvpp/gen/jvpp_callback_facade_gen.py5
-rw-r--r--vpp-api/java/jvpp/gen/jvpp_impl_gen.py5
-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
5 files changed, 20 insertions, 35 deletions
diff --git a/vpp-api/java/jvpp/gen/jvpp_callback_facade_gen.py b/vpp-api/java/jvpp/gen/jvpp_callback_facade_gen.py
index 7b8723bf87c..de239b6d1a3 100644
--- a/vpp-api/java/jvpp/gen/jvpp_callback_facade_gen.py
+++ b/vpp-api/java/jvpp/gen/jvpp_callback_facade_gen.py
@@ -53,10 +53,7 @@ public final class CallbackJVppFacade implements $base_package.$callback_facade_
public CallbackJVppFacade(final $base_package.JVpp jvpp,
java.util.Map<Integer, $base_package.$callback_package.JVppCallback> callbacks) {
- if(jvpp == null) {
- throw new java.lang.NullPointerException("jvpp is null");
- }
- this.jvpp = jvpp;
+ this.jvpp = java.util.Objects.requireNonNull(jvpp,"jvpp is null");
this.callbacks = callbacks;
}
diff --git a/vpp-api/java/jvpp/gen/jvpp_impl_gen.py b/vpp-api/java/jvpp/gen/jvpp_impl_gen.py
index 08ebddfcf97..4e2625714a9 100644
--- a/vpp-api/java/jvpp/gen/jvpp_impl_gen.py
+++ b/vpp-api/java/jvpp/gen/jvpp_impl_gen.py
@@ -52,10 +52,7 @@ public final class JVppImpl implements $base_package.JVpp {
private final $base_package.VppConnection connection;
public JVppImpl(final $base_package.VppConnection connection) {
- if(connection == null) {
- throw new java.lang.NullPointerException("Connection is null");
- }
- this.connection = connection;
+ this.connection = java.util.Objects.requireNonNull(connection,"Connection is null");
}
@Override
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();