You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by sl...@apache.org on 2026/09/10 21:40:01 UTC

(maven-javadoc-plugin) branch master updated: Treat an empty release value as unset

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

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


The following commit(s) were added to refs/heads/master by this push:
     new 75b1cf7b Treat an empty release value as unset
75b1cf7b is described below

commit 75b1cf7b6f5ed3c75da206cf5ef02e37821fffd6
Author: Sylwester Lachiewicz <sl...@apache.org>
AuthorDate: Thu Sep 10 22:49:45 2026 +0200

    Treat an empty release value as unset
    
    An empty string is what Maven injects for a declared but blank
    maven.compiler.release, which is how a child of org.apache:apache:32
    or later gets javac back onto source/target. maven-compiler-plugin
    already treats that value as unset; the javadoc mojo checked only for
    null and crashed in getDefaultJavadocApiLink.
    
    Fixes #1376
---
 .../maven/plugins/javadoc/AbstractJavadocMojo.java | 17 +++++++++---
 .../plugins/javadoc/AbstractJavadocMojoTest.java   | 31 ++++++++++++++++++++++
 2 files changed, 44 insertions(+), 4 deletions(-)

diff --git a/src/main/java/org/apache/maven/plugins/javadoc/AbstractJavadocMojo.java b/src/main/java/org/apache/maven/plugins/javadoc/AbstractJavadocMojo.java
index a4350365..2214137b 100644
--- a/src/main/java/org/apache/maven/plugins/javadoc/AbstractJavadocMojo.java
+++ b/src/main/java/org/apache/maven/plugins/javadoc/AbstractJavadocMojo.java
@@ -2099,7 +2099,7 @@ public abstract class AbstractJavadocMojo extends AbstractMojo {
             // or source values specified
             boolean autoExclude = legacyMode;
             if (!autoExclude) {
-                if (release != null) {
+                if (isReleaseSet()) {
                     autoExclude = JavaVersion.parse(release).isBefore("9");
                 } else if (source != null) {
                     autoExclude = JavaVersion.parse(source).isBefore("9");
@@ -4334,7 +4334,7 @@ public abstract class AbstractJavadocMojo extends AbstractMojo {
 
         if (supportModulePath) {
             supportModulePath &= javadocRuntimeVersion.isAtLeast("9");
-            if (release != null) {
+            if (isReleaseSet()) {
                 supportModulePath &= JavaVersion.parse(release).isAtLeast("9");
             } else if (source != null) {
                 supportModulePath &= JavaVersion.parse(source).isAtLeast("9");
@@ -4579,7 +4579,7 @@ public abstract class AbstractJavadocMojo extends AbstractMojo {
 
         addArgIf(arguments, quiet, "-quiet");
 
-        if (javadocRuntimeVersion.isAtLeast("9") && release != null) {
+        if (javadocRuntimeVersion.isAtLeast("9") && isReleaseSet()) {
             arguments.add("--release");
             arguments.add(release);
         } else {
@@ -5509,7 +5509,7 @@ public abstract class AbstractJavadocMojo extends AbstractMojo {
         }
 
         final JavaVersion javaApiversion;
-        if (release != null) {
+        if (isReleaseSet()) {
             javaApiversion = JavaVersion.parse(release);
         } else if (source != null && !source.isEmpty()) {
             javaApiversion = JavaVersion.parse(source);
@@ -5833,6 +5833,15 @@ public abstract class AbstractJavadocMojo extends AbstractMojo {
         return null;
     }
 
+    /**
+     * Whether an explicit {@code release} is configured. A blank value, which Maven injects when
+     * {@code maven.compiler.release} is declared but empty, counts as unset so that {@code source}
+     * applies instead, matching maven-compiler-plugin.
+     */
+    private boolean isReleaseSet() {
+        return release != null && !release.isEmpty();
+    }
+
     /**
      * Construct the output file for the generated javadoc-options XML file, after creating the
      * javadocOptionsDir if necessary. This method does NOT write to the file in question.
diff --git a/src/test/java/org/apache/maven/plugins/javadoc/AbstractJavadocMojoTest.java b/src/test/java/org/apache/maven/plugins/javadoc/AbstractJavadocMojoTest.java
index c9a577ec..0714da15 100644
--- a/src/test/java/org/apache/maven/plugins/javadoc/AbstractJavadocMojoTest.java
+++ b/src/test/java/org/apache/maven/plugins/javadoc/AbstractJavadocMojoTest.java
@@ -19,11 +19,15 @@
 package org.apache.maven.plugins.javadoc;
 
 import java.io.File;
+import java.nio.file.Path;
 
 import org.apache.maven.plugin.logging.Log;
+import org.apache.maven.plugins.javadoc.options.OfflineLink;
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.io.TempDir;
 
+import static org.apache.maven.api.plugin.testing.MojoExtension.setVariableValueToObject;
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.mockito.ArgumentMatchers.anyString;
 import static org.mockito.Mockito.mock;
@@ -112,4 +116,31 @@ class AbstractJavadocMojoTest {
         assertThat(AbstractJavadocMojo.toRelative(basedir, basedir.getPath() + "\\src\\site"))
                 .isEqualTo("src/site");
     }
+
+    @Test
+    void emptyReleaseFallsBackToSourceForTheApiLink(@TempDir Path optionsDir) throws Exception {
+        setVariableValueToObject(mojo, "detectJavaApiLink", true);
+        setVariableValueToObject(mojo, "javadocOptionsDir", optionsDir.toFile());
+        // what Maven injects for a declared but blank maven.compiler.release
+        setVariableValueToObject(mojo, "release", "");
+        setVariableValueToObject(mojo, "source", "11");
+
+        OfflineLink link = mojo.getDefaultJavadocApiLink();
+
+        assertThat(link).isNotNull();
+        assertThat(link.getUrl()).isEqualTo("https://docs.oracle.com/en/java/javase/11/docs/api/");
+    }
+
+    @Test
+    void releaseWinsOverSourceForTheApiLink(@TempDir Path optionsDir) throws Exception {
+        setVariableValueToObject(mojo, "detectJavaApiLink", true);
+        setVariableValueToObject(mojo, "javadocOptionsDir", optionsDir.toFile());
+        setVariableValueToObject(mojo, "release", "11");
+        setVariableValueToObject(mojo, "source", "17");
+
+        OfflineLink link = mojo.getDefaultJavadocApiLink();
+
+        assertThat(link).isNotNull();
+        assertThat(link.getUrl()).isEqualTo("https://docs.oracle.com/en/java/javase/11/docs/api/");
+    }
 }