Skip to content

Reformat Java sources with open-java-format - #12711

Draft
bric3 wants to merge 1 commit into
bdu/use-open-java-formatfrom
bdu/reformat-with-open-java-format
Draft

bric3 wants to merge 1 commit into
bdu/use-open-java-formatfrom
bdu/reformat-with-open-java-format

Conversation

@bric3

@bric3 bric3 commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

What Does This Do

Apply open-java-format 2.98.0.5 to 6,346 Java files with the configuration in #12710.

Representative Formatting Changes

These examples revisit the same methods as #12444, on master revision 3228587fbf0010a3834b47fd2b1c242445c5da2b.

Lambda Pipelines

PluginApplication.java

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

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);
+        }));

Long TableTest rows stay single annotation values, even when they exceed 120 columns. Spotless protects existing off/on regions around the Java and table steps.

Parameter Wrapping

In the same PluginApplication.printReport method, OJF packs the parameters on one continuation line and keeps the closing delimiter beside the final parameter. Prince's default balanced wrapping puts each parameter and the closing delimiter on separate lines. The experiments also use different widths: OJF 120 columns, Prince 100.

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

Switch Blocks

JsonToExpressionConverter.java

OJF joins the opening block with its case label. Prince keeps the original separate line.

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

Inline Argument Comments

In CoreTracer, OJF keeps the comment attached to its argument:

                    null /* serviceName */,

The Prince experiment moved that comment after the comma onto its own line. This is also one of the earlier formatter regressions checked during this evaluation.

Short Guards and Javadocs

OJF preserves these compact forms in CoreTracer; Prince adds braces to the guard and expands the Javadoc:

            if (this.inUse) return false;
    /** Tracer start time in nanoseconds measured up to a millisecond accuracy */

OJF also retains the blank line between static and regular imports, which the Prince experiment removed.

Motivation

Improve human readability of the source of google java format

Additional Notes

String reflow is disabled and TableTest formatting runs last.

A parsed audit of every changed Java file found no changes to AST node structure, literal values, or canonical table values and row counts.

run with
jbang tooling/VerifyFormatting.java \
    path/to/dd-trace-java-ojf-baseline \
    path/to/dd-trace-java-open-java-format \
    current-pr-java.txt
//JAVA 25
//DEPS org.tabletest:tabletest-formatter-core:1.1.2
import com.sun.source.tree.AnnotationTree;
import com.sun.source.tree.AssignmentTree;
import com.sun.source.tree.BinaryTree;
import com.sun.source.tree.IdentifierTree;
import com.sun.source.tree.ImportTree;
import com.sun.source.tree.LiteralTree;
import com.sun.source.tree.MemberSelectTree;
import com.sun.source.tree.NewArrayTree;
import com.sun.source.tree.ParenthesizedTree;
import com.sun.source.tree.Tree;
import com.sun.source.util.JavacTask;
import com.sun.source.util.TreeScanner;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
import javax.tools.Diagnostic;
import javax.tools.DiagnosticCollector;
import javax.tools.JavaFileObject;
import javax.tools.ToolProvider;
import org.tabletest.formatter.config.Config;
import org.tabletest.formatter.core.TableTestFormatter;

/** Audits parsed Java before and after formatting, excluding imports and table padding. */
class VerifyFormatting {
    record Snapshot(List<String> literals, List<String> tables, List<Tree.Kind> structure) {}

    static Map<String, Snapshot> read(Path root, List<String> paths) throws Exception {
        var result = new TreeMap<String, Snapshot>();
        var compiler = ToolProvider.getSystemJavaCompiler();
        var diagnostics = new DiagnosticCollector<JavaFileObject>();
        try (var manager = compiler.getStandardFileManager(diagnostics, null, null)) {
            var files = manager.getJavaFileObjectsFromPaths(
                    paths.stream().map(root::resolve).toList());
            var task = (JavacTask) compiler.getTask(
                    null,
                    manager,
                    diagnostics,
                    List.of("-proc:none", "--enable-preview", "--source", "25"),
                    null,
                    files);
            for (var unit : task.parse()) {
                var literals = new ArrayList<String>();
                var tables = new ArrayList<String>();
                var structure = new ArrayList<Tree.Kind>();
                new TreeScanner<Void, Void>() {
                    public Void scan(Tree node, Void ignored) {
                        if (node instanceof ImportTree) return null;
                        if (node != null) structure.add(node.getKind());
                        return super.scan(node, ignored);
                    }

                    public Void visitLiteral(LiteralTree node, Void ignored) {
                        literals.add(node.getKind() + ":" + node.getValue());
                        return null;
                    }

                    public Void visitAnnotation(AnnotationTree node, Void ignored) {
                        if (!node.getAnnotationType().toString().endsWith("TableTest"))
                            return super.visitAnnotation(node, ignored);
                        var rows = new ArrayList<String>();
                        for (var arg : node.getArguments()) {
                            Tree value = arg instanceof AssignmentTree assignment ? assignment.getExpression() : arg;
                            if (arg instanceof AssignmentTree assignment
                                    && !assignment.getVariable().toString().equals("value")) {
                                scan(arg, ignored);
                                continue;
                            }
                            if (value instanceof NewArrayTree array)
                                for (var row : array.getInitializers()) rows.add(stringValue(row));
                            else rows.add(stringValue(value));
                        }
                        tables.add(rows.size() + ":"
                                + new TableTestFormatter().format(String.join("\n", rows), "", Config.NO_INDENT));
                        return null;
                    }
                }.scan(unit, null);
                result.put(
                        root.relativize(Path.of(unit.getSourceFile().toUri())).toString(),
                        new Snapshot(literals, tables, structure));
            }
        }
        var errors = diagnostics.getDiagnostics().stream()
                .filter(d -> d.getKind() == Diagnostic.Kind.ERROR)
                .toList();
        if (!errors.isEmpty()) throw new AssertionError(errors.toString());
        return result;
    }

