Skip to content

Forbid wildcard imports with Spotless - #12262

Open
AlexeyKuznetsov-DD wants to merge 2 commits into
masterfrom
alexeyk/spotless-expand-imports
Open

Forbid wildcard imports with Spotless#12262
AlexeyKuznetsov-DD wants to merge 2 commits into
masterfrom
alexeyk/spotless-expand-imports

Conversation

@AlexeyKuznetsov-DD

@AlexeyKuznetsov-DD AlexeyKuznetsov-DD commented Aug 21, 2026

Copy link
Copy Markdown
Contributor

What Does This Do

Configures Spotless to remove unused Java imports and reject wildcard imports across the repository. All existing wildcard imports are expanded to explicit imports.

The PR is intentionally split into two commits to simplify review:

  1. Forbid wildcard imports with Spotless contains the six build and formatter configuration files. It applies forbidWildcardImports() to the main build, the standalone dependency-validation build, and both Java buildSrc projects. It also preserves the localized Netty 3.8 GrEclipse compatibility override.
  2. Expand existing wildcard imports contains the existing source-formatting output: 173 Java, Scala, Groovy, or source-fixture files, including the complete explicit imports required by the Spring Boot JPA smoke application and the JSP source fixture.

Motivation

Wildcard imports obscure the dependencies used by a source file and conflict with the repository's import conventions. The lightweight built-in Spotless check prevents new wildcard imports; if one is introduced, spotlessCheck reports it and the developer can replace it with explicit imports.

Automatic expandWildcardImports() was evaluated first, but it is too memory-greedy for this repository. The step constructs JavaParser symbol solvers from each source-set classpath, and heap analysis showed those solver graphs retained across thousands of Spotless formatter instances until an 8 GiB Gradle heap was exhausted. The final implementation therefore uses forbidWildcardImports() rather than automatic expansion.

Additional Notes

Netty 3.8 uses the current GrEclipse formatter locally because the repository-wide GrEclipse 4.27 pin cannot format those tests. The localized override and its generated compatibility formatting can be removed after that pin is lifted. See diffplug/spotless#3013.

The centralized Spotless setup follows the existing formatter configuration introduced and updated in #12208.

Validation:

  • ./gradlew spotlessCheck writeMainVersionFile --rerun-tasks --parallel --max-workers=4
  • ./gradlew :dd-java-agent:agent-debugger:debugger-el:test --tests com.datadog.debugger.el.expressions.HasAnyExpressionTest
  • ./gradlew :dd-java-agent:agent-tooling:test --tests datadog.trace.agent.tooling.stratum.StratumManagerTest (2 tests)
  • ./gradlew :dd-smoke-tests:apm-tracing-disabled:bootJar
  • ./gradlew :dd-smoke-tests:springboot-jpa:bootWar
  • ./gradlew -p buildSrc :call-site-instrumentation-plugin:spotlessCheck
  • ./gradlew -p buildSrc :modifiable-config-agent:spotlessCheck :modifiable-config-agent:build
  • ./gradlew -p test-published-dependencies spotlessCheck
  • ./gradlew -p test-published-dependencies :agent-logs-on-java-7:compileTestJava
  • Negative probes confirmed wildcard imports fail the built-in Spotless check in the main build and standalone builds
  • Repository scan found zero remaining Java wildcard imports outside generated build output
  • Stable patch comparison confirmed the rewritten source-formatting commit is identical to its previously reviewed version

Contributor Checklist

Jira ticket: N/A

@AlexeyKuznetsov-DD AlexeyKuznetsov-DD added comp: tooling Build & Tooling type: refactoring tag: ai generated Largely based on code generated by an AI or LLM tag: no release notes Changes to exclude from release notes labels Aug 21, 2026
@AlexeyKuznetsov-DD AlexeyKuznetsov-DD self-assigned this Aug 21, 2026
@AlexeyKuznetsov-DD
AlexeyKuznetsov-DD force-pushed the alexeyk/spotless-expand-imports branch 2 times, most recently from 3fc2c07 to 878d85d Compare August 21, 2026 18:31
@AlexeyKuznetsov-DD
AlexeyKuznetsov-DD marked this pull request as ready for review August 21, 2026 18:36
@AlexeyKuznetsov-DD
AlexeyKuznetsov-DD requested review from a team as code owners August 21, 2026 18:36
@AlexeyKuznetsov-DD
AlexeyKuznetsov-DD requested review from jandro996, jpbempel, manuel-alvarez-alvarez, mhlidd, sarahchen6 and vandonr and removed request for a team August 21, 2026 18:36

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 878d85d8d4

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread gradle/spotless.gradle Outdated

@datadog-prod-us1-5 datadog-prod-us1-5 Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Datadog Autotest: FAIL

The main build expands wildcard imports. Two separate Gradle builds still accept wildcard imports, so the repository-wide rule is incomplete.

Open Bits AI session

🤖 Datadog Autotest · Commit 878d85d · What is Autotest? · @DataDog review to ask questions · Any feedback? Reach out in #autotest

Comment thread gradle/spotless.gradle Outdated
@datadog-prod-us1-5

This comment has been minimized.

@AlexeyKuznetsov-DD
AlexeyKuznetsov-DD force-pushed the alexeyk/spotless-expand-imports branch from 878d85d to a73f602 Compare August 21, 2026 18:48
@AlexeyKuznetsov-DD
AlexeyKuznetsov-DD marked this pull request as draft August 21, 2026 18:49

@jpbempel jpbempel 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.

LGTM

@dd-octo-sts

dd-octo-sts Bot commented Aug 21, 2026

Copy link
Copy Markdown
Contributor

🟢 Java Benchmark SLOs — All performance SLOs passed

Suite Status
Startup 🟢 pass

SLO thresholds are defined here based on automatically generated metrics. A warning is raised when results are within 5% of the threshold.

PR vs. master results
Scenario Candidate master Δ (95% CI of mean)
startup:insecure-bank:iast:Agent 14.92 s 14.74 s [+0.2%; +2.2%] (maybe worse)
startup:insecure-bank:tracing:Agent 13.68 s 13.76 s [-1.5%; +0.2%] (no difference)
startup:petclinic:appsec:Agent 17.44 s 17.23 s [+0.3%; +2.2%] (maybe worse)
startup:petclinic:iast:Agent 16.81 s 17.46 s [-7.8%; +0.4%] (no difference)
startup:petclinic:profiling:Agent 17.24 s 17.37 s [-1.9%; +0.4%] (no difference)
startup:petclinic:sca:Agent 17.53 s 17.27 s [+0.5%; +2.6%] (maybe worse)
startup:petclinic:tracing:Agent 16.53 s 16.57 s [-1.1%; +0.6%] (no difference)

Commit: 403c9945 · CI Pipeline · Benchmarking Platform UI


Load and DaCapo benchmarks can be triggered manually in the GitLab pipeline. Results will appear in the Benchmarking Platform UI after completion.

@pr-commenter

pr-commenter Bot commented Aug 21, 2026

Copy link
Copy Markdown

Debugger benchmarks

Parameters

Baseline Candidate
baseline_or_candidate baseline candidate
ci_job_date 1787354928 1787355255
end_time 2026-08-21T23:30:19 2026-08-21T23:35:46
git_branch master alexeyk/spotless-expand-imports
git_commit_sha 710bee5 7bcf2ef
start_time 2026-08-21T23:28:49 2026-08-21T23:34:16
See matching parameters
Baseline Candidate
ci_job_id 1974461279 1974461279
ci_pipeline_id 132530959 132530959
cpu_model Intel(R) Xeon(R) Platinum 8175M CPU @ 2.50GHz Intel(R) Xeon(R) Platinum 8175M CPU @ 2.50GHz
git_commit_date 1787354316 1787354316

Summary

Found 0 performance improvements and 0 performance regressions! Performance is the same for 10 metrics, 5 unstable metrics.

See unchanged results
scenario Δ mean agg_http_req_duration_min Δ mean agg_http_req_duration_p50 Δ mean agg_http_req_duration_p75 Δ mean agg_http_req_duration_p99 Δ mean throughput
scenario:noprobe unstable
[-20.694µs; +27.806µs] or [-6.249%; +8.397%]
unstable
[-31.690µs; +37.275µs] or [-8.700%; +10.233%]
unstable
[-40.352µs; +48.109µs] or [-10.669%; +12.719%]
unstable
[-52.476µs; +137.047µs] or [-4.613%; +12.048%]
same
scenario:basic same same same unstable
[-162.329µs; +42.605µs] or [-16.660%; +4.372%]
same
scenario:loop same same same same same
Request duration reports for reports
gantt
    title reports - request duration [CI 0.99] : candidate=None, baseline=None
    dateFormat X
    axisFormat %s
section baseline
noprobe (364.269 µs) : 334, 395
.   : milestone, 364,
basic (343.482 µs) : 337, 350
.   : milestone, 343,
loop (8.113 ms) : 8050, 8177
.   : milestone, 8113,
section candidate
noprobe (367.061 µs) : 332, 402
.   : milestone, 367,
basic (343.997 µs) : 337, 351
.   : milestone, 344,
loop (8.114 ms) : 8050, 8178
.   : milestone, 8114,
Loading
  • baseline results
Scenario Request median duration [CI 0.99]
noprobe 364.269 µs [333.562 µs, 394.976 µs]
basic 343.482 µs [336.983 µs, 349.98 µs]
loop 8.113 ms [8.05 ms, 8.177 ms]
  • candidate results
Scenario Request median duration [CI 0.99]
noprobe 367.061 µs [332.412 µs, 401.711 µs]
basic 343.997 µs [337.027 µs, 350.966 µs]
loop 8.114 ms [8.05 ms, 8.178 ms]

@AlexeyKuznetsov-DD
AlexeyKuznetsov-DD force-pushed the alexeyk/spotless-expand-imports branch from a73f602 to c9ec832 Compare August 21, 2026 19:11
@AlexeyKuznetsov-DD
AlexeyKuznetsov-DD marked this pull request as ready for review August 21, 2026 19:16

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: c9ec832e8c

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread buildSrc/call-site-instrumentation-plugin/build.gradle.kts Outdated
Comment thread gradle/spotless.gradle Outdated

@datadog-prod-us1-5 datadog-prod-us1-5 Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Datadog Autotest: PASS

More details

The formatter rules apply consistently across the main and separate Gradle builds. The source edits contain import changes and adjacent whitespace only.

Was this helpful? React 👍 or 👎

Open Bits AI session

🤖 Datadog Autotest · Commit c9ec832 · What is Autotest? · @DataDog review to ask questions · Any feedback? Reach out in #autotest

@pr-commenter

pr-commenter Bot commented Aug 21, 2026

Copy link
Copy Markdown

Kafka / producer-benchmark

Parameters

Baseline Candidate
baseline_or_candidate baseline candidate
git_branch master alexeyk/spotless-expand-imports
git_commit_date 1787314937 1787355846
git_commit_sha 926e82f 403c994
See matching parameters
Baseline Candidate
ci_job_date 1787357403 1787357403
ci_job_id 1974484356 1974484356
ci_pipeline_id 132532272 132532272
cpu_model Intel(R) Xeon(R) Platinum 8259CL CPU @ 2.50GHz Intel(R) Xeon(R) Platinum 8259CL CPU @ 2.50GHz
jdkVersion 11.0.31 11.0.31
jmhVersion 1.36 1.36
jvm /usr/lib/jvm/java-11-openjdk-amd64/bin/java /usr/lib/jvm/java-11-openjdk-amd64/bin/java
jvmArgs -Dhttp.proxyHost=127.0.0.1 -Dhttp.proxyPort=15002 -Dhttps.proxyHost=127.0.0.1 -Dhttps.proxyPort=15002 -Dhttp.nonProxyHosts=localhost *.localhost
kernel_version Linux runner-zfyrx7zua-project-304-concurrent-1-ajzkvqbz 6.8.0-1031-aws #33~22.04.1-Ubuntu SMP Thu Jun 26 14:22:30 UTC 2025 x86_64 x86_64 x86_64 GNU/Linux Linux runner-zfyrx7zua-project-304-concurrent-1-ajzkvqbz 6.8.0-1031-aws #33~22.04.1-Ubuntu SMP Thu Jun 26 14:22:30 UTC 2025 x86_64 x86_64 x86_64 GNU/Linux
vmName OpenJDK 64-Bit Server VM OpenJDK 64-Bit Server VM
vmVersion 11.0.31+11-post-1ubuntu1-22.04.2-Ubuntu 11.0.31+11-post-1ubuntu1-22.04.2-Ubuntu

Summary

Found 0 performance improvements and 0 performance regressions! Performance is the same for 3 metrics, 0 unstable metrics.

See unchanged results
scenario Δ mean throughput
scenario:not-instrumented/KafkaProduceBenchmark.benchProduce same
scenario:only-tracing-dsm-disabled-benchmarks/KafkaProduceBenchmark.benchProduce same
scenario:only-tracing-dsm-enabled-benchmarks/KafkaProduceBenchmark.benchProduce same

