Skip to content

Reformat Java sources with Google Java Format 2 - #13145

Draft
bric3 wants to merge 1 commit into
bdu/use-google-java-format-2from
bdu/reformat-with-google-java-format-2
Draft

bric3 wants to merge 1 commit into
bdu/use-google-java-format-2from
bdu/reformat-with-google-java-format-2

Conversation

@bric3

@bric3 bric3 commented Oct 31, 2026

Copy link
Copy Markdown
Contributor

What Does This Do

Reformats 342 Java files with Google Java Format 2.0.0 and its default cleanup pass. No non-Java files are changed.

Representative Formatting Changes

These examples use the exact source sites and inputs from #12444 and #12445, at commit 36ca5fbc827f21df1ebd9574ed4ba36c917958a3. The PR stack itself starts from current master, c30d76e0715baa06b6104606f8285153c66a6b04.

The output below comes from Google Java Format 2.0.0 with the default Google style and cleanups enabled, and long-string reflow disabled, matching the Spotless configuration.

Lambda Pipelines

The sole lambda argument now starts beside forEach, reducing the indentation inside its body.

PluginApplication.java

         Extension.EXTENSIONS.stream()
             .filter(ext -> ext.appliesTo(spec))
-            .forEach(
-                ext -> {
+            .forEach(ext -> {

Fluent Calls

This fluent call keeps its existing layout.

AdviceGeneratorImpl.java

      final List<Expression> helperTypes =
          Arrays.stream(helpers)
              .map(type -> new StringLiteralExpr(type.getClassName()))
              .collect(Collectors.toList());

Nested Callbacks

Both sole lambda arguments move beside their calls. The scheduler call keeps a continuation line.

CoreTracer.java

-    sharedCommunicationObjects.whenReady(
-        () ->
-            AgentTaskScheduler.get()
-                .execute(
-                    () -> {
-                      startMetricsAggregation(config, sco);
-                      maybeStartLogsExport(config);
-                    }));
+    sharedCommunicationObjects.whenReady(() ->
+        AgentTaskScheduler.get()
+            .execute(() -> {
+              startMetricsAggregation(config, sco);
+              maybeStartLogsExport(config);
+            }));

Nested Lambda Pipelines

The map and flatMap lambdas move beside their calls, reducing the indentation of the nested pipeline.

AssertBuilder.java

     return type.getAnnotationByName("AutoService")
-        .<Set<Class<?>>>map(
-            annotation ->
-                annotation.asNormalAnnotationExpr().getPairs().stream()
-                    .filter(pair -> pair.getNameAsString().equals("value"))
-                    .flatMap(
-                        pair ->
-                            pair.getValue().asArrayInitializerExpr().getValues().stream()
+        .<Set<Class<?>>>map(annotation ->
+            annotation.asNormalAnnotationExpr().getPairs().stream()
+                .filter(pair -> pair.getNameAsString().equals("value"))
+                .flatMap(pair ->
+                    pair.getValue().asArrayInitializerExpr().getValues().stream()

Parameter Wrapping

The same method signature keeps its existing layout.

PluginApplication.java

  private static void printReport(
      final Configuration configuration, final List<CallSiteResult> result, final boolean failed) {

Control-flow Braces

The single-statement if keeps its existing layout.

CoreTracer.java

      if (this.inUse) return false;

Javadoc Formatting

This one-line Javadoc stays on one line.

CoreTracer.java

  /** Tracer start time in nanoseconds measured up to a millisecond accuracy */

Inline Comment Placement

The argument comment stays beside null.

CoreTracer.java

          null /* serviceName */,

Import Separation

The blank line between static and regular imports is preserved.

PluginApplication.java

import static datadog.trace.plugin.csi.impl.CallSiteFactory.typeResolver;

import datadog.trace.plugin.csi.AdviceGenerator.CallSiteResult;

Switch Blocks Stay Unchanged

The same switch case keeps its existing layout.

JsonToExpressionConverter.java

case "not":
  {
    JsonReader.Token token = reader.peek();

Default Cleanups

Google Java Format 2.0.0 also removes this redundant semicolon in the original CoreTracer input. The cleanup pass is enabled by default. It also supports removing empty annotation parentheses and parentheses around a single untyped lambda parameter.

CoreTracer.java

         final Pair<String, CharSequence> serviceNameAndSource =
             traceConfig.getPreferredServiceNameAndSource();
-        ;
         if (serviceNameAndSource != null && serviceNameAndSource.hasLeft()) {

Motivation

Keep the mechanical output separate from the formatter configuration in #13144. The stack starts from current master, while the showcase reuses the original inputs from the earlier formatter experiments for direct comparison.

Additional Notes

This draft is stacked on #13144.

A Java 25 parsed-source audit of all 342 changed files found no unexpected differences in source structure, identifiers, literal values, TableTest rows, comment content and placement, or Spotless-fenced regions. The audit allows the documented cleanup transformations. It checked 32,284 literal values, 130 TableTest annotations, 4,124 comments, and 14 fenced regions.

TagInterceptorTest was run with a temporary init script that removes the unused container-image JVM argument provider from :dd-trace-core:test, with task reuse and build-cache reuse disabled. The normal task attempted to resolve a private test-agent image before starting this container-free test and could not reach the registry. The init script is outside the repository and is not part of this PR.

Focused core-test workaround (165 tests passed)

Save this as a temporary focused-core-test.init.gradle.kts:

import org.gradle.api.tasks.testing.Test

gradle.projectsEvaluated {
  rootProject.findProject(":dd-trace-core")?.tasks?.named<Test>("test")?.configure {
    jvmArgumentProviders.removeIf {
      it.javaClass.name == "datadog.buildlogic.testcontainers.ContainerImageArguments"
    }
    outputs.upToDateWhen { false }
  }
}
./gradlew :dd-trace-core:test --tests datadog.trace.core.taginterceptor.TagInterceptorTest -PtestJvm=25 --init-script /path/to/focused-core-test.init.gradle.kts --no-build-cache --no-configuration-cache

The full repository test suite and performance benchmarks were not run.

Related experiments: #12421 / #12422 and #12444 / #12445.

Contributor Checklist

@bric3 bric3 added comp: tooling Build & Tooling tag: ai generated Largely based on code generated by an AI or LLM tag: experimental Experimental changes tag: no release notes Changes to exclude from release notes type: refactoring labels Oct 31, 2026
@datadog-datadog-prod-us1-2

This comment has been minimized.

@pr-commenter

pr-commenter Bot commented Oct 31, 2026

Copy link
Copy Markdown

Debugger benchmarks

Parameters

Baseline Candidate
baseline_or_candidate baseline candidate
ci_job_date 1793466387 1793466714
end_time 2026-10-31T17:07:56 2026-10-31T17:13:22
git_branch master bdu/reformat-with-google-java-format-2
git_commit_sha c30d76e 6095616
start_time 2026-10-31T17:06:28 2026-10-31T17:11:55
See matching parameters
Baseline Candidate
ci_job_id 2199233171 2199233171
ci_pipeline_id 149188328 149188328
cpu_model Intel(R) Xeon(R) Platinum 8259CL CPU @ 2.50GHz Intel(R) Xeon(R) Platinum 8259CL CPU @ 2.50GHz
git_commit_date 1793465709 1793465709

Summary

Found 0 performance improvements and 0 performance regressions! Performance is the same for 9 metrics, 6 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
[-49.850µs; +15.032µs] or [-15.156%; +4.570%]
unstable
[-64.848µs; +24.518µs] or [-17.876%; +6.759%]
unstable
[-75.451µs; +31.912µs] or [-19.980%; +8.451%]
unstable
[-108.548µs; +268.307µs] or [-8.587%; +21.225%]
same
scenario:basic same same same unstable
[+58.403µs; +303.219µs] or [+5.367%; +27.866%]
unstable
[-74.539op/s; +180.247op/s] or [-3.280%; +7.931%]
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 (362.763 µs) : 309, 417
.   : milestone, 363,
basic (327.406 µs) : 321, 334
.   : milestone, 327,
loop (8.096 ms) : 8034, 8159
.   : milestone, 8096,
section candidate
noprobe (342.598 µs) : 316, 369
.   : milestone, 343,
basic (326.946 µs) : 322, 332
.   : milestone, 327,
loop (8.097 ms) : 8034, 8160
.   : milestone, 8097,
Loading
  • baseline results
Scenario Request median duration [CI 0.99]
noprobe 362.763 µs [308.796 µs, 416.73 µs]
basic 327.406 µs [320.622 µs, 334.189 µs]
loop 8.096 ms [8.034 ms, 8.159 ms]
  • candidate results
Scenario Request median duration [CI 0.99]
noprobe 342.598 µs [316.317 µs, 368.879 µs]
basic 326.946 µs [322.036 µs, 331.857 µs]
loop 8.097 ms [8.034 ms, 8.16 ms]

@dd-octo-sts

dd-octo-sts Bot commented Oct 31, 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.01 s 13.89 s [+0.3%; +1.5%] (maybe worse)
startup:insecure-bank:tracing:Agent 13.00 s 13.03 s [-1.2%; +0.7%] (no difference)
startup:petclinic:appsec:Agent 17.15 s 16.40 s [+0.1%; +9.1%] (maybe worse)
startup:petclinic:iast:Agent 16.92 s 16.98 s [-1.2%; +0.4%] (no difference)
startup:petclinic:profiling:Agent 16.72 s 16.78 s [-1.2%; +0.5%] (no difference)
startup:petclinic:sca:Agent 17.09 s 17.00 s [-0.4%; +1.4%] (no difference)
startup:petclinic:tracing:Agent 16.17 s 16.16 s [-0.8%; +1.0%] (no difference)

Commit: 60956161 · 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.

This branch has not been deployed

No deployments
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: experimental Experimental changes 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.

1 participant