    static String stringValue(Tree value) {
        if (value instanceof LiteralTree literal && literal.getValue() instanceof String text) return text;
        if (value instanceof BinaryTree binary && binary.getKind() == Tree.Kind.PLUS)
            return stringValue(binary.getLeftOperand()) + stringValue(binary.getRightOperand());
        if (value instanceof ParenthesizedTree parens) return stringValue(parens.getExpression());
        if (value instanceof IdentifierTree || value instanceof MemberSelectTree) return "${" + value + "}";
        throw new AssertionError("Unsupported TableTest value: " + value);
    }

    public static void main(String[] args) throws Exception {
        if (args.length < 3 || args.length > 4 || (args.length == 4 && !args[3].equals("tables"))) {
            throw new IllegalArgumentException(
                    "Usage: VerifyFormatting.java before-root after-root paths-file [tables]");
        }
        var paths = Files.readAllLines(Path.of(args[2]));
        var before = read(Path.of(args[0]).toAbsolutePath(), paths);
        var after = read(Path.of(args[1]).toAbsolutePath(), paths);
        int failures = 0;
        for (var path : paths) {
            var a = before.get(path);
            var b = after.get(path);
            if (args.length > 3 ? !a.tables.equals(b.tables) : !a.equals(b)) {
                System.out.println(path + " literals=" + a.literals.equals(b.literals) + " tables="
                        + a.tables.equals(b.tables) + " structure=" + a.structure.equals(b.structure));
                failures++;
            }
        }
        System.out.println("Audited " + paths.size() + " Java files; differences=" + failures);
        if (failures != 0) throw new AssertionError("Formatter changed parsed source");
    }
}

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 Oct 1, 2026
@bric3 bric3 mentioned this pull request Oct 1, 2026
@bric3
bric3 force-pushed the bdu/reformat-with-open-java-format branch from b0152a5 to 09403da Compare October 1, 2026 15:09
@datadog-datadog-prod-us1-2

datadog-datadog-prod-us1-2 Bot commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

🎯 Code Coverage (details)
• Patch Coverage: 59.57%
• Overall Coverage: 59.37%

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

@pr-commenter

pr-commenter Bot commented Oct 1, 2026 •

Copy link
Copy Markdown

Debugger benchmarks

Parameters

Baseline Candidate
baseline_or_candidate baseline candidate
ci_job_date 1790871680 1790871995
end_time 2026-10-01T16:22:47 2026-10-01T16:28:03
git_branch master bdu/reformat-with-open-java-format
git_commit_sha 8887cb7 12092cc
start_time 2026-10-01T16:21:20 2026-10-01T16:26:36
See matching parameters
Baseline Candidate
ci_job_id 2099817008 2099817008
ci_pipeline_id 141695349 141695349
cpu_model Intel(R) Xeon(R) Platinum 8259CL CPU @ 2.50GHz Intel(R) Xeon(R) Platinum 8259CL CPU @ 2.50GHz
git_commit_date 1790869592 1790869592

