Skip to content

Commit

Permalink
refactor cleanup and ignore spotbugs false positives
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewazores committed Feb 7, 2022
1 parent d8fcd8d commit 5acba12
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions src/main/java/io/cryostat/recordings/RecordingArchiveHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@
import io.cryostat.rules.ArchivedRecordingInfo;
import io.cryostat.util.URIUtil;

import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import org.apache.commons.codec.binary.Base32;

public class RecordingArchiveHelper {
Expand Down Expand Up @@ -121,6 +122,10 @@ public class RecordingArchiveHelper {
this.base32 = base32;
}

@SuppressFBWarnings(
value = "NP_NULL_ON_SOME_PATH_FROM_RETURN_VALUE",
justification =
"SpotBugs false positive. validateSavePath() ensures that the getParent() and getFileName() of the Path are not null, barring some exceptional circumstance like some external filesystem access race.")
public Future<ArchivedRecordingInfo> saveRecording(
ConnectionDescriptor connectionDescriptor, String recordingName) {

Expand All @@ -143,9 +148,9 @@ public Future<ArchivedRecordingInfo> saveRecording(
}
},
false);
validateSavePath(recordingName, savePath);
Path parentPath = savePath.getParent();
Path filenamePath = savePath.getFileName();
validateSavePath(recordingName, parentPath, filenamePath);
String filename = filenamePath.toString();
ArchivedRecordingInfo archivedRecordingInfo =
new ArchivedRecordingInfo(
Expand Down Expand Up @@ -173,16 +178,20 @@ public Future<ArchivedRecordingInfo> saveRecording(
return future;
}

@SuppressFBWarnings(
value = "NP_NULL_ON_SOME_PATH_FROM_RETURN_VALUE",
justification =
"SpotBugs false positive. validateSavePath() ensures that the getParent() and getFileName() of the Path are not null, barring some exceptional circumstance like some external filesystem access race.")
public Future<ArchivedRecordingInfo> deleteRecording(String recordingName) {

CompletableFuture<ArchivedRecordingInfo> future = new CompletableFuture<>();

try {
Path archivedRecording = getRecordingPath(recordingName).get();
fs.deleteIfExists(archivedRecording);
validateSavePath(recordingName, archivedRecording);
Path parentPath = archivedRecording.getParent();
Path filenamePath = archivedRecording.getFileName();
validateSavePath(recordingName, filenamePath, filenamePath);
String filename = filenamePath.toString();
ArchivedRecordingInfo archivedRecordingInfo =
new ArchivedRecordingInfo(
Expand All @@ -207,14 +216,13 @@ public Future<ArchivedRecordingInfo> deleteRecording(String recordingName) {
return future;
}

private void validateSavePath(String recordingName, Path parentPath, Path filenamePath)
throws IOException {
if (parentPath == null) {
private void validateSavePath(String recordingName, Path path) throws IOException {
if (path.getParent() == null) {
throw new IOException(
String.format(
"Filesystem parent for %s could not be determined", recordingName));
}
if (filenamePath == null) {
if (path.getFileName() == null) {
throw new IOException(
String.format("Filesystem path for %s could not be determined", recordingName));
}
Expand Down

0 comments on commit 5acba12

Please sign in to comment.