Skip to content

Commit 937b92b

Browse files
authored
Fix NPE when reading posixfileattributes on windows (#419)
This only appeared in 17.0.2 (or lower 17er) on windows, so run ci against this version.
1 parent 08ae7e3 commit 937b92b

2 files changed

Lines changed: 17 additions & 4 deletions

File tree

.github/workflows/maven.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,14 @@ jobs:
2323
build:
2424
name: Build it
2525
uses: codehaus-plexus/.github/.github/workflows/maven.yml@master
26+
with:
27+
# Execute on a jdk between 17 and 17.0.2 to explicitly test workaround for jar tool --date support not present in that version
28+
# See org.codehaus.plexus.archiver.jar.JarToolModularJarArchiver.isJarDateOptionSupported
29+
# https://github.com/codehaus-plexus/plexus-archiver/issues/164
30+
matrix-include: >
31+
[
32+
{"jdk": "17.0.2", "os": "windows-latest", distribution: "zulu" }
33+
]
2634
2735
# deploy:
2836
# name: Deploy

src/main/java/org/codehaus/plexus/archiver/jar/JarToolModularJarArchiver.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -153,9 +153,14 @@ protected void postCreateArchive() throws ArchiverException {
153153
private void fixLastModifiedTimeZipEntries() throws IOException {
154154
long timeMillis = getLastModifiedTime().toMillis();
155155
Path destFile = getDestFile().toPath();
156-
PosixFileAttributes posixFileAttributes = Files.getFileAttributeView(
157-
destFile, PosixFileAttributeView.class, LinkOption.NOFOLLOW_LINKS)
158-
.readAttributes();
156+
PosixFileAttributeView view =
157+
Files.getFileAttributeView(destFile, PosixFileAttributeView.class, LinkOption.NOFOLLOW_LINKS);
158+
159+
PosixFileAttributes posixFileAttributes = null;
160+
if (view != null) {
161+
posixFileAttributes = view.readAttributes();
162+
}
163+
159164
FileAttribute<?>[] attributes;
160165
if (posixFileAttributes != null) {
161166
attributes = new FileAttribute<?>[1];
@@ -272,7 +277,7 @@ private static FileTime revertToLocalTime(FileTime time) {
272277
}
273278

274279
/**
275-
* Check support for {@code --date} option introduced since Java 17.0.3 (JDK-8279925).
280+
* Check support for {@code --date} option introduced since Java 17.0.3 with <a href="https://bugs.openjdk.org/browse/JDK-8277755">JDK-8277755</a>.
276281
*
277282
* @return true if the JAR tool supports the {@code --date} option
278283
*/

0 commit comments

Comments
 (0)