@mhlidd mhlidd left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nice changes!

@AlexeyKuznetsov-DD
AlexeyKuznetsov-DD force-pushed the alexeyk/spotless-expand-imports branch from c9ec832 to a576807 Compare August 21, 2026 19:56
@AlexeyKuznetsov-DD
AlexeyKuznetsov-DD requested a review from a team as a code owner August 21, 2026 19:56
@AlexeyKuznetsov-DD
AlexeyKuznetsov-DD requested review from erikayasuda and removed request for a team August 21, 2026 19:56

@datadog-prod-us1-5 datadog-prod-us1-5 Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Datadog Autotest: FAIL

The new rule does not cover buildSrc/modifiable-config-agent. A wildcard import can enter that Java project without a Spotless error.

Open Bits AI session

🤖 Datadog Autotest · Commit a576807 · What is Autotest? · @DataDog review to ask questions · Any feedback? Reach out in #autotest

Comment thread buildSrc/call-site-instrumentation-plugin/build.gradle.kts Outdated
@AlexeyKuznetsov-DD
AlexeyKuznetsov-DD force-pushed the alexeyk/spotless-expand-imports branch 2 times, most recently from a503e53 to 7bcf2ef Compare August 21, 2026 23:19
@AlexeyKuznetsov-DD AlexeyKuznetsov-DD changed the title Expand wildcard imports with Spotless Forbid wildcard imports with Spotless Aug 21, 2026
@AlexeyKuznetsov-DD
AlexeyKuznetsov-DD force-pushed the alexeyk/spotless-expand-imports branch from 7bcf2ef to 403c994 Compare August 21, 2026 23:45
@pr-commenter

pr-commenter Bot commented Aug 22, 2026

Copy link
Copy Markdown

Kafka / consumer-benchmark

Parameters

Baseline Candidate
baseline_or_candidate baseline candidate
git_branch master alexeyk/spotless-expand-imports
git_commit_date 1787314937 1787355846
git_commit_sha 926e82f 403c994
See matching parameters
Baseline Candidate
ci_job_date 1787357021 1787357021
ci_job_id 1974484357 1974484357
ci_pipeline_id 132532272 132532272
cpu_model Intel(R) Xeon(R) Platinum 8259CL CPU @ 2.50GHz Intel(R) Xeon(R) Platinum 8259CL CPU @ 2.50GHz
jdkVersion 11.0.31 11.0.31
jmhVersion 1.36 1.36
jvm /usr/lib/jvm/java-11-openjdk-amd64/bin/java /usr/lib/jvm/java-11-openjdk-amd64/bin/java
jvmArgs -Dhttp.proxyHost=127.0.0.1 -Dhttp.proxyPort=15002 -Dhttps.proxyHost=127.0.0.1 -Dhttps.proxyPort=15002 -Dhttp.nonProxyHosts=localhost *.localhost
kernel_version Linux runner-zfyrx7zua-project-304-concurrent-0-irsreu3v 6.8.0-1031-aws #33~22.04.1-Ubuntu SMP Thu Jun 26 14:22:30 UTC 2025 x86_64 x86_64 x86_64 GNU/Linux Linux runner-zfyrx7zua-project-304-concurrent-0-irsreu3v 6.8.0-1031-aws #33~22.04.1-Ubuntu SMP Thu Jun 26 14:22:30 UTC 2025 x86_64 x86_64 x86_64 GNU/Linux
vmName OpenJDK 64-Bit Server VM OpenJDK 64-Bit Server VM
vmVersion 11.0.31+11-post-1ubuntu1-22.04.2-Ubuntu 11.0.31+11-post-1ubuntu1-22.04.2-Ubuntu

Summary

Found 0 performance improvements and 1 performance regressions! Performance is the same for 2 metrics, 0 unstable metrics.

scenario Δ mean throughput
scenario:not-instrumented/KafkaConsumerBenchmark.benchConsume worse
[-13570.181op/s; -3969.474op/s] or [-4.589%; -1.342%]
See unchanged results
scenario Δ mean throughput
scenario:only-tracing-dsm-disabled-benchmarks/KafkaConsumerBenchmark.benchConsume same
scenario:only-tracing-dsm-enabled-benchmarks/KafkaConsumerBenchmark.benchConsume same

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

Labels

comp: tooling Build & Tooling tag: ai generated Largely based on code generated by an AI or LLM tag: no release notes Changes to exclude from release notes type: refactoring

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants