Skip to content

Fix Javadoc corruption from literal */ in parameter description - #11766

Merged
iscai-msft merged 4 commits into
microsoft:mainfrom
iscai-msft:fix-javadoc-content-type-escape
Aug 27, 2026
Merged

iscai-msft merged 4 commits into
microsoft:mainfrom
iscai-msft:fix-javadoc-content-type-escape

Conversation

@iscai-msft

@iscai-msft iscai-msft commented Aug 26, 2026 •

Copy link
Copy Markdown
Member

Summary

Fixes generated Java code corruption when a Javadoc table cell (parameter name/type/description, or response header name/type/description) contains a literal */ sequence.

Root cause

Values written into the optional-parameters and response-headers Javadoc tables are escaped for XML special characters via CodeNamer.escapeXmlComment, but never comment-escaped. When a value embeds */ (for example, TCGC's Content-Type parameter doc for an unconstrained Http.File content type, whose contentTypes array is ["*/*"]), the literal */ prematurely closes the surrounding generated /** ... */ Javadoc block. This corrupts the rest of the generated Java file and breaks compilation with a long cascade of parser errors.

Fix

CodeNamer.escapeComment already exists and correctly escapes */ to */, but it wasn't applied consistently. This change centralizes the escaping in the shared ClientMethodTemplateBase#javadocTable helper so every cell value (not just parameter descriptions) is protected, alongside the existing XML escaping.

Context

Found while fixing Azure/typespec-azure#5288 (Azure/typespec-azure#5306), where making the Content-Type parameter for default Http.File bodies client-visible (previously hidden as a constant) surfaced this latent Javadoc-escaping bug in CI.

Parameter descriptions are XML-escaped via CodeNamer.escapeXmlComment
but not comment-escaped, so a literal */ (e.g. from an unconstrained
*/* content type doc) can prematurely close the generated
/** ... */ Javadoc block, corrupting the rest of the file.
CodeNamer.escapeComment already exists for this purpose; apply it.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 6a785543-019d-4b0c-9750-5affcfc900ee

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes Java generator output corruption when parameter documentation contains the literal */ sequence, which can prematurely terminate generated /** ... */ Javadoc blocks and break compilation.

Changes:

  • Apply comment-terminator escaping (CodeNamer.escapeComment) in ClientMethodTemplateBase#parameterDescriptionOrDefault in addition to existing XML escaping.
  • Add a Chronus changelog entry documenting the fix for @typespec/http-client-java.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
packages/http-client-java/generator/http-client-generator-core/src/main/java/com/microsoft/typespec/http/client/generator/core/template/ClientMethodTemplateBase.java Escapes */ in parameter descriptions used in generated Javadoc tables to prevent source corruption.
.chronus/changes/fix-javadoc-content-type-escape-2026-08-26.md Changelog entry for the Javadoc corruption fix in the Java HTTP client generator.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@azure-sdk-automation

azure-sdk-automation Bot commented Aug 26, 2026 •

Copy link
Copy Markdown

You can try these changes here

🛝 Playground 🌐 Website 🛝 VSCode Extension

- Move CodeNamer.escapeComment escaping into javadocTable so every
  cell (parameter/response-header name, type, description) is
  protected against a literal */ terminating the Javadoc block,
  not just parameter descriptions.
- Add ClientMethodTemplateBaseTests covering the exact regression
  scenario (a description containing */*).

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 6a785543-019d-4b0c-9750-5affcfc900ee
Copilot AI review requested due to automatic review settings August 26, 2026 16:10

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 6a785543-019d-4b0c-9750-5affcfc900ee
Copilot AI review requested due to automatic review settings August 26, 2026 16:18
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 6a785543-019d-4b0c-9750-5affcfc900ee

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.

@github-actions

github-actions Bot commented Aug 26, 2026 •

Copy link
Copy Markdown
Contributor

All changed packages have been documented.

  • ✅ @typespec/http-client-java
Show changes

@typespec/http-client-java - fix ✏️

Fix generated Javadoc corruption when a table cell value (parameter name/type/description, or response header name/type/description) contains a literal */ (e.g. an unconstrained */* content type), which previously closed the surrounding /** ... */ comment early.

@iscai-msft
iscai-msft added this pull request to the merge queue Aug 26, 2026
Merged via the queue into microsoft:main with commit d8e1467 Aug 27, 2026
35 checks passed
@iscai-msft
iscai-msft deleted the fix-javadoc-content-type-escape branch August 27, 2026 00:11
Weidong Xu (weidongxu-microsoft) added a commit to Azure/typespec-azure that referenced this pull request Aug 31, 2026
## Summary

- bump `@azure-tools/typespec-java` from `0.46.0` to `0.46.1`
- publish the Java fixes synced in #5239

## Included fixes

- management `remove-model` generation (`microsoft/typespec#11698`)
- Javadocs containing `*/` (`microsoft/typespec#11766`)
- response headers following a constant header
(`microsoft/typespec#11793`)

---------

Copilot-Session: 0c853adf-d456-4d99-bacc-fd941aca7924
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

emitter:client:java Issue for the Java client emitter: @typespec/http-client-java

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants