3

Using Java 25 with the new JEP 467: Markdown Documentation Comments, I tried to add the following:

/// @see [Example Site](https://example.com/)

Javadoc (invoked by Maven) complained "error: unexpected content", with a ^ under the ending ).

The JEP 467 spec says:

You can use all other forms of Markdown links, including links to URLs ….

The inline and block tags are parsed in the same way as for traditional documentation comments, except that tag content is also parsed as Markdown.

Thus I don't see anything that indicates that Markdown URL links may not be used in a @see block.

My objective is not to find another way to link to classes or methods. I truly want to link to a URL. Many things we write are inspired, influenced, or guided by blog articles or even Stack Overflow. So to make things meta, if I were writing a Java implementation of Javadoc parsing I might just reference this very Stack Overflow question!

/// Parses Javadoc Markdown comments and returns a Markdown node tree.
/// @implNote Supports Markdown for the `@see` tag.
/// @see [Java 25 Javadoc not allowing Markdown URL link syntax in `@see`](https://stackoverflow.com/q/79794040)

Can someone confirm this is a Javadoc bug, and let me know where I can file a bug against that tool? (I don't have an OpenJDK account, so I seem unable to file one at https://bugs.openjdk.org/ .)

1
  • Of course, @see <a href="https://example.com/">Example Site</a> is explicitly allowed (and I use it all the time). This does not mean arbitrary HTML is allowed; as far as I can tell, <a href is treated as a special case. Commented Oct 19 at 11:57

1 Answer 1

4

JEPs aren't actually specs. You're looking for the JavaDoc Documentation for the Standard Doclet (JDK25).

From the markdown section of that spec:

Both inline tags and block tags may be used in Markdown documentation comments, although neither may be used within the literal text of code spans and fenced or indented code blocks.

For those tags that may contain text with markup, in a Markdown documentation comment that markup will also be in Markdown format.

Emphasis mine.

@see is not a tag that may contain text with markup. At least, I don't think so; this spec is not written nearly as exactingly precise as what we're used to with e.g. the Java Language Spec, and term "a tag that may contain text with markup" is not actually defined. The docs for the @see tag seem pretty clear though: It offers 3 different options and the list ends there. There's room for markup within the confines of one of those 3 choices, but the @see tag itself does not allow it (it allows only 3 things, and within those 3 things, those might allow it).

Solution A - accept it

I think your best option is to accept it and not try to get OpenJDK to 'fix' it. @see is already quite markdownesque in what it allows. For example, this is and has always been legal:

/**
 * @see SomeClass#someMethod The wrapped method
 */

Which results in the text of the link being 'The wrapped method', that then links to someMethod's javadoc.

What you presumably want is to write:

/// @see [The wrapped method][SomeClass#someMethod]

And there's some value in being able to keep things consistent, and to be able to just text-edit your source file and easily turn a @see into an inline link and vice versa, which you can't do with 'old style @see'. However, if your aim is to make the docs readable in raw text form, then the old @see is, if anything, superior; the brackets don't add anything given that @see already implies we're writing links.

Solution B - inline it

You can always just do this:

instead of:

/// My fun method
///
/// @see SomeClass#someMethod The wrapped method
public void whatever() { ... }

write:

/// My fun method
///
/// see: [The wrapped method][SomeClass#someMethod]
public void whatever() { ... }

It's very slightly annoying that the semantic structure of your javadoc is modified by this, but not pertinently so: The semantic difference between a link mentioned inline vs one mentioned in an @see is virtually invisible. I believe the default doclet sticks the @see stuff at the very end, whereas with this, e.g. params, return description, and exception descriptions would all be below your pseudo-inlined link.

If that's a real problem...

Solution C - the OpenJDK mailing lists

Given that it isn't a bug, and OpenJDK's bug tracker is not for feature requests (and not open to the public), it's not the right venue to raise the topic. Instead, the openjdk mailing lists are. They are public.

The one that is probably the most relevant is javadoc-dev.

Sign up to request clarification or add additional context in comments.

8 Comments

"What you presumably want is to write [is a Markdown link to a method defined in a class]". No. The whole point of this really is an actual URL link. It is incredibly common that Java code is an implementation of some specification. Thus it only makes sense that the Javadocs provide a link to that specification. There are implementations of XML, HTTP, HTML, etc. It's just good practice to provide a link in the Javadocs pointing to the authoritative spec, e.g. @see [HTML Spec](https://html.spec.whatwg.org/). I'll read the rest of your answer closely, but I wanted to clarify the objective.
Well now that I'm reading the Javadoc spec you mentioned, I see that there is a @spec URL title, which I didn't even know existed. This will be useful. Still the issue I raised remains—maybe I want to to reference this very Stack Overflow question in a method Javadoc documentation, but not as a spec: @see [Java 25 Javadoc not allowing Markdown URL link syntax in @see](https://stackoverflow.com/q/79794040). I will continue reading your response and the Javadoc spec more closely.
Ah, well, fortunately one of those 3 ways you can use @see is to provide links, but, now we are indeed in 'oof, now I need to write HTML'. @see <a href> is explicitly legal. You'd have to write @see <a href="https://stackoverflow.com/q/79794040">Java 25 Javadoc not allowing Markdown URL link syntax in @see</a> which.. yeah. I find that tragic too. I retract my suggestion - I think this is worth taking to javadoc-dev!
(Specifically, having @see [text](URL) as an alternative to @see <a href="URL">text</a>).
This is getting worse with LLM code generation. I have to constantly remind it to use HTML for @see in Markdown Javadocs, so it changes it to See …, which it can use Markdown instead of <a>, so I have to have very explicit instructions to "Use Markdown Javadocs for this class, but not for @see". I just now sent an email to javadoc-dev and I'm awaiting the moderator to accept my post.
@GarretWilson "hey, OpenJDK, can you change the tooling because my LLM keeps messing up".. oof. Well, I'm sure they'll be more diplomatic than I could ever be, but I'd definitely tell you to take a long long hike into the middle of nowhere with that kind of request :) Best of luck!
Substitute "junior developer" or "me before I've had breakfast" for "LLM" in that sentence. It's the same thing.
I brought this up on the javadoc-dev list, and they filed Javadoc bug JDK-8371504: Support Markdown link syntax in Markdown @see tags.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.