jvpp: fix coverity warn: reliance on default encoding 55/4955/2
authorMarek Gradzki <mgradzki@cisco.com>
Tue, 31 Jan 2017 12:25:53 +0000 (13:25 +0100)
committerDamjan Marion <dmarion.lists@gmail.com>
Tue, 31 Jan 2017 14:08:14 +0000 (14:08 +0000)
Change-Id: I8333b7d19ebdacac5445b4505750dd0a46764b36
Signed-off-by: Marek Gradzki <mgradzki@cisco.com>
src/vpp-api/java/jvpp-core/io/fd/vpp/jvpp/core/test/CallbackApiTest.java
src/vpp-api/java/jvpp-core/io/fd/vpp/jvpp/core/test/CallbackJVppFacadeTest.java
src/vpp-api/java/jvpp-core/io/fd/vpp/jvpp/core/test/CreateSubInterfaceTest.java
src/vpp-api/java/jvpp-core/io/fd/vpp/jvpp/core/test/FutureApiTest.java
src/vpp-api/java/jvpp-ioampot/io/fd/vpp/jvpp/ioampot/test/IoamPotApiTest.java

index 986993b..8fcef96 100644 (file)
@@ -30,6 +30,7 @@ import io.fd.vpp.jvpp.core.dto.ShowVersion;
 import io.fd.vpp.jvpp.core.dto.ShowVersionReply;
 import io.fd.vpp.jvpp.core.dto.SwInterfaceDetails;
 import io.fd.vpp.jvpp.core.dto.SwInterfaceDump;
