From 55cfa50d1ce8b82361c789836416e262109da3a3 Mon Sep 17 00:00:00 2001 From: Suraj Singh Date: Mon, 5 Jun 2023 11:03:13 -0700 Subject: [PATCH] Resolve forbidden APIs Signed-off-by: Suraj Singh --- .../replication/SegmentReplicationIT.java | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/server/src/internalClusterTest/java/org/opensearch/indices/replication/SegmentReplicationIT.java b/server/src/internalClusterTest/java/org/opensearch/indices/replication/SegmentReplicationIT.java index 952cf8ba3b0ec..2af24af513b9e 100644 --- a/server/src/internalClusterTest/java/org/opensearch/indices/replication/SegmentReplicationIT.java +++ b/server/src/internalClusterTest/java/org/opensearch/indices/replication/SegmentReplicationIT.java @@ -43,6 +43,7 @@ import org.opensearch.cluster.routing.ShardRouting; import org.opensearch.cluster.routing.ShardRoutingState; import org.opensearch.cluster.routing.allocation.command.CancelAllocationCommand; +import org.opensearch.common.io.PathUtils; import org.opensearch.common.io.stream.NamedWriteableRegistry; import org.opensearch.common.lease.Releasable; import org.opensearch.common.lucene.index.OpenSearchDirectoryReader; @@ -71,12 +72,13 @@ import org.opensearch.test.transport.MockTransportService; import org.opensearch.transport.TransportService; -import java.io.File; import java.io.IOException; +import java.net.URISyntaxException; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.List; +import java.util.Locale; import java.util.Map; import java.util.Set; import java.util.TreeSet; @@ -1352,15 +1354,12 @@ private String getOlderLuceneCodec() throws IOException { final TreeSet codecNames = new TreeSet<>(); ZipInputStream zip = new ZipInputStream(Codec.class.getProtectionDomain().getCodeSource().getLocation().openStream()); Pattern pattern = Pattern.compile("lucene[0-9]+"); - while (true) { - ZipEntry e = zip.getNextEntry(); - if (e == null) break; - // Filter lucene codec names from directory - if (e.isDirectory()) { + for (ZipEntry entry = zip.getNextEntry(); entry != null; entry = zip.getNextEntry()) { + if (entry.isDirectory()) { // Remove trailing file separator from path i.e. '../lucene94/' -> '../lucene94' - final String dirPath = e.getName().substring(0, e.getName().length() - 1); + final String dirPath = entry.getName().substring(0, entry.getName().length() - 1); // Fetch name i.e. '../lucene94' -> 'lucene94' - final String dirName = dirPath.substring(dirPath.lastIndexOf(File.separator) + 1); + final String dirName = dirPath.substring(dirPath.lastIndexOf(PathUtils.getDefaultFileSystem().getSeparator()) + 1); Matcher matcher = pattern.matcher(dirName); if (matcher.matches()) { codecNames.add(dirName); @@ -1370,6 +1369,6 @@ private String getOlderLuceneCodec() throws IOException { logger.debug("--> Older lucene codecs {}", codecNames); String oldestSupportedCodec = codecNames.pollFirst(); // Get actual lucene codec class name i.e. lucene90 -> Lucene90 - return oldestSupportedCodec.substring(0, 1).toUpperCase() + oldestSupportedCodec.substring(1); + return oldestSupportedCodec.substring(0, 1).toUpperCase(Locale.getDefault()) + oldestSupportedCodec.substring(1); } }