GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||
GeezerVison is showing github.com — [java] Fix #6270: CommentSize skips file header comments by fudianchn · Pull Request #6948 · pmd/pmd Conversation
Contributor
What
WhyThe rule documentation states it checks "non-header comments", but the implementation iterated over every comment, producing false positives for typical license headers (e.g. ASLv2, which exceeds the default 6-line limit). Closes #6270. Root cause
HowDetermine the start position of the first code token (the first package/import/type/module declaration) and skip any comment whose end position is at or before it. This uses the standard Java-ecosystem meaning of "file header" (the comments preceding the first declaration) and matches the issue's ASLv2-before-package example; it also holds for default-package files (no package — the header sits before the first type). Empty files keep the old behavior (nothing skipped). Testing
Notes
Fixes #6270
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactionsThe rule documents that "non-header comments" are checked, but the implementation checked every comment, producing false positives for typical multi-line license/copyright headers (e.g. ASLv2). A comment is now considered part of the file header when it ends before the first code token of the compilation unit (the package/import/type/ module declaration) and is then skipped. The documentation example is also corrected: the previous one had a single non-empty line only (so the line count would not flag it) and would be a header comment. Fixes pmd#6270 Signed-off-by: 付典 <[email protected]>
zbynek
approved these changes
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks good. There's some discussion about the usefulness of the rule in general: #2265 , but this improvement can be implemented regardless.
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
|
There was an error while loading. Please reload this page.
|
Compared to main: (comment created at 2026-08-07 18:05:22+00:00 for 4409b44) |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
The regression tester report is interesting:
|
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
[java] CommentSize: False positive with file header comments
There was an error while loading. Please reload this page.