Skip to content

Commit

Permalink
Resolve forbidden APIs due to inputstream
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 55cfa50 commit 623eaa8
Showing 1 changed file with 11 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@

import java.io.IOException;
import java.net.URISyntaxException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
Expand Down Expand Up @@ -1350,16 +1352,17 @@ public void testWithOlderCodecs() throws Exception {

// Return oldest lucene codec name. It does this by iterating throw all directories under lucene library and filter
// ones matching lucene codec name regex
private String getOlderLuceneCodec() throws IOException {
private String getOlderLuceneCodec() throws IOException, URISyntaxException {
final TreeSet<String> codecNames = new TreeSet<>();
ZipInputStream zip = new ZipInputStream(Codec.class.getProtectionDomain().getCodeSource().getLocation().openStream());
final String separator = PathUtils.getDefaultFileSystem().getSeparator();
Pattern pattern = Pattern.compile("lucene[0-9]+");
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 = entry.getName().substring(0, entry.getName().length() - 1);
// Fetch name i.e. '../lucene94' -> 'lucene94'
final String dirName = dirPath.substring(dirPath.lastIndexOf(PathUtils.getDefaultFileSystem().getSeparator()) + 1);
Path luceneJarPath = PathUtils.get(Codec.class.getProtectionDomain().getCodeSource().getLocation().toURI());
try (var fileIn = Files.newInputStream(luceneJarPath)) {
ZipInputStream zip = new ZipInputStream(fileIn);
for (ZipEntry entry = zip.getNextEntry(); entry != null; entry = zip.getNextEntry()) {
final String dirPath = entry.getName();
// Fetch name i.e. '../lucene94/' -> 'lucene94'
final String dirName = dirPath.substring(dirPath.lastIndexOf(separator, dirPath.length() - 2) + 1, dirPath.length() - 1);
Matcher matcher = pattern.matcher(dirName);
if (matcher.matches()) {
codecNames.add(dirName);
Expand Down

0 comments on commit 623eaa8

Please sign in to comment.