Skip to content

Commit

Permalink
Resolve forbidden APIs
Browse files Browse the repository at this point in the history
Signed-off-by: Suraj Singh <[email protected]>
  • Loading branch information
dreamer-89 committed Jun 5, 2023
1 parent d78745a commit 55cfa50
Showing 1 changed file with 8 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -1352,15 +1354,12 @@ private String getOlderLuceneCodec() throws IOException {
final TreeSet<String> 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);
Expand All @@ -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);
}
}

0 comments on commit 55cfa50

Please sign in to comment.