You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by el...@apache.org on 2026/08/22 12:21:22 UTC

(maven-jarsigner) branch master updated: Fix isZipFile() to enforce null parameter contract (#104)

This is an automated email from the ASF dual-hosted git repository.

elharo pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/maven-jarsigner.git


The following commit(s) were added to refs/heads/master by this push:
     new 1715a4e  Fix isZipFile() to enforce null parameter contract (#104)
1715a4e is described below

commit 1715a4e2649539e76caa6ab6315cebe5f38049b1
Author: Elliotte Rusty Harold <el...@users.noreply.github.com>
AuthorDate: Sat Aug 22 08:21:16 2026 -0400

    Fix isZipFile() to enforce null parameter contract (#104)
    
    * Fix isZipFile() to enforce null parameter contract (#99)
    
    * merge
---
 src/main/java/org/apache/maven/shared/jarsigner/JarSignerUtil.java  | 4 ++++
 .../java/org/apache/maven/shared/jarsigner/JarSignerUtilTest.java   | 6 ++++++
 2 files changed, 10 insertions(+)

diff --git a/src/main/java/org/apache/maven/shared/jarsigner/JarSignerUtil.java b/src/main/java/org/apache/maven/shared/jarsigner/JarSignerUtil.java
index 7d587c6..ff45cc6 100644
--- a/src/main/java/org/apache/maven/shared/jarsigner/JarSignerUtil.java
+++ b/src/main/java/org/apache/maven/shared/jarsigner/JarSignerUtil.java
@@ -56,6 +56,10 @@ public class JarSignerUtil {
      * @return <code>true</code> if the file looks like a ZIP file, <code>false</code> otherwise.
      */
     public static boolean isZipFile(final File file) {
+        if (file == null) {
+            throw new NullPointerException("file");
+        }
+
         boolean result = false;
 
         try (JarFile jarFile = new JarFile(file)) {
diff --git a/src/test/java/org/apache/maven/shared/jarsigner/JarSignerUtilTest.java b/src/test/java/org/apache/maven/shared/jarsigner/JarSignerUtilTest.java
index e812f19..017440a 100644
--- a/src/test/java/org/apache/maven/shared/jarsigner/JarSignerUtilTest.java
+++ b/src/test/java/org/apache/maven/shared/jarsigner/JarSignerUtilTest.java
@@ -37,6 +37,7 @@ import org.junit.jupiter.api.io.TempDir;
 import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertFalse;
 import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
 import static org.junit.jupiter.api.Assertions.assertTrue;
 
 /**
@@ -96,6 +97,11 @@ class JarSignerUtilTest extends AbstractJarSignerTest {
         assertTrue(JarSignerUtil.isZipFile(executableJar));
     }
 
+    @Test
+    void isZipFileWithNull() {
+        assertThrows(NullPointerException.class, () -> JarSignerUtil.isZipFile(null));
+    }
+
     @Test
     void unsignArchiveConcurrent() throws Exception {
         File target = prepareTestJar("javax.persistence_2.0.5.v201212031355.jar");