Skip to content

Reformat Java sources with Prince of Space 2.3.1 - #12445

Draft
bric3 wants to merge 2 commits into
bdu/use-prince-of-spacefrom
bdu/reformat-with-prince-of-space
Draft

bric3 wants to merge 2 commits into
bdu/use-prince-of-spacefrom
bdu/reformat-with-prince-of-space

Conversation

@bric3

@bric3 bric3 commented Sep 9, 2026 •

Copy link
Copy Markdown
Contributor

What Does This Do

Reformats 6,093 Java files with Prince of Space 2.3.1, using the configuration in #12444.
The output is regenerated from clean master sources at 3ab1b2050365377e42f546710cfdc314639476b0 and contains Java formatting changes only.

  • Update system-test snapshots for the new source line numbers.

Representative Formatting Changes

Each diff compares google-java-format 1.36.1 on master 3ab1b20503 with Prince of Space 2.3.1 on 2931a8d7dc. Lambda and anonymous-class excerpts include their closing braces and parentheses.

Lambda Pipelines

PluginApplication.java

-        Extension.EXTENSIONS.stream()
-            .filter(ext -> ext.appliesTo(spec))
-            .forEach(
-                ext -> {
-                  try {
-                    ext.apply(configuration, result);
-                  } catch (final Throwable e) {
-                    result.addError(e, ErrorCode.EXTENSION_ERROR, ext.getClass());
-                  }
-                });
+        Extension.EXTENSIONS
+          .stream()
+          .filter(ext -> ext.appliesTo(spec))
+          .forEach(ext -> {
+            try {
+              ext.apply(configuration, result);
+            } catch (final Throwable e) {
+              result.addError(e, ErrorCode.EXTENSION_ERROR, ext.getClass());
+            }
+          });

Fluent Calls

AdviceGeneratorImpl.java

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

Nested Callbacks

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

AssertBuilder.java

   protected Set<Class<?>> getSpi(ClassOrInterfaceDeclaration type) {
-    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()
-                                .map(
-                                    value ->
-                                        value
-                                            .asClassExpr()
-                                            .getType()
-                                            .resolve()
-                                            .asReferenceType()
-                                            .getTypeDeclaration()
-                                            .get()
-                                            .getQualifiedName()))
-                    .map(AssertBuilder::loadClass)
-                    .collect(Collectors.toSet()))
-        .orElse(Collections.emptySet());
+    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()
+          .map(value -> value
+            .asClassExpr()
+            .getType()
+            .resolve()
+            .asReferenceType()
+            .getTypeDeclaration()
+            .get()
+            .getQualifiedName()))
+        .map(AssertBuilder::loadClass)
+        .collect(Collectors.toSet()))
+      .orElse(Collections.emptySet());
   }

Balanced Parameter Wrapping

PluginApplication.java

   private static void printReport(
-      final Configuration configuration, final List<CallSiteResult> result, final boolean failed) {
-    CallSiteReporter.getReporter(configuration)
-        .forEach(reporter -> reporter.report(result, failed));
+      final Configuration configuration,
+      final List<CallSiteResult> result,
+      final boolean failed
+  ) {
+    CallSiteReporter
+      .getReporter(configuration)
+      .forEach(reporter -> reporter.report(result, failed));
   }

The configuration uses two-space indentation, a 100-character line width, balanced wrapping and Prince's default closingParenOnNewLine(true).

Lambda in an HTTP Builder Chain

SharedCommunicationObjects.java

Before (google-java-format 1.36.1):

  private OkHttpClient injectTestAgentSessionHeaderInterceptor(String testSessionToken) {
    return agentHttpClient
        .newBuilder()
        .addInterceptor(
            chain ->
                chain.proceed(
                    chain
                        .request()
                        .newBuilder()
                        .header(X_DATADOG_TEST_SESSION_TOKEN, testSessionToken)
                        .build()))
        .build();
  }

After (Prince of Space 2.3.1):

  private OkHttpClient injectTestAgentSessionHeaderInterceptor(String testSessionToken) {
    return agentHttpClient
      .newBuilder()
      .addInterceptor(chain -> chain.proceed(chain
        .request()
        .newBuilder()
        .header(X_DATADOG_TEST_SESSION_TOKEN, testSessionToken)
        .build()
      ))
      .build();
  }

Anonymous Classes in Method Calls

PluginApplication.java

-      Files.walkFileTree(
-          configuration.classesFolder,
-          new SimpleFileVisitor<Path>() {
-            public FileVisitResult visitFile(final Path file, final BasicFileAttributes attrs) {
-              if (Files.isRegularFile(file)
-                  && pattern.matcher(file.getFileName().toString()).matches()) {
-                builder.build(file.toFile()).ifPresent(result::add);
-              }
-              return FileVisitResult.CONTINUE;
-            }
-          });
+      Files.walkFileTree(configuration.classesFolder, new SimpleFileVisitor<Path>() {
+        public FileVisitResult visitFile(final Path file, final BasicFileAttributes attrs) {
+          if (Files.isRegularFile(file)
+              && pattern.matcher(file.getFileName().toString()).matches()) {
+            builder.build(file.toFile()).ifPresent(result::add);
+          }
+          return FileVisitResult.CONTINUE;
+        }
+      });

Ternary Expressions

SharedCommunicationObjects.java

-    httpClientTimeout =
-        config.isCiVisibilityEnabled()
-            ? config.getCiVisibilityBackendApiTimeoutMillis()
-            : TimeUnit.SECONDS.toMillis(config.getAgentTimeout());
+    httpClientTimeout = config.isCiVisibilityEnabled()
+        ? config.getCiVisibilityBackendApiTimeoutMillis()
+        : TimeUnit.SECONDS.toMillis(config.getAgentTimeout());

Mandatory Braces

CoreTracer.java

-      if (this.inUse) return false;
+      if (this.inUse) {
+        return false;
+      }

Javadoc Normalisation

CoreTracer.java

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

Import Separation

PluginApplication.java

 import static datadog.trace.plugin.csi.impl.CallSiteFactory.typeResolver;
-
 import datadog.trace.plugin.csi.AdviceGenerator.CallSiteResult;

Motivation

Keep the generated output separate from the formatter configuration. The examples use the same source sites as #12421, #12422, #13144 and #13145 for comparison.

Additional Notes

This remains a draft formatter experiment stacked on #12444.

Caution

The Prince of Space 2.3.1 / TableTest formatter 1.1.2 pipeline still requires 129 file exclusions:

  • 102 files: TableTest formatter 1.1.2 turns concatenated row strings into separate annotation array elements;
  • 27 files: other comments are duplicated, removed or reordered.

These files retain their exact content from master. The exclusions are listed in gradle/spotless.gradle.

Prince 2.3.1 preserves the surrogate char literals in both TraceGenerator fixtures and the escaped NUL in PatchUtil, so these three files are re-enabled. The exclusions decrease from 132 to 129.

ClientIpAddressResolver now formats its IPv4 range array without the added fence: its range comments appear once and in order. TagInterceptorTest keeps two narrow spotless:off / spotless:on fences for long TableTest arrays; their comments now identify the TableTest formatter as the component that corrupts concatenated rows.

Direct API checks reproduce the TableTest failure independently of Prince. The three targeted Prince reproductions pass with 2.3.1. Other comment duplication remains: Prince 2.3.1 prints the "All bits set" field comment in DD64bTraceId twice, without Spotless or the TableTest formatter.

The included sources pass the preservation audit and a forced second Java formatting pass. The audit checks parsed structure, identifiers, decoded literals and constant strings, TableTest data, comment content and order, and exact fenced regions. It permits added control-flow braces, conventional comment layout and import organisation. Inline comments can move to a preceding line.

The uncached repository-wide reformat used an 8 GB Gradle daemon heap after the 4 GB run exhausted its heap. Both final passes disable the build cache following a Spotless cached-output file-move failure.

A forced rerun of all Spotless formats stalled in :dd-smoke-tests:java9-modules:spotlessGroovyGradle and was stopped. The forced stability check therefore targets Java formatting tasks.

Focused core tests use a temporary external init script to omit an unrelated private container-image lookup; test caching is disabled for that run. Full-suite tests and performance benchmarks were not run.

Contributor Checklist

@bric3 bric3 added tag: no release notes Changes to exclude from release notes type: refactoring tag: experimental Experimental changes comp: tooling Build & Tooling tag: ai generated Largely based on code generated by an AI or LLM labels Sep 9, 2026
@bric3
bric3 added this pull request to stack #12446 September 9, 2026 16:29
@bric3
bric3 force-pushed the bdu/reformat-with-prince-of-space branch from 4f14d64 to 28f72b5 Compare September 9, 2026 21:07
@bric3 bric3 mentioned this pull request Oct 1, 2026
@bric3
bric3 force-pushed the bdu/reformat-with-prince-of-space branch from 5eb8c5c to 79a09e5 Compare November 1, 2026 15:36
@bric3 bric3 changed the title Reformat Java sources with Prince of Space Reformat Java sources with Prince of Space 2.3.0 Nov 1, 2026
@pr-commenter

pr-commenter Bot commented Nov 1, 2026 •

Copy link
Copy Markdown

Debugger benchmarks

Parameters

Baseline Candidate
baseline_or_candidate baseline candidate
ci_job_date 1793629909 1793630235
end_time 2026-11-02T14:33:17 2026-11-02T14:38:43
git_branch master bdu/reformat-with-prince-of-space
git_commit_sha 087b04f c0d0f5f
start_time 2026-11-02T14:31:50 2026-11-02T14:37:16
See matching parameters
Baseline Candidate
ci_job_id 2201402510 2201402510
ci_pipeline_id 149392040 149392040
cpu_model Intel(R) Xeon(R) Platinum 8259CL CPU @ 2.50GHz Intel(R) Xeon(R) Platinum 8259CL CPU @ 2.50GHz
git_commit_date 1793629061 1793629061

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
[-31.024µs; +49.448µs] or [-9.739%; +15.523%]
unstable
[-39.205µs; +64.393µs] or [-11.134%; +18.287%]
unstable
[-47.818µs; +76.997µs] or [-13.030%; +20.981%]
unstable
[-150.913µs; +422.187µs] or [-12.892%; +36.067%]
same
scenario:basic same unsure
[+0.288µs; +12.817µs] or [+0.088%; +3.918%]
unsure
[+0.778µs; +12.993µs] or [+0.231%; +3.857%]
unstable
[-181.762µs; +33.975µs] or [-16.158%; +3.020%]
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 (352.12 µs) : 317, 388
.   : milestone, 352,
basic (327.118 µs) : 320, 334
.   : milestone, 327,
loop (8.096 ms) : 8033, 8160
.   : milestone, 8096,
section candidate
noprobe (364.714 µs) : 305, 425
.   : milestone, 365,
basic (333.671 µs) : 329, 339
.   : milestone, 334,
loop (8.102 ms) : 8040, 8164
.   : milestone, 8102,
Loading
  • baseline results
Scenario Request median duration [CI 0.99]
noprobe 352.12 µs [316.668 µs, 387.571 µs]
basic 327.118 µs [320.131 µs, 334.106 µs]
loop 8.096 ms [8.033 ms, 8.16 ms]
  • candidate results
Scenario Request median duration [CI 0.99]
noprobe 364.714 µs [304.82 µs, 424.608 µs]
basic 333.671 µs [328.623 µs, 338.719 µs]
loop 8.102 ms [8.04 ms, 8.164 ms]

@datadog-prod-us1-5

datadog-prod-us1-5 Bot commented Nov 1, 2026 •

Copy link
Copy Markdown
Contributor

🎯 Code Coverage (details)
• Patch Coverage: 57.02%
• Overall Coverage: 59.84%

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: c0d0f5f | Docs | Give us feedback!

@dd-octo-sts

