Skip to content

[java] New rule: InternalApiUsage - #6994

Merged
adangel merged 5 commits into
pmd:mainfrom
zbynek:internal-usage
Sep 24, 2026
Merged

adangel merged 5 commits into
pmd:mainfrom
zbynek:internal-usage

Conversation

@zbynek

@zbynek zbynek commented Aug 24, 2026 •

Copy link
Copy Markdown
Contributor

Describe the PR

Adds a rule that detects usages of internal APIs, currently checking for @VisibleForTesting, @TestOnly, JetBrains @ApiStatus and Apigurdian's @API.

Related issues

Ready?

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

@zbynek
zbynek force-pushed the internal-usage branch 3 times, most recently from fc48cdf to 7a029b2 Compare August 25, 2026 06:11
@pmd-actions-helper

pmd-actions-helper Bot commented Aug 25, 2026 •

Copy link
Copy Markdown
Contributor

Documentation Preview

Compared to main:
This changeset changes 0 violations,
introduces 30 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-09-24 09:07:55+00:00 for d30214e)

@zbynek
zbynek marked this pull request as draft August 26, 2026 13:42
@zbynek
zbynek force-pushed the internal-usage branch 2 times, most recently from 86a78d6 to 234fa23 Compare August 27, 2026 23:00
@zbynek
zbynek marked this pull request as ready for review September 21, 2026 22:53
@adangel adangel added the a:new-rule Proposal to add a new built-in rule label Sep 22, 2026

@adangel adangel left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks!

The only question I have is: Should we support fields now? IMHO, we could also deliver this in a later release and have this rule in 7.28.0. If we defer this, then we should update the examples on #6889.

The regression tester finds some cases in checkstyle, where a class (not a test class, a helper class) in test-sources access a @VisibleForTesting only constructor. This is ok in general, but in this case, the constructor is in the same source unit - so we could apply the same rule for internal (can be accessed if it is in the same unit).

@zbynek

zbynek commented Sep 23, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the feedback, I hope the last commit handles all of it. There's always more to do: if an internal class is used in any way (extends, instanceof,...), it should be reported too. I think focusing on fields and methods is sufficient for 7.28.0 though.

@adangel adangel added this to the 7.28.0 milestone Sep 24, 2026

@adangel adangel left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks!

I'll update the release notes and merge it afterwards.

@adangel
adangel merged commit 0a14568 into pmd:main Sep 24, 2026
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

a:new-rule Proposal to add a new built-in rule

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[java] New rule: InternalApiUsage

2 participants