From 9d869d3130b441b5585f7e0a095a5d7d65f20d2e Mon Sep 17 00:00:00 2001 From: Esta Nagy Date: Tue, 27 Feb 2024 22:02:39 +0100 Subject: [PATCH] NullPointerException during restore on Windows (#163) - Fixes the source of the NPE - Marks nullable fields of the affected type with annotations to allow static analysis to discover similar issues Resolves #162 {patch} Signed-off-by: Esta Nagy --- .../github/nagyesta/filebarj/core/model/FileMetadata.java | 5 +++++ .../filebarj/core/restore/pipeline/RestorePipeline.java | 3 ++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/file-barj-core/src/main/java/com/github/nagyesta/filebarj/core/model/FileMetadata.java b/file-barj-core/src/main/java/com/github/nagyesta/filebarj/core/model/FileMetadata.java index 0a04588..eb7d46f 100644 --- a/file-barj-core/src/main/java/com/github/nagyesta/filebarj/core/model/FileMetadata.java +++ b/file-barj-core/src/main/java/com/github/nagyesta/filebarj/core/model/FileMetadata.java @@ -9,6 +9,7 @@ import lombok.Data; import lombok.NonNull; import lombok.extern.jackson.Jacksonized; +import org.jetbrains.annotations.Nullable; import java.io.IOException; import java.io.InputStream; @@ -29,6 +30,7 @@ public class FileMetadata implements Comparable { @NonNull @JsonProperty("id") private final UUID id; + @Nullable @JsonProperty("file_system_key") private final String fileSystemKey; /** @@ -42,6 +44,7 @@ public class FileMetadata implements Comparable { *
* {@link com.github.nagyesta.filebarj.core.config.BackupJobConfiguration#getHashAlgorithm()} */ + @Nullable @JsonProperty("original_hash") private final String originalHash; /** @@ -99,11 +102,13 @@ public class FileMetadata implements Comparable { /** * The Id of the archive metadata for the entity storing this file. */ + @Nullable @JsonProperty("archive_metadata_id") private UUID archiveMetadataId; /** * An optional error message in case of blocker issues during backup. */ + @Nullable @JsonProperty("error") private String error; diff --git a/file-barj-core/src/main/java/com/github/nagyesta/filebarj/core/restore/pipeline/RestorePipeline.java b/file-barj-core/src/main/java/com/github/nagyesta/filebarj/core/restore/pipeline/RestorePipeline.java index 45639c6..00746cb 100644 --- a/file-barj-core/src/main/java/com/github/nagyesta/filebarj/core/restore/pipeline/RestorePipeline.java +++ b/file-barj-core/src/main/java/com/github/nagyesta/filebarj/core/restore/pipeline/RestorePipeline.java @@ -292,7 +292,8 @@ protected void copyRestoredFileToRemainingLocations( final var copy = restoreTargets.mapToRestorePath(file.getAbsolutePath()); try { deleteIfExists(copy); - if (original.getFileSystemKey().equals(file.getFileSystemKey())) { + final var originalFileSystemKey = original.getFileSystemKey(); + if (originalFileSystemKey != null && originalFileSystemKey.equals(file.getFileSystemKey())) { Files.createLink(copy, unpackedFile); } else { Files.copy(unpackedFile, copy);