Skip to content

Use Google Java Format 2 - #13144

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

bric3 wants to merge 1 commit into
masterfrom
bdu/use-google-java-format-2

Conversation

@bric3

@bric3 bric3 commented Oct 31, 2026 •

Copy link
Copy Markdown
Contributor

What Does This Do

Upgrades every Spotless Java configuration from google-java-format 1.36.1 to 2.0.0 through the shared version catalog.
It keeps the existing two-space indentation and 100-character line width, enables GJF 2's default cleanups, and keeps long-string reflow disabled.

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

Evaluate Google Java Format 2's new layout engine, particularly its lambda formatting, against the same representative code used by the Palantir and Prince of Space experiments.

Additional Notes

This is the configuration layer of a two-PR draft experiment. Java reformatting is isolated in #13145.

The existing Spotless 8.10.4 integration supports GJF 2.0.0. The upgrade uses its default cleanup pass, which can make small source changes as shown above. GJF 2.0.0 release notes.

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

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