Skip to content

Metadata/Xdoc generators do not handle {@literal} and incorrectly handle {@code} with XML special characters #18993

@vivek-0509

Description

@vivek-0509

Description

Javadoc inline tags {@literal} and {@code} with XML special characters (<, >) not handled correctly in metadata and xdoc generation .

There are two bugs:

  1. {@literal} is not handled - JavadocMetadataScraperUtil.constructSubTreeText() and SiteUtil.getDescriptionFromJavadocForXdoc() have no logic for LITERAL_INLINE_TAG nodes. The child nodes (including syntax tokens {,@literal, }) are written to the output as plain text instead of being processed. This becomes a breaking issue when the content contains XML special characters like < or >, as they are not escaped.

  2. {@code} does not escape < and > - adjustCodeInlineTagChildToHtml() only escapes & -> &amp;, but not < -> &lt; or > -> &gt;. This means {@code <p>} produces <code><p></code> (broken XML) instead of the correct <code>&lt;p&gt;</code>.

How to Reproduce

Add {@literal <} or {@code <p>} to any module's class-level Javadoc and run mvn clean verify. The build will fail because the generated meta XML and/or xdoc XML files contain invalid XML.

For example, changing a module's Javadoc from:

Each paragraph but the first has &lt;p&gt; immediately

to the preferred inline tag form:

Each paragraph but the first has {@code <p>} immediately

causes the meta XML generator to produce <code><p></code> instead of <code>&lt;p&gt;</code>, resulting in malformed XML because the <p> is not escaped and gets interpreted as an actual HTML tag.

Actual Behavior

Currently, the generators produce broken output:

  • {@literal <} -> {@literal <} (raw structural tokens leak into the output as plain text)
  • {@literal >} -> {@literal >} (same issue)
  • {@code <p>} -> <code><p></code> (the <p> is not escaped, producing invalid XML)
  • {@code &} -> <code>&amp;</code> (only & escaping works correctly)

Expected Behavior

After the fix, the generators should produce correct XML output:

  • {@literal <} -> &lt; in both meta XML and xdoc output
  • {@literal >} -> &gt; in both meta XML and xdoc output
  • {@code <p>} -> <code>&lt;p&gt;</code> in both meta XML and xdoc output

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions