Skip to content

JavaDocImpl.comment() throws on a javadoc containing a literal {n} #166

Closed

Description

@bnaudts

JavaDocImpl.comment() expands {n} in the stored text as a placeholder for inline tag n. Literal text of that form in the javadoc itself gets the same treatment. When n is not a valid tag index, comment() throws.

Where: maddi-cst-impl/src/main/java/io/codelaser/maddi/cst/impl/element/JavaDocImpl.java, comment():

Pattern p = Pattern.compile("\\{(\\d+)}");
Matcher m = p.matcher(super.comment());
while (m.find()) {
    int tagIndex = Integer.parseInt(m.group(1));
    Tag tag = tags.get(tagIndex);   // IndexOutOfBoundsException
    ...

Seen as:

java.lang.IndexOutOfBoundsException: Index: 1 Size: 1
    at java.base/java.util.ImmutableCollections$List12.get(ImmutableCollections.java:611)
    at io.codelaser.maddi.cst.impl.element.JavaDocImpl.comment(JavaDocImpl.java:189)

This happened while parsing an open-source project (nacos) and calling comment() on each type's comments.

Minimal shape: a javadoc that contains a MessageFormat-style pattern and at least one inline tag, for example:

/**
 * Formats {@code key} as "{0}={1}".
 */

The stored text holds {0} for {@code key}, so tag 0 exists. The literal {0} and {1} are then taken as placeholders too. {1} is out of range and throws. {0} is silently replaced by the wrong tag.

Expected: comment() returns the javadoc text as written. Literal {n} sequences are kept, and only the parser's own placeholders are expanded.

Possible fixes:

  • Escape literal { (or {n}) when the placeholders are created, and unescape in comment().
  • Use a placeholder form that cannot occur in source text, such as one with a private-use character.

Either way, out-of-range indices should not throw.

Workaround for callers: commentWithPlaceholders() returns the stored text without expansion. That is enough for checks that only look for words in the comment.

Activity

  1. Tamilarasan-mac commented on Oct 23, 2026

    @Tamilarasan-mac

    i like to work on it

  2. bnaudts commented on Oct 23, 2026

    @bnaudts
    ContributorAuthor

    Cool, give it a go. Ensure that you're working on the latest 'devel' branch, and commit with '-s' to sign off on the DCO.

  3. bnaudts commented on Oct 30, 2026

    @bnaudts
    ContributorAuthor

    I'm working towards a new release on Tuesday Nov 3rd, and I'd like to get a fix in before that. Are you still interested in solving this issue?

  4. Tamilarasan-mac commented on Nov 3, 2026

    @Tamilarasan-mac

    Ok, I'll try my best

  5. bnaudts commented on Nov 3, 2026

    @bnaudts
    ContributorAuthor

    Sorry this issue should have been closed yesterday. I already did the fix yesterday morning before the 0.9.6 release. I've had a quick look in the issue list and there are quite a few open but most require an in-depth understanding of the code-base. However, since the 0.9.6 release the IDE plugins and the MCP server are in very decent shape; it would help a lot if you could test-drive one of them, and report issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions