Use URLEncoder.encode(String, Charset) 89/97589/3
authorRobert Varga <robert.varga@pantheon.tech>
Tue, 21 Sep 2021 20:10:37 +0000 (22:10 +0200)
committerStephen Kitt <skitt@redhat.com>
Wed, 22 Sep 2021 10:03:24 +0000 (10:03 +0000)
We are running with Java 11 and as Modernizer correctly points out, we
can use direct charset variant which was introduced with Java 10. This
cuts down a tiny bit of dead code.

Change-Id: I7c42984bc1e05e94f5266f26e13aaab650ae4f70
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
opendaylight/md-sal/sal-akka-segmented-journal/pom.xml
opendaylight/md-sal/sal-akka-segmented-journal/src/main/java/org/opendaylight/controller/akka/segjournal/SegmentedFileJournal.java
opendaylight/md-sal/sal-clustering-commons/pom.xml
opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/persistence/LocalSnapshotStore.java
opendaylight/md-sal/sal-clustering-commons/src/test/java/org/opendaylight/controller/cluster/persistence/LocalSnapshotStoreTest.java

index a1dc7b279337c16e9185a94fc86d992f67cced07..94793f6e265ab7e8a73186f29d2f0ee398a5864b 100644 (file)
@@ -19,11 +19,6 @@ and is available at http://www.eclipse.org/legal/epl-v10.html
     <artifactId>sal-akka-segmented-journal</artifactId>
     <packaging>bundle</packaging>
 
-    <properties>
-        <!-- FIXME: Remove this -->
-        <odlparent.modernizer.enforce>false</odlparent.modernizer.enforce>
-    </properties>
-
     <dependencies>
         <!-- Akka -->
         <dependency>
index ac59c8fb41ea01bbc3deb7f1228087e621098057..8efb2db3ab5f3878c62c0934cdcb17732bc2b387 100644 (file)
@@ -21,7 +21,6 @@ import com.typesafe.config.ConfigMemorySize;
 import io.atomix.storage.StorageLevel;
 import io.atomix.storage.journal.SegmentedJournal;
 import java.io.File;
-import java.io.UnsupportedEncodingException;
 import java.net.URLEncoder;
 import java.nio.charset.StandardCharsets;
 import java.util.ArrayList;
@@ -117,7 +116,7 @@ public class SegmentedFileJournal extends AsyncWriteJournal {
     }
 
     private ActorRef createHandler(final String persistenceId) {
-        final String directoryName = encode(persistenceId);
+        final String directoryName = URLEncoder.encode(persistenceId, StandardCharsets.UTF_8);
         final File directory = new File(rootDir, directoryName);
         LOG.debug("Creating handler for {} in directory {}", persistenceId, directory);
 
@@ -142,16 +141,6 @@ public class SegmentedFileJournal extends AsyncWriteJournal {
         return message.promise.future();
     }
 
-    private static String encode(final String str) {
-        try {
-            return URLEncoder.encode(str, StandardCharsets.UTF_8.name());
-        } catch (UnsupportedEncodingException e) {
-            // Shouldn't happen
-            LOG.warn("Error encoding {}", str, e);
-            return str;
-        }
-    }
-
     private static int getBytes(final Config config, final String path, final int defaultValue) {
         if (!config.hasPath(path)) {
             return defaultValue;
index 9959edf2afc6880423e4c6e64d37a7e0df78c676..b465fccc863783490ecae2d281cf2e92dae3818f 100644 (file)
   <artifactId>sal-clustering-commons</artifactId>
   <packaging>bundle</packaging>
 
-  <properties>
-    <!-- FIXME: Remove this -->
-    <odlparent.modernizer.enforce>false</odlparent.modernizer.enforce>
-  </properties>
-
   <dependencies>
     <!-- Java -->
     <dependency>
index 695f34ecee5fe7647fc310ee6f6572512c6ae57f..b63b732f5bc99f5b97c552ee71af15c4ef700490 100644 (file)
@@ -28,7 +28,6 @@ import java.io.IOException;
 import java.io.InputStream;
 import java.io.ObjectInputStream;
 import java.io.ObjectOutputStream;
-import java.io.UnsupportedEncodingException;
 import java.net.URLDecoder;
 import java.net.URLEncoder;
 import java.nio.charset.StandardCharsets;
@@ -70,7 +69,7 @@ public class LocalSnapshotStore extends SnapshotStore {
     private final File snapshotDir;
 
     public LocalSnapshotStore(final Config config) {
-        this.executionContext = context().system().dispatchers().lookup(config.getString("stream-dispatcher"));
+        executionContext = context().system().dispatchers().lookup(config.getString("stream-dispatcher"));
         snapshotDir = new File(config.getString("dir"));
 
         final int localMaxLoadAttempts = config.getInt("max-load-attempts");
@@ -331,23 +330,11 @@ public class LocalSnapshotStore extends SnapshotStore {
     }
 
     private static String encode(final String str) {
-        try {
-            return URLEncoder.encode(str, StandardCharsets.UTF_8.name());
-        } catch (UnsupportedEncodingException e) {
-            // Shouldn't happen
-            LOG.warn("Error encoding {}", str, e);
-            return str;
-        }
+        return URLEncoder.encode(str, StandardCharsets.UTF_8);
     }
 
     private static String decode(final String str) {
-        try {
-            return URLDecoder.decode(str, StandardCharsets.UTF_8.name());
-        } catch (final UnsupportedEncodingException e) {
-            // Shouldn't happen
-            LOG.warn("Error decoding {}", str, e);
-            return str;
-        }
+        return URLDecoder.decode(str, StandardCharsets.UTF_8);
     }
 
     @VisibleForTesting
index 8531501fa2f0c027d322d0ecc8570accd1d939b5..d45042567d9fa16d2b2a5b1ec2dc49038c405581 100644 (file)
@@ -32,7 +32,6 @@ import com.typesafe.config.ConfigFactory;
 import java.io.File;
 import java.io.FileOutputStream;
 import java.io.IOException;
-import java.io.UnsupportedEncodingException;
 import java.net.URLEncoder;
 import java.nio.charset.StandardCharsets;
 import org.apache.commons.io.FileUtils;
@@ -196,9 +195,7 @@ public class LocalSnapshotStoreTest {
         }
     }
 
-    private static String toSnapshotName(final String persistenceId, final int seqNr, final int timestamp)
-            throws UnsupportedEncodingException {
-        final String encodedPersistenceId = URLEncoder.encode(persistenceId, StandardCharsets.UTF_8.name());
-        return "snapshot-" + encodedPersistenceId + "-" + seqNr + "-" + timestamp;
+    private static String toSnapshotName(final String persistenceId, final int seqNr, final int timestamp) {
+        return "snapshot-" + URLEncoder.encode(persistenceId, StandardCharsets.UTF_8) + "-" + seqNr + "-" + timestamp;
     }
 }