Skip to content

Commit

Permalink
#435 Add null check when getting and applying Windows file attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
srikanth-lingala committed Jun 16, 2022
1 parent 98aaf45 commit 5f51b67
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/main/java/net/lingala/zip4j/util/FileUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,15 @@ private static void applyWindowsFileAttributes(Path file, byte[] fileAttributes)
}

DosFileAttributeView fileAttributeView = Files.getFileAttributeView(file, DosFileAttributeView.class, LinkOption.NOFOLLOW_LINKS);

//IntelliJ complains that fileAttributes can never be null. But apparently it can.
//See https://github.com/srikanth-lingala/zip4j/issues/435
//Even the javadoc of Files.getFileAttributeView says it can be null
//noinspection ConstantConditions
if (fileAttributes == null) {
return;
}

try {
fileAttributeView.setReadOnly(isBitSet(fileAttributes[0], 0));
fileAttributeView.setHidden(isBitSet(fileAttributes[0], 1));
Expand Down Expand Up @@ -511,6 +520,11 @@ private static byte[] getWindowsFileAttributes(Path file) {
try {
DosFileAttributeView dosFileAttributeView = Files.getFileAttributeView(file, DosFileAttributeView.class,
LinkOption.NOFOLLOW_LINKS);

if (dosFileAttributeView == null) {
return fileAttributes;
}

DosFileAttributes dosFileAttributes = dosFileAttributeView.readAttributes();

byte windowsAttribute = 0;
Expand Down

0 comments on commit 5f51b67

Please sign in to comment.