Summary

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

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:loop worse
[+462.557µs; +561.146µs] or [+6.152%; +7.463%]
worse
[+464.916µs; +565.959µs] or [+6.140%; +7.474%]
worse
[+456.172µs; +564.704µs] or [+5.995%; +7.421%]
worse
[+447.733µs; +593.550µs] or [+5.814%; +7.708%]
worse
[-10.024op/s; -5.814op/s] or [-7.719%; -4.476%]
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
[-76.693µs; +42.835µs] or [-22.587%; +12.615%]
unstable
[-82.507µs; +52.365µs] or [-22.269%; +14.134%]
unstable
[-107.074µs; +65.755µs] or [-27.346%; +16.794%]
unstable
[-628.190µs; +213.941µs] or [-44.560%; +15.176%]
same
scenario:basic same same same unstable
[-122.373µs; +132.719µs] or [-11.647%; +12.632%]
unstable
[-216.776op/s; +111.068op/s] or [-9.321%; +4.776%]
Request duration reports for reports
gantt
    title reports - request duration [CI 0.99] : candidate=None, baseline=None
    dateFormat X
    axisFormat %s
section baseline
noprobe (370.497 µs) : 294, 447
.   : milestone, 370,
basic (325.191 µs) : 319, 332
.   : milestone, 325,
loop (7.572 ms) : 7552, 7592
.   : milestone, 7572,
section candidate
noprobe (355.426 µs) : 307, 404
.   : milestone, 355,
basic (327.516 µs) : 321, 334
.   : milestone, 328,
loop (8.087 ms) : 8024, 8151
.   : milestone, 8087,
Loading
  • baseline results
Scenario Request median duration [CI 0.99]
noprobe 370.497 µs [293.977 µs, 447.017 µs]
basic 325.191 µs [318.634 µs, 331.748 µs]
loop 7.572 ms [7.552 ms, 7.592 ms]
  • candidate results
Scenario Request median duration [CI 0.99]
noprobe 355.426 µs [306.898 µs, 403.954 µs]
basic 327.516 µs [321.455 µs, 333.576 µs]
loop 8.087 ms [8.024 ms, 8.151 ms]

@dd-octo-sts

dd-octo-sts Bot commented Oct 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.02 s 14.04 s [-0.8%; +0.5%] (no difference)
startup:insecure-bank:tracing:Agent 12.94 s 12.99 s [-1.1%; +0.4%] (no difference)
startup:petclinic:appsec:Agent 17.20 s 17.03 s [+0.2%; +1.8%] (maybe worse)
startup:petclinic:iast:Agent 16.98 s 16.92 s [-0.4%; +1.2%] (no difference)
startup:petclinic:profiling:Agent 16.63 s 16.61 s [-0.9%; +1.1%] (no difference)
startup:petclinic:sca:Agent 17.10 s 16.97 s [-0.3%; +1.8%] (no difference)
startup:petclinic:tracing:Agent 16.33 s 16.22 s [-0.3%; +1.7%] (no difference)

Commit: 12092cc1 · 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 Oct 1, 2026

Copy link
Copy Markdown

Kafka / producer-benchmark

Parameters

Baseline Candidate
baseline_or_candidate baseline candidate
git_branch bdu/use-open-java-format bdu/reformat-with-open-java-format
git_commit_date 1790867285 1790867289
git_commit_sha 7206293 09403da
See matching parameters
Baseline Candidate
ci_job_date 1790868824 1790868824
ci_job_id 2099444991 2099444991
ci_pipeline_id 141669547 141669547
cpu_model Intel(R) Xeon(R) Platinum 8175M CPU @ 2.50GHz Intel(R) Xeon(R) Platinum 8175M 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-tnrms8ab 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-tnrms8ab 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 unsure
[-4987.127op/s; -37.879op/s] or [-3.616%; -0.027%]

@bric3
bric3 force-pushed the bdu/reformat-with-open-java-format branch from 09403da to 12092cc Compare October 1, 2026 16:07
@bric3
bric3 added this pull request to stack #12714 October 1, 2026 16:08
@pr-commenter

pr-commenter Bot commented Oct 1, 2026

Copy link
Copy Markdown

Kafka / consumer-benchmark

Parameters

Baseline Candidate
baseline_or_candidate baseline candidate
git_branch bdu/use-open-java-format bdu/reformat-with-open-java-format
git_commit_date 1790869587 1790869592
git_commit_sha 76c0948 12092cc
See matching parameters
Baseline Candidate
ci_job_date 1790872262 1790872262
ci_job_id 2099817003 2099817003
ci_pipeline_id 141695349 141695349
cpu_model Intel(R) Xeon(R) Platinum 8175M CPU @ 2.50GHz Intel(R) Xeon(R) Platinum 8175M 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-0uqfxbiv 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-0uqfxbiv 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 same
scenario:only-tracing-dsm-disabled-benchmarks/KafkaConsumerBenchmark.benchConsume same
scenario:only-tracing-dsm-enabled-benchmarks/KafkaConsumerBenchmark.benchConsume unsure
[+495.053op/s; +8009.174op/s] or [+0.303%; +4.906%]

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