Skip to content

Commit

Permalink
NullPointerException during restore on Windows (#163)
Browse files Browse the repository at this point in the history
- 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 <[email protected]>
  • Loading branch information
nagyesta authored Feb 27, 2024
1 parent 12681ff commit 9d869d3
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -29,6 +30,7 @@ public class FileMetadata implements Comparable<FileMetadata> {
@NonNull
@JsonProperty("id")
private final UUID id;
@Nullable
@JsonProperty("file_system_key")
private final String fileSystemKey;
/**
Expand All @@ -42,6 +44,7 @@ public class FileMetadata implements Comparable<FileMetadata> {
* <br/>
* {@link com.github.nagyesta.filebarj.core.config.BackupJobConfiguration#getHashAlgorithm()}
*/
@Nullable
@JsonProperty("original_hash")
private final String originalHash;
/**
Expand Down Expand Up @@ -99,11 +102,13 @@ public class FileMetadata implements Comparable<FileMetadata> {
/**
* 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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 9d869d3

Please sign in to comment.