From f9d6c1e7d6d9e8fa80d87d9c8d7cf35cc5c9943e Mon Sep 17 00:00:00 2001 From: Martin Panzer Date: Sat, 28 Feb 2026 20:23:32 +0100 Subject: [PATCH] Fix NPE when reading posixfileattributes on windows This only appeared in 17.0.2 (or lower 17er) on windows, so run ci against this version. --- .github/workflows/maven.yml | 8 ++++++++ .../archiver/jar/JarToolModularJarArchiver.java | 13 +++++++++---- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index fb8795b4..26ff93d8 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -23,6 +23,14 @@ jobs: build: name: Build it uses: codehaus-plexus/.github/.github/workflows/maven.yml@master + with: + # Execute on a jdk between 17 and 17.0.2 to explicitly test workaround for jar tool --date support not present in that version + # See org.codehaus.plexus.archiver.jar.JarToolModularJarArchiver.isJarDateOptionSupported + # https://github.com/codehaus-plexus/plexus-archiver/issues/164 + matrix-include: > + [ + {"jdk": "17.0.2", "os": "windows-latest", distribution: "zulu" } + ] # deploy: # name: Deploy diff --git a/src/main/java/org/codehaus/plexus/archiver/jar/JarToolModularJarArchiver.java b/src/main/java/org/codehaus/plexus/archiver/jar/JarToolModularJarArchiver.java index 2510a81c..bbda89c3 100644 --- a/src/main/java/org/codehaus/plexus/archiver/jar/JarToolModularJarArchiver.java +++ b/src/main/java/org/codehaus/plexus/archiver/jar/JarToolModularJarArchiver.java @@ -153,9 +153,14 @@ protected void postCreateArchive() throws ArchiverException { private void fixLastModifiedTimeZipEntries() throws IOException { long timeMillis = getLastModifiedTime().toMillis(); Path destFile = getDestFile().toPath(); - PosixFileAttributes posixFileAttributes = Files.getFileAttributeView( - destFile, PosixFileAttributeView.class, LinkOption.NOFOLLOW_LINKS) - .readAttributes(); + PosixFileAttributeView view = + Files.getFileAttributeView(destFile, PosixFileAttributeView.class, LinkOption.NOFOLLOW_LINKS); + + PosixFileAttributes posixFileAttributes = null; + if (view != null) { + posixFileAttributes = view.readAttributes(); + } + FileAttribute[] attributes; if (posixFileAttributes != null) { attributes = new FileAttribute[1]; @@ -272,7 +277,7 @@ private static FileTime revertToLocalTime(FileTime time) { } /** - * Check support for {@code --date} option introduced since Java 17.0.3 (JDK-8279925). + * Check support for {@code --date} option introduced since Java 17.0.3 with JDK-8277755. * * @return true if the JAR tool supports the {@code --date} option */