Skip to content

refactor(internal): deprecate the implementations of deprecated contracts - #3423

Open
juherr wants to merge 1 commit into
masterfrom
refactor/deprecate-the-implementations-of-deprecated-contracts
Open

refactor(internal): deprecate the implementations of deprecated contracts#3423
juherr wants to merge 1 commit into
masterfrom
refactor/deprecate-the-implementations-of-deprecated-contracts

Conversation

@juherr

@juherr juherr commented Aug 25, 2026

Copy link
Copy Markdown
Member

What this changes

IClass deprecated getInstances, getInstanceHashCodes and addInstance in 7.10.0, but
TestClass, ClassImpl and NoOpTestClass went on implementing them unmarked. javac therefore
reported every implementation, and every call delegating to the next one down, as a fresh use of a
deprecated API — thirteen warnings for a decision that was taken years ago.

Marking the implementations states what is already true of the contract they serve. It also silences
the delegating calls in their bodies for free, since a deprecated method may use deprecated API.

TestNG separately read two defaults off CommandLineArgs, whose own javadoc schedules it for
removal in 8.0. It now declares them itself.

What to look at in review

getInstanceHashCodes is the one that needs a decision. The same method body satisfies two
contracts:

  • IClass.getInstanceHashCodes() — deprecated since 7.10.0
  • IObject.getInstanceHashCodes() — current, and still reached from the non-deprecated
    ITestNGMethod.getInstanceHashCodes() by way of BaseTestMethod and IObject.instanceHashCodes

So @Deprecated on those three implementations is half true. Each carries a comment saying which
half, because the annotation alone reads as if the whole method were dead — and org.testng.internal
is an exported OSGi package, so a downstream holding a NoOpTestClass now sees a deprecation on a
method whose IObject contract is current.

The clean fix is to stop the two interfaces sharing a name, and #3424 now does exactly that: it
renames IObject.getInstanceHashCodes() to getObjectHashCodes(), after which these annotations are
simply true and the three comments go away. It is stacked on this branch, so this PR still reads on
its own; #3424 also turned up a nullness gap in ClassImpl that the shared name had been hiding.

The two TestNG defaults are runner defaults, not CLI defaults. CliConfigurer overwrites both
unconditionally (setXmlPathInJar, setSuiteThreadPoolSize), so the CLI path never observes these
field initializers; they exist for the programmatic path, where m_xmlPathInJar feeds
JarFileUtils and m_suiteThreadPoolSize picks the sequential-versus-parallel branch. Reading them
off a class scheduled for deletion was the compiler pointing that out. They are now declared next to
DEFAULT_OUTPUTDIR, private like DEFAULT_THREADPOOL_FACTORY. Say the word if you would rather
they were public, so callers keep a supported way to read the default after 8.0.

The remaining CommandLineArgs uses in TestNG all sit inside @Deprecated methods and are
already silent.

Scope

The annotated types are package-private (TestClass) or live in org.testng.internal, which
javadoc already excludes. No published API changes shape, and no behaviour changes.

Effect on the build's warning output

Counters read from ./gradlew testClasses --rerun-tasks with Error Prone and autostyle switched
off, so the numbers are javac's alone:

before after
warning: [deprecation] 108 95
warning: [removal] 7 7

The thirteen this removes are every deprecation warning the main source set produced. The
remainder are in test sources and are back-compatibility coverage — tests that exercise a deprecated
API on purpose, which should keep doing so.

Verification

./gradlew build passes on this branch: no failures and no errors across the test result files.

Summary by CodeRabbit

  • Deprecations

    • Marked several legacy test-instance management APIs as deprecated.
    • Existing behavior remains unchanged; newer object-based APIs should be used instead.
  • Configuration

    • Added local defaults for test JAR XML paths and suite thread-pool sizing.
    • Default initialization is now handled directly by the test runner.

…acts

IClass deprecated getInstances, getInstanceHashCodes and addInstance in
7.10.0, but TestClass, ClassImpl and NoOpTestClass carried on implementing
them unmarked. Every implementation, and every call delegating to the next one
down, therefore read as a fresh use of a deprecated API. Marking the
implementations states what is already true of the contract they serve.

getInstanceHashCodes is the awkward one: the same body also implements
IObject.getInstanceHashCodes, which is current and still reached through
ITestNGMethod. A comment at each of the three sites says so, because the
annotation on its own would read as if the whole method were dead.

The annotated types are package-private or live in org.testng.internal, which
javadoc already excludes, so no published API changes shape.

TestNG also read two defaults off CommandLineArgs, a class its own javadoc
schedules for removal in 8.0. Those values are runner defaults rather than CLI
ones -- the CLI overwrites both unconditionally -- so TestNG now declares them
itself alongside DEFAULT_OUTPUTDIR. The main source set ends up free of
deprecation warnings without a single suppression.
@juherr
juherr requested a review from krmahadevan as a code owner August 25, 2026 19:05
@coderabbitai

coderabbitai Bot commented Aug 25, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: aa0c046f-aed5-44ee-86fd-2a8e4e7b56a4

📥 Commits

Reviewing files that changed from the base of the PR and between 5b0746b and d384f06.

📒 Files selected for processing (4)
  • testng-core/src/main/java/org/testng/TestClass.java
  • testng-core/src/main/java/org/testng/TestNG.java
  • testng-core/src/main/java/org/testng/internal/ClassImpl.java
  • testng-core/src/main/java/org/testng/internal/NoOpTestClass.java

Included review availability: Your plan provides up to 8 included reviews per hour; 5 remain after this review.


📝 Walkthrough

Walkthrough

The change marks legacy instance APIs as deprecated and adds local TestNG defaults for the test JAR XML path and suite thread-pool size. Existing method behavior remains unchanged.

Changes

Legacy instance API deprecations

Layer / File(s) Summary
Deprecate legacy instance methods
testng-core/src/main/java/org/testng/TestClass.java, testng-core/src/main/java/org/testng/internal/ClassImpl.java, testng-core/src/main/java/org/testng/internal/NoOpTestClass.java
Legacy instance retrieval, hash-code, and registration methods are marked deprecated. Their implementations remain unchanged.

TestNG default values

Layer / File(s) Summary
Localize TestNG defaults
testng-core/src/main/java/org/testng/TestNG.java
TestNG defines defaults for the test JAR XML path and suite thread-pool size, then uses them for field initialization.

Estimated code review effort: 1 (Trivial) | ~5 minutes

Merge Risk: ⚪ Minimal · up to d384f

This change marks deprecated implementations and moves runner defaults away from a deprecated command-line class without changing intended behavior; no actionable merge-blocking risk remains after normal checks and review.

Suggested reviewers: krmahadevan

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 22.22% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 18 functions across 4 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: marking implementations of already deprecated contracts as deprecated. It is concise and specific.
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch refactor/deprecate-the-implementations-of-deprecated-contracts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

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.

1 participant