Skip to content

InvalidSnippet: don't flag external snippets that use the class attribute - #6248

Open
joselynrianaaa wants to merge 1 commit into
google:masterfrom
joselynrianaaa:fix-invalidsnippet-external-snippets
Open

joselynrianaaa wants to merge 1 commit into
google:masterfrom
joselynrianaaa:fix-invalidsnippet-external-snippets

Conversation

@joselynrianaaa

Copy link
Copy Markdown

Fixes #6238

InvalidSnippet reported "This @snippet has no body" for external snippets that
reference their content with the class attribute, for example:

{@snippet class=com.example.Snippets region=builder lang=java}

Per the JavaDoc specification, the colon, newline and body may be omitted in an
external snippet, which is one that uses either file or class:
https://docs.oracle.com/en/java/javase/25/docs/specs/javadoc/doc-comment-spec.html#external-snippets

The check already exempted snippets with a file attribute but not class. This
change exempts both. A snippet that has no body and neither attribute is still
reported.

Tests added to InvalidSnippetTest:

  • snippetWithoutBody_butWithClass: the case from the issue.
  • snippetWithoutBody_butWithClassAndTrailingSpace: {@snippet class=HelloWorld },
    the form used in the JDK programmer's guide.
  • snippetWithoutBody_andWithoutFileOrClass: confirms the warning still fires when
    there is no body and no external reference.

@google-cla

google-cla Bot commented Oct 27, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@joselynrianaaa
joselynrianaaa force-pushed the fix-invalidsnippet-external-snippets branch from e2a8745 to 283721f Compare October 27, 2026 23:46

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

InvalidSnippet incorrectly flags external snippets using the class attribute

1 participant