GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — [apex] Fix #5906: MethodWithSameNameAsEnclosingClass range is too broad by HawkForge · Pull Request #7264 · pmd/pmd

Conversation

@HawkForge

@HawkForge HawkForge commented Oct 29, 2026

Copy link
Copy Markdown
Contributor

Describe the PR

Fixes the too-broad violation range of the Apex rule MethodWithSameNameAsEnclosingClass. Thanks to @stephen-carter-at-sf for the report.

The rule called addViolation(node) on the ASTMethod, so the reported range covered the whole method including its body. It now reports the range from the start of the method to the end of its signature (the text before the body block), as was done for ExcessiveParameterList in #5617.

Two test cases were added (multi-line signature with parameters, and a no-parameter method) using expected-linenumbers ranges. They fail without the change.

Related issues

  • Fix [apex] MethodWithSameNameAsEnclosingClass: Violation range should only cover the method name #5906

Ready?

  • Added unit tests for fixes and features
  • Passing all unit tests
  • Complete build ./mvnw clean verify passes (checked automatically by github actions)
  • Added (in-code) documentation (if needed)

Replaces #7227, which got closed when my fork was accidentally detached.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@HawkForge
[apex] Fix pmd#5906: MethodWithSameNameAsEnclosingClass reports only …
2145a6b
…the method signature
@UncleOwen

UncleOwen commented Oct 29, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

Would it make sense to override getReportLocation() in ASTMethod? That way, all violations on methods get fixed at the same time.

pmd-java does the same thing in AbstractExecutableDeclaration.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

HawkForge added 2 commits November 12, 2026 10:31
@HawkForge
Merge branch 'main' into fix/5906-apex-method-same-name-range
8ca3feb
@HawkForge
[apex] Override getReportLocation in ASTMethod to report only the sig…
1ecd403
…nature
@HawkForge

HawkForge commented Nov 12, 2026

Copy link
Copy Markdown
Contributor Author

good call, thanks. moved it into ASTMethod.getReportLocation() so every rule reporting on a method gets the signature-only range (method start up to just before the body block), and dropped the private helper from MethodWithSameNameAsEnclosingClassRule. apex has no identifier token on the method node like java does, so i couldn't just return that. no rule test expectations changed, only 4 position asserts in ApexParserTest that check the node's report location now expect the signature range. also merged main to fix the conflict.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

UncleOwen
UncleOwen reviewed Nov 12, 2026
View reviewed changes
Comment thread docs/pages/release_notes.md Resolved

Uh oh!

There was an error while loading. Please reload this page.

HawkForge and others added 2 commits November 14, 2026 10:53
@HawkForge @UncleOwen
Drop unrelated release note entries
d58ef76
Co-authored-by: UncleOwen <[email protected]>
@adangel
Merge branch 'main' into fix/5906-apex-method-same-name-range
8dabe5f
adangel
adangel reviewed Nov 20, 2026
View reviewed changes

@adangel adangel left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Thanks for the PR!

apex has no identifier token on the method node like java does, so i couldn't just return that.

It's true, that in PMD's AST of Apex, there is no identifier node and no token. But we could use the underlying node from SummitAst, which has the identifier (unfortunately, it is not a field, because there are synthetic methods for triggers, that don't have a node).

I'll give that a try... it would make it easier, if we could just use the sourceLocation of the identifier then (and ExcessiveParameterList rule could then be simplified as well).

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread ...ces/net/sourceforge/pmd/lang/apex/rule/errorprone/xml/MethodWithSameNameAsEnclosingClass.xml Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread ...ces/net/sourceforge/pmd/lang/apex/rule/errorprone/xml/MethodWithSameNameAsEnclosingClass.xml Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread docs/pages/release_notes.md Resolved

Uh oh!

There was an error while loading. Please reload this page.

@adangel adangel mentioned this pull request Nov 20, 2026
[apex] Fix #5669: Report ApexUnitTestMethodShouldHaveIsTestAnnotation only on the method name #7263
Merged
1 of 4 tasks
@adangel
[apex] Use identifier for ASTMethod report location
d2dc1be
adangel
adangel reviewed Nov 20, 2026
View reviewed changes
Comment thread pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTMethod.java Resolved

Uh oh!

There was an error while loading. Please reload this page.

@adangel

adangel commented Nov 20, 2026

Copy link
Copy Markdown
Member

This change now also fixes #5669. I didn't change ExcessiveParameterList, as there it makes sense to also return the range over the parameters.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@pmd-actions-helper

pmd-actions-helper Bot commented Nov 20, 2026

Copy link
Copy Markdown
Contributor

Documentation Preview

Compared to main:
This changeset changes 3323 violations,
introduces 0 new violations, 0 new errors and 0 new configuration errors,
removes 0 violations, 0 errors and 0 configuration errors.
There are 0 changed duplications, 0 new duplications and 0 removed duplications.
There are 0 changed CPD errors, 0 new CPD errors and 0 removed CPD errors.

Regression Tester Report

(comment created at 2026-11-20 19:45:00+00:00 for d2dc1be)

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@adangel
Fix javadoc
8a181ba
@adangel adangel added this to the 7.30.0 milestone Nov 21, 2026
adangel
adangel approved these changes Nov 21, 2026
View reviewed changes
@adangel adangel self-assigned this Nov 21, 2026
@adangel
adangel merged commit f0807ce into pmd:main Nov 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@UncleOwen UncleOwen UncleOwen left review comments
@adangel adangel adangel approved these changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

@adangel adangel

Labels

None yet

Projects

None yet

Milestone

7.30.0

Development

Successfully merging this pull request may close these issues.

[apex] MethodWithSameNameAsEnclosingClass: Violation range should only cover the method name

Uh oh!

There was an error while loading. Please reload this page.

3 participants

@HawkForge @UncleOwen @adangel
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.