Skip to content

Commit efc8e57

Browse files
committed
Avoid spotbugs warning
1 parent 866a112 commit efc8e57

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

graalpython/org.graalvm.python.embedding/src/org/graalvm/python/embedding/VirtualFileSystemImpl.java

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -540,17 +540,26 @@ private void initEntries() {
540540
checkPlatform();
541541
}
542542
if (extractFilter != null) {
543-
String wheelMetadataSuffix = ".dist-info" + getSeparator() + "RECORD";
544543
for (BaseEntry entry : vfsEntries.values()) {
545-
if (entry instanceof FileEntry fileEntry && fileEntry.getPlatformPath().endsWith(wheelMetadataSuffix)) {
546-
Path baseDir = Paths.get(fileEntry.getPlatformPath()).getParent().getParent();
547-
try (BufferedReader is = new BufferedReader(new InputStreamReader(getResourceUrl(fileEntry.getResourcePath()).openStream()))) {
544+
Path baseDir = null;
545+
if (entry instanceof FileEntry fileEntry) {
546+
Path path = Paths.get(fileEntry.getPlatformPath());
547+
Path name = path.getFileName();
548+
if (name != null && name.endsWith("RECORD")) {
549+
Path distInfo = path.getParent();
550+
if (distInfo != null && distInfo.toString().endsWith(".dist-info")) {
551+
baseDir = distInfo.getParent();
552+
}
553+
}
554+
}
555+
if (baseDir != null) {
556+
try (BufferedReader is = new BufferedReader(new InputStreamReader(getResourceUrl(entry.getResourcePath()).openStream()))) {
548557
String line;
549558
List<FileEntry> extractedTogether = new ArrayList<>();
550559
while ((line = is.readLine()) != null) {
551560
int commaIndex = line.indexOf(',');
552561
if (commaIndex < 0) {
553-
warn("Failed to parse wheel entry in record file %s: %s", fileEntry.getPlatformPath(), line);
562+
warn("Failed to parse wheel entry in record file %s: %s", entry.getPlatformPath(), line);
554563
continue;
555564
}
556565
Path platformPath = baseDir.resolve(line.substring(0, commaIndex).replace("/", PLATFORM_SEPARATOR));
@@ -559,7 +568,7 @@ private void initEntries() {
559568
if (extractableEntry instanceof FileEntry extractableFileEntry) {
560569
extractedTogether.add(extractableFileEntry);
561570
} else {
562-
warn("Could not find file referred from wheel record file %s: %s", fileEntry.getPlatformPath(), platformPath);
571+
warn("Could not find file referred from wheel record file %s: %s", entry.getPlatformPath(), platformPath);
563572
}
564573
}
565574
}
@@ -571,7 +580,7 @@ private void initEntries() {
571580
} catch (IOException ex) {
572581
// This is just best-effort attempt at guessing which libraries to extract
573582
// together, ignore errors
574-
warn("Exception when reading wheel record file %s: %s", fileEntry.getPlatformPath(), ex);
583+
warn("Exception when reading wheel record file %s: %s", entry.getPlatformPath(), ex);
575584
}
576585
}
577586
}

0 commit comments

Comments
 (0)