java:S7476, S1123, and S1133 mis-handle Java 23 Markdown Javadoc (///) comments

Product: SonarQube Community (self-hosted)
sonar-java version: sonar-java 8.28.0.43176 on SonarQube Community Build 26.4.0.121862
Java source level: 21 (javac 21, source/target 17)

Rule

java:S7476 — A single-line comment should start with exactly two slashes, no more.
(also affects java:S1123 and java:S1133, which misfire on the same construct)

Description

SonarJava does not support Java 23 Markdown documentation comments (///). It treats them as malformed single-line comments instead of Javadoc, which causes cascading false positives: S7476 flags the comment syntax, while S1123 and S1133 fail to recognize the valid @deprecated documentation inside the Markdown Javadoc. The equivalent traditional /** ... */ Javadoc does not trigger these issues.

Reproducer

package demo;

/// Legacy calculator utility.
/// Provides basic arithmetic helpers.
public class Sample {

    /// Adds two integers.
    ///
    /// @param a first operand
    /// @param b second operand
    /// @return the sum of a and b
    /// @deprecated use {@link #addSafe(int, int)} instead
    @Deprecated
    public int add(int a, int b) {
        return a + b;
    }

    public int addSafe(int a, int b) {
        return a + b;
    }
}

The equivalent /** ... */ form does not raise S7476, S1123, or S1133:

/**
 * Adds two integers.
 * @deprecated use {@link #addSafe(int, int)} instead
 */
@Deprecated
public int add(int a, int b) { return a + b; }

Hello @Emilyaxe,

Thank you for the report.

I see in your message that you are using Java 21 to perform the analysis. When using a Java version earlier than 23, raising an issue for S7476 on markdown comments starting with three slashes is the expected behaviour: the rule warns the user that starting a comment with /// will be interpreted as Javadoc starting from Java 23.

Rules S1123 and S1133 also properly handle /// comments as Javadoc when Java 23 or greater is used in the analysis. The behaviour you observed is probably due to using Java 21 here.

Best regards,
Aurélien

Thank you for the explanation.
I will change to Java 23.