Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,16 @@ public FileAttributes(@Nonnull Path path, boolean followLinks) throws IOExceptio
this.lastModifiedTime = (FileTime) attrs.get("lastModifiedTime");
}

private static String getPrincipalName(Path path, String attribute) throws IOException {
Object owner = Files.getAttribute(path, attribute, LinkOption.NOFOLLOW_LINKS);
return ((Principal) owner).getName();
@Nullable
private static String getPrincipalName(Path path, String attribute) {
try {
Object owner = Files.getAttribute(path, attribute, LinkOption.NOFOLLOW_LINKS);
return ((Principal) owner).getName();
} catch (IOException e) {
// Some file systems (e.g., WSL2 mapped network drives) don't provide ownership information
// Return null instead of propagating the exception
return null;
}
}

public FileAttributes(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
*/

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.DisabledOnOs;
Expand All @@ -35,4 +37,20 @@ void testGetPosixFileAttributes() throws Exception {
PlexusIoResourceAttributes fa = new FileAttributes(file);
assertNotNull(fa);
}

@Test
void testFileAttributesHandlesIOException() throws IOException {
// Test that FileAttributes can be constructed for a regular file
// even if ownership information is not available (e.g., WSL2 mapped network drives)
File tempFile = Files.createTempFile("plexus-io-test", ".tmp").toFile();
try {
// This should not throw even if ownership info is unavailable
PlexusIoResourceAttributes fa = new FileAttributes(tempFile);
assertNotNull(fa);
// The attributes object should be usable even if userName/groupName are null
assertNotNull(fa.toString());
} finally {
tempFile.delete();
}
}
}
Loading