dd-octo-sts Bot commented Nov 1, 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.78 s 14.68 s [-0.2%; +1.5%] (no difference)
startup:insecure-bank:tracing:Agent 13.65 s 13.63 s [-0.6%; +1.0%] (no difference)
startup:petclinic:appsec:Agent 17.19 s 17.05 s [-0.0%; +1.7%] (no difference)
startup:petclinic:iast:Agent 17.11 s 17.02 s [-0.3%; +1.2%] (no difference)
startup:petclinic:profiling:Agent 16.65 s 16.92 s [-2.7%; -0.5%] (maybe better)
startup:petclinic:sca:Agent 17.20 s 16.90 s [+1.0%; +2.6%] (maybe worse)
startup:petclinic:tracing:Agent 16.21 s 16.21 s [-0.9%; +0.9%] (no difference)

Commit: c0d0f5fc · 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 Nov 1, 2026 •

Copy link
Copy Markdown

Kafka / producer-benchmark

Parameters

Baseline Candidate
baseline_or_candidate baseline candidate
git_branch bdu/use-prince-of-space bdu/reformat-with-prince-of-space
git_commit_date 1793616679 1793629061
git_commit_sha 933e5b6 c0d0f5f
See matching parameters
Baseline Candidate
ci_job_date 1793630414 1793630414
ci_job_id 2201402502 2201402502
ci_pipeline_id 149392040 149392040
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-jcx90erk 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-jcx90erk 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

@pr-commenter

pr-commenter Bot commented Nov 1, 2026 •

Copy link
Copy Markdown

Kafka / consumer-benchmark

Parameters

Baseline Candidate
baseline_or_candidate baseline candidate
git_branch bdu/use-prince-of-space bdu/reformat-with-prince-of-space
git_commit_date 1793616679 1793629061
git_commit_sha 933e5b6 c0d0f5f
See matching parameters
Baseline Candidate
ci_job_date 1793630457 1793630457
ci_job_id 2201402506 2201402506
ci_pipeline_id 149392040 149392040
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-h7v62718 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-h7v62718 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/KafkaConsumerBenchmark.benchConsume unsure
[-15958.523op/s; -2370.811op/s] or [-5.332%; -0.792%]
scenario:only-tracing-dsm-disabled-benchmarks/KafkaConsumerBenchmark.benchConsume same
scenario:only-tracing-dsm-enabled-benchmarks/KafkaConsumerBenchmark.benchConsume same

@bric3
bric3 force-pushed the bdu/reformat-with-prince-of-space branch from 79a09e5 to e2a4048 Compare November 1, 2026 19:44
@bric3
bric3 force-pushed the bdu/reformat-with-prince-of-space branch from e2a4048 to 2931a8d Compare November 2, 2026 10:52
@bric3 bric3 changed the title Reformat Java sources with Prince of Space 2.3.0 Reformat Java sources with Prince of Space 2.3.1 Nov 2, 2026
@bric3
bric3 force-pushed the bdu/reformat-with-prince-of-space branch from 734df03 to 2931a8d Compare November 2, 2026 12:19
Restore the master layout of line-sensitive Java sources and protect it
with Spotless fences. Reuse the two-line package header for the opening
fence so imports and executable code retain their original line numbers.

- WithHardcodedSecret: keep the secret returns at lines 9 and 13 for the
  IAST class-reader assertions.
- HardcodedSecretController: keep the secret return at line 11 for the
  Spring Boot IAST vulnerability-location assertion.
- LambdaScaHandler: keep the reflective invocation at line 38 for the
  Lambda SCA reachability assertions.
- DebuggerTestApplication: preserve the lines used by log, metric and
  span probes, including the 95-104 range.
- ServerDebuggerTestApplication: preserve the code-origin line 158 and
  the dynamic-enablement line probe at 329.
- InterfacedController: keep the controller method at line 11 for the
  Spring code-origin assertion.
- ExceptionProbeManagerTest: preserve the exception's stack frame so
  its expected fingerprint remains valid.
- ExceptionHelperTest: keep the exception at line 75 for the folded
  stack-trace assertion.
- HandlerMappingResourceNameFilter: keep filterChain.doFilter at line 57
  for exception-replay snapshots in the external system-tests repository.

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