Use URLEncoder.encode(String, Charset) 89/97589/3 master
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 a1dc7b2..94793f6 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 ac59c8f..8efb2db 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 9959edf..b465fcc 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 695f34e..b63b732 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 8531501..d450425 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;
     }
 }