Fix FB suppression 64/103164/1
authorRobert Varga <robert.varga@pantheon.tech>
Tue, 8 Nov 2022 20:16:48 +0000 (21:16 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Tue, 8 Nov 2022 20:24:45 +0000 (21:24 +0100)
Once we have a ByteSource, use it of a CharSource of UTF8 before
reading it. This is the proper way of getting a String.

Change-Id: Ifd92fe561b5864791b77342a3c9352ac23bd5048
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
netconf/tools/netconf-testtool/src/main/java/org/opendaylight/netconf/test/tool/NetconfDeviceSimulator.java

index c776114b72d6aa30eb3df6dcf6e5962f67122642..8407b94064082f1a14aec37d3ff05b424fa8a7dc 100644 (file)
@@ -10,7 +10,6 @@ package org.opendaylight.netconf.test.tool;
 import com.google.common.collect.Collections2;
 import com.google.common.util.concurrent.Futures;
 import com.google.common.util.concurrent.ThreadFactoryBuilder;
-import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
 import io.netty.channel.Channel;
 import io.netty.channel.ChannelFuture;
 import io.netty.channel.local.LocalAddress;
@@ -23,6 +22,7 @@ import java.net.Inet4Address;
 import java.net.InetSocketAddress;
 import java.net.UnknownHostException;
 import java.nio.channels.AsynchronousChannelGroup;
+import java.nio.charset.StandardCharsets;
 import java.util.ArrayList;
 import java.util.HashSet;
 import java.util.List;
@@ -72,9 +72,7 @@ import org.opendaylight.yangtools.yang.parser.rfc7950.repo.TextToIRTransformer;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-@SuppressFBWarnings("DM_DEFAULT_ENCODING")
 public class NetconfDeviceSimulator implements Closeable {
-
     private static final Logger LOG = LoggerFactory.getLogger(NetconfDeviceSimulator.class);
 
     private final NioEventLoopGroup nettyThreadgroup;
@@ -348,8 +346,9 @@ public class NetconfDeviceSimulator implements Closeable {
         final SourceIdentifier moduleSourceIdentifier = new SourceIdentifier(module.getName(),
             module.getRevision().map(Revision::toString).orElse(null));
         try {
-            final String moduleContent = new String(
-                consumer.getSchemaSource(moduleSourceIdentifier, YangTextSchemaSource.class).get().read());
+
+            final String moduleContent = consumer.getSchemaSource(moduleSourceIdentifier, YangTextSchemaSource.class)
+                .get().asCharSource(StandardCharsets.UTF_8).read();
             capabilities.add(new YangModuleCapability(module, moduleContent));
             //IOException would be thrown in creating SchemaContext already
         } catch (final ExecutionException | InterruptedException | IOException e) {