You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Java generator: parameter defaultValue not escaped in @param Javadoc, breaks compilation for values containing "*/" #24852
When a parameter's OpenAPI schema has a default value containing the
sequence */ (e.g. an Accept header defaulting to */*), the generated
Java client's @param Javadoc line embeds that value raw and unescaped,
which prematurely closes the enclosing /** ... */ comment block and
produces a Java file that fails to compile.
openapi-generator version
7.25.0 (also reproduces on other recent versions - the relevant template
code is unchanged on master as of this writing)
Java (client) generator
Steps to reproduce
Minimal OpenAPI 3.1 spec with a header parameter defaulting to */*:
Compilation fails. The generated @param line reads:
```
@PARAM accept (optional, default to /)
```
The */ inside that text closes the Javadoc block early, so every line
after it in the same comment becomes invalid Java source.
Expected behavior
The generated client should compile. defaultValue (and any other
free-text value interpolated into a Javadoc comment) should go through
comment-safe escaping, the same way consumes/produces content types
are handled via escapeText() in addConsumesInfo (see #10598, which
is the same underlying class of bug in the other direction).
The relevant template: Java/libraries/okhttp-gson/api.mustache,
the {{#defaultValue}}, default to {{.}}{{/defaultValue}} line - {{.}} only gets Mustache's HTML-entity escaping, not Java-comment
escaping.
IMO this is really a symptom of how escaping is done in general here: values get pre-escaped in the Java generator, but that cannot be right, since the same value needs different escaping depending on where it lands (inline comment vs. Javadoc vs. raw string literal vs. default-value literal). Escaping has to happen at the point of use.
For this bug specifically, I would add a comment-escaping Mustache lambda applied only at the Javadoc sites (the {{.}} in {{#defaultValue}}, default to {{.}}{{/defaultValue}} etc.). So something like {{.}} in {{#defaultValue}}, default to {{#escapeJavaDoc}}{{.}}{{/escapeJavaDoc}}{{/defaultValue}}.
Note the naive */ -> *_/ trick makes it compile but lies about the value (*/* becomes *_/*). Since Javadoc is HTML, an entity like */ avoids the early comment close and renders back to */ in the docs, though it is sensitive: anything reading the raw comment text still sees the entity.
I think this needs a general overhaul, but it's sensitive and easy to break something in the process. But it is a generally weak spot - already there are some issues showing it can be used also for arbitrary code injection.
Activity
Picazsoo commentedon Sep 7, 2026
IMO this is really a symptom of how escaping is done in general here: values get pre-escaped in the Java generator, but that cannot be right, since the same value needs different escaping depending on where it lands (inline comment vs. Javadoc vs. raw string literal vs. default-value literal). Escaping has to happen at the point of use.
For this bug specifically, I would add a comment-escaping Mustache lambda applied only at the Javadoc sites (the
{{.}}in{{#defaultValue}}, default to {{.}}{{/defaultValue}}etc.). So something like{{.}}in{{#defaultValue}}, default to {{#escapeJavaDoc}}{{.}}{{/escapeJavaDoc}}{{/defaultValue}}.Note the naive
*/->*_/trick makes it compile but lies about the value (*/*becomes*_/*). Since Javadoc is HTML, an entity like*/avoids the early comment close and renders back to*/in the docs, though it is sensitive: anything reading the raw comment text still sees the entity.I think this needs a general overhaul, but it's sensitive and easy to break something in the process. But it is a generally weak spot - already there are some issues showing it can be used also for arbitrary code injection.
Just my 2 cents.