+import java.nio.charset.StandardCharsets;
 
 public class CallbackApiTest {
 
@@ -49,13 +50,13 @@ public class CallbackApiTest {
 
             System.out.println("Sending GetNodeIndex request...");
             GetNodeIndex getNodeIndexRequest = new GetNodeIndex();
-            getNodeIndexRequest.nodeName = "non-existing-node".getBytes();
+            getNodeIndexRequest.nodeName = "non-existing-node".getBytes(StandardCharsets.UTF_8);
             jvpp.send(getNodeIndexRequest);
 
             System.out.println("Sending SwInterfaceDump request...");
             SwInterfaceDump swInterfaceDumpRequest = new SwInterfaceDump();
             swInterfaceDumpRequest.nameFilterValid = 0;
-            swInterfaceDumpRequest.nameFilter = "".getBytes();
+            swInterfaceDumpRequest.nameFilter = "".getBytes(StandardCharsets.UTF_8);
             jvpp.send(swInterfaceDumpRequest);
 
             Thread.sleep(1000);
@@ -75,15 +76,18 @@ public class CallbackApiTest {
         public void onShowVersionReply(final ShowVersionReply msg) {
             System.out.printf("Received ShowVersionReply: context=%d, program=%s, version=%s, "
                     + "buildDate=%s, buildDirectory=%s%n",
-                msg.context, new String(msg.program), new String(msg.version),
-                new String(msg.buildDate), new String(msg.buildDirectory));
+                msg.context,
+                new String(msg.program, StandardCharsets.UTF_8),
+                new String(msg.version, StandardCharsets.UTF_8),
+                new String(msg.buildDate, StandardCharsets.UTF_8),
+                new String(msg.buildDirectory, StandardCharsets.UTF_8));
         }
 
         @Override
         public void onSwInterfaceDetails(final SwInterfaceDetails msg) {
             System.out.printf("Received SwInterfaceDetails: interfaceName=%s, l2AddressLength=%d, adminUpDown=%d, "
                     + "linkUpDown=%d, linkSpeed=%d, linkMtu=%d%n",
-                new String(msg.interfaceName), msg.l2AddressLength, msg.adminUpDown,
+                new String(msg.interfaceName, StandardCharsets.UTF_8), msg.l2AddressLength, msg.adminUpDown,
                 msg.linkUpDown, msg.linkSpeed, (int) msg.linkMtu);
         }
 
index 9f7cb8d..cf6b0bb 100644 (file)
@@ -26,6 +26,7 @@ import io.fd.vpp.jvpp.core.callfacade.CallbackJVppCoreFacade;
 import io.fd.vpp.jvpp.core.dto.GetNodeIndex;
 import io.fd.vpp.jvpp.core.dto.GetNodeIndexReply;
 import io.fd.vpp.jvpp.core.dto.ShowVersionReply;
+import java.nio.charset.StandardCharsets;
 
 /**
  * CallbackJVppFacade together with CallbackJVppFacadeCallback allow for setting different callback for each request.
@@ -37,8 +38,11 @@ public class CallbackJVppFacadeTest {
         @Override
         public void onShowVersionReply(final ShowVersionReply msg) {
             System.out.printf("ShowVersionCallback1 received ShowVersionReply: context=%d, program=%s,"
-                    + "version=%s, buildDate=%s, buildDirectory=%s%n", msg.context, new String(msg.program),
-                new String(msg.version), new String(msg.buildDate), new String(msg.buildDirectory));
+                    + "version=%s, buildDate=%s, buildDirectory=%s%n", msg.context,
+                new String(msg.program, StandardCharsets.UTF_8),
+                new String(msg.version, StandardCharsets.UTF_8),
+                new String(msg.buildDate, StandardCharsets.UTF_8),
+                new String(msg.buildDirectory, StandardCharsets.UTF_8));
         }
 
         @Override
@@ -52,8 +56,11 @@ public class CallbackJVppFacadeTest {
         @Override
         public void onShowVersionReply(final ShowVersionReply msg) {
             System.out.printf("ShowVersionCallback2 received ShowVersionReply: context=%d, program=%s,"
-                    + "version=%s, buildDate=%s, buildDirectory=%s%n", msg.context, new String(msg.program),
-                new String(msg.version), new String(msg.buildDate), new String(msg.buildDirectory));
+                    + "version=%s, buildDate=%s, buildDirectory=%s%n", msg.context,
+                new String(msg.program, StandardCharsets.UTF_8),
+                new String(msg.version, StandardCharsets.UTF_8),
+                new String(msg.buildDate, StandardCharsets.UTF_8),
+                new String(msg.buildDirectory, StandardCharsets.UTF_8));
         }
 
         @Override
@@ -88,7 +95,7 @@ public class CallbackJVppFacadeTest {
             callbackFacade.showVersion(showVersionCallback2);
 
             GetNodeIndex getNodeIndexRequest = new GetNodeIndex();
-            getNodeIndexRequest.nodeName = "dummyNode".getBytes();
+            getNodeIndexRequest.nodeName = "dummyNode".getBytes(StandardCharsets.UTF_8);
             callbackFacade.getNodeIndex(getNodeIndexRequest, getNodeIndexCallback);
 
             Thread.sleep(2000);
index a96258f..7684721 100644 (file)
@@ -26,6 +26,7 @@ import io.fd.vpp.jvpp.core.dto.CreateSubifReply;
 import io.fd.vpp.jvpp.core.dto.SwInterfaceDetailsReplyDump;
 import io.fd.vpp.jvpp.core.dto.SwInterfaceDump;
 import io.fd.vpp.jvpp.core.future.FutureJVppCoreFacade;
+import java.nio.charset.StandardCharsets;
 
 /**
  * <p>Tests sub-interface creation.<br> Equivalent to:<br>
@@ -45,7 +46,7 @@ public class CreateSubInterfaceTest {
 
     private static SwInterfaceDump createSwInterfaceDumpRequest(final String ifaceName) {
         SwInterfaceDump request = new SwInterfaceDump();
-        request.nameFilter = ifaceName.getBytes();
+        request.nameFilter = ifaceName.getBytes(StandardCharsets.UTF_8);
         request.nameFilterValid = 1;
         return request;
     }
index f478bab..0d7c747 100644 (file)
@@ -29,6 +29,7 @@ import io.fd.vpp.jvpp.core.dto.SwInterfaceDetails;
 import io.fd.vpp.jvpp.core.dto.SwInterfaceDetailsReplyDump;
 import io.fd.vpp.jvpp.core.dto.SwInterfaceDump;
 import io.fd.vpp.jvpp.core.future.FutureJVppCoreFacade;
+import java.nio.charset.StandardCharsets;
 import java.util.Objects;
 import java.util.concurrent.CompletableFuture;
 import java.util.concurrent.Future;
@@ -46,8 +47,10 @@ public class FutureApiTest {
         LOG.info(
             String.format(
                 "Received ShowVersionReply: context=%d, program=%s, version=%s, buildDate=%s, buildDirectory=%s%n",
-                reply.context, new String(reply.program), new String(reply.version), new String(reply.buildDate),
-                new String(reply.buildDirectory)));
+                reply.context, new String(reply.program, StandardCharsets.UTF_8),
+                new String(reply.version, StandardCharsets.UTF_8),
+                new String(reply.buildDate, StandardCharsets.UTF_8),
+                new String(reply.buildDirectory, StandardCharsets.UTF_8)));
     }
 
     private static void testEmptyBridgeDomainDump(final FutureJVppCoreFacade jvpp) throws Exception {
@@ -72,7 +75,7 @@ public class FutureApiTest {
     private static void testGetNodeIndex(final FutureJVppCoreFacade jvpp) {
         LOG.info("Sending GetNodeIndex request...");
         final GetNodeIndex request = new GetNodeIndex();
-        request.nodeName = "non-existing-node".getBytes();
+        request.nodeName = "non-existing-node".getBytes(StandardCharsets.UTF_8);
         final Future<GetNodeIndexReply> replyFuture = jvpp.getNodeIndex(request).toCompletableFuture();
         try {
             final GetNodeIndexReply reply = replyFuture.get();
@@ -88,7 +91,7 @@ public class FutureApiTest {
         LOG.info("Sending SwInterfaceDump request...");
         final SwInterfaceDump request = new SwInterfaceDump();
         request.nameFilterValid = 0;
-        request.nameFilter = "".getBytes();
+        request.nameFilter = "".getBytes(StandardCharsets.UTF_8);
 
         final Future<SwInterfaceDetailsReplyDump> replyFuture = jvpp.swInterfaceDump(request).toCompletableFuture();
         final SwInterfaceDetailsReplyDump reply = replyFuture.get();
@@ -97,7 +100,8 @@ public class FutureApiTest {
             LOG.info(
                 String.format("Received SwInterfaceDetails: interfaceName=%s, l2AddressLength=%d, adminUpDown=%d, "
                         + "linkUpDown=%d, linkSpeed=%d, linkMtu=%d%n",
-                    new String(details.interfaceName), details.l2AddressLength, details.adminUpDown,
+                    new String(details.interfaceName, StandardCharsets.UTF_8),
+                    details.l2AddressLength, details.adminUpDown,
                     details.linkUpDown, details.linkSpeed, (int) details.linkMtu));
         }
     }
index 74eb86a..391b25f 100644 (file)
@@ -24,6 +24,7 @@ import io.fd.vpp.jvpp.ioampot.JVppIoampotImpl;
 import io.fd.vpp.jvpp.ioampot.callback.PotProfileAddCallback;
 import io.fd.vpp.jvpp.ioampot.dto.PotProfileAdd;
 import io.fd.vpp.jvpp.ioampot.dto.PotProfileAddReply;
+import java.nio.charset.StandardCharsets;
 
 public class IoamPotApiTest {
 
@@ -62,8 +63,8 @@ public class IoamPotApiTest {
             request.maxBits = 53;
             request.lpc = 1234;
             request.polynomialPublic = 1234;
-            request.listNameLen = (byte)"test pot profile".getBytes().length;
-            request.listName = "test pot profile".getBytes();
+            request.listNameLen = (byte)"test pot profile".getBytes(StandardCharsets.UTF_8).length;
+            request.listName = "test pot profile".getBytes(StandardCharsets.UTF_8);
             final int result = jvpp.send(request);
             System.out.printf("PotProfileAdd send result = %d%n", result);