From d1291eb114dfc496ac4fee81108804e37d445ed5 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 26 Oct 2025 07:26:04 +0000 Subject: [PATCH 1/2] Initial plan From 58c6691c56758d0b40f38ce278819d9ff8f606ae Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 26 Oct 2025 07:31:00 +0000 Subject: [PATCH 2/2] Fix WSL2 file ownership IOException handling Co-authored-by: slachiewicz <6705942+slachiewicz@users.noreply.github.com> --- .../io/attributes/FileAttributes.java | 13 ++++++++++--- .../io/attributes/FileAttributesTest.java | 18 ++++++++++++++++++ 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/codehaus/plexus/components/io/attributes/FileAttributes.java b/src/main/java/org/codehaus/plexus/components/io/attributes/FileAttributes.java index d530790..214387c 100644 --- a/src/main/java/org/codehaus/plexus/components/io/attributes/FileAttributes.java +++ b/src/main/java/org/codehaus/plexus/components/io/attributes/FileAttributes.java @@ -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( diff --git a/src/test/java/org/codehaus/plexus/components/io/attributes/FileAttributesTest.java b/src/test/java/org/codehaus/plexus/components/io/attributes/FileAttributesTest.java index 3449f76..c77e09c 100644 --- a/src/test/java/org/codehaus/plexus/components/io/attributes/FileAttributesTest.java +++ b/src/test/java/org/codehaus/plexus/components/io/attributes/FileAttributesTest.java @@ -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; @@ -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(); + } + } }