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

olamy pushed a commit to branch maven-archiver-3.x
in repository https://gitbox.apache.org/repos/asf/maven-archiver.git


The following commit(s) were added to refs/heads/maven-archiver-3.x by this 
push:
     new 1289e57  Treat empty Automatic-Module-Name as no Automatic-Module-Name 
at all (3.x) (#280)
1289e57 is described below

commit 1289e5742fb94f222a41993da87d8f76d7f4ed62
Author: Fridrich Strba <fridr...@users.noreply.github.com>
AuthorDate: Thu Jul 24 10:55:03 2025 +0200

    Treat empty Automatic-Module-Name as no Automatic-Module-Name at all (3.x) 
(#280)
    
    * Treat empty Automatic-Module-Name as no Automatic-Module-Name at all
    
    * Add test case for empty Automatic-Module-Name attributes
---
 .../org/apache/maven/archiver/MavenArchiver.java   |  4 ++-
 .../apache/maven/archiver/MavenArchiverTest.java   | 30 +++++++++++++++++++++-
 2 files changed, 32 insertions(+), 2 deletions(-)

diff --git a/src/main/java/org/apache/maven/archiver/MavenArchiver.java 
b/src/main/java/org/apache/maven/archiver/MavenArchiver.java
index 5ea457e..f577273 100644
--- a/src/main/java/org/apache/maven/archiver/MavenArchiver.java
+++ b/src/main/java/org/apache/maven/archiver/MavenArchiver.java
@@ -597,7 +597,9 @@ public class MavenArchiver {
 
         String automaticModuleName = 
manifest.getMainSection().getAttributeValue("Automatic-Module-Name");
         if (automaticModuleName != null) {
-            if (!isValidModuleName(automaticModuleName)) {
+            if (automaticModuleName.isEmpty()) {
+                
manifest.getMainSection().removeAttribute("Automatic-Module-Name");
+            } else if (!isValidModuleName(automaticModuleName)) {
                 throw new ManifestException("Invalid automatic module name: '" 
+ automaticModuleName + "'");
             }
         }
diff --git a/src/test/java/org/apache/maven/archiver/MavenArchiverTest.java 
b/src/test/java/org/apache/maven/archiver/MavenArchiverTest.java
index 608f749..0e02e03 100644
--- a/src/test/java/org/apache/maven/archiver/MavenArchiverTest.java
+++ b/src/test/java/org/apache/maven/archiver/MavenArchiverTest.java
@@ -559,9 +559,37 @@ class MavenArchiverTest {
     }
 
     /*
-     * Test to make sure that manifest sections are present in the manifest 
prior to the archive has been created.
+     * Test to make sure that empty Automatic-Module-Name will result in no
+     * Automatic-Module-Name attribute at all, but that the archive will be 
created.
      */
     @Test
+    void testManifestWithEmptyAutomaticModuleName() throws Exception {
+        File jarFile = new File("target/test/dummy.jar");
+        JarArchiver jarArchiver = getCleanJarArchiver(jarFile);
+
+        MavenArchiver archiver = getMavenArchiver(jarArchiver);
+
+        MavenSession session = getDummySession();
+        MavenProject project = getDummyProject();
+        MavenArchiveConfiguration config = new MavenArchiveConfiguration();
+
+        Map<String, String> manifestEntries = new HashMap<>();
+        manifestEntries.put("Automatic-Module-Name", "");
+        config.setManifestEntries(manifestEntries);
+
+        archiver.createArchive(session, project, config);
+        assertThat(jarFile).exists();
+
+        final Manifest jarFileManifest = getJarFileManifest(jarFile);
+        Attributes manifest = jarFileManifest.getMainAttributes();
+
+        assertThat(manifest).doesNotContainKey(new 
Attributes.Name("Automatic-Module-Name"));
+    }
+
+    //
+    // Test to make sure that manifest sections are present in the manifest 
prior to the archive has been created.
+    //
+    @Test
     void testManifestSections() throws Exception {
         MavenArchiver archiver = new MavenArchiver();
 

Reply via email to