Skip to content

Commit f850f56

Browse files
authored
Fix spotless:apply failure on modern JDKs (#777)
## Summary - Pin `google-java-format` to **1.22.0** in the root `pom.xml` so `mvn spotless:apply` stops crashing on modern JDKs (the code generator runs on JDK 25, where spotless-maven-plugin 2.30.0's bundled GJF 1.15.0 throws `NoSuchMethodError` against the renamed `com.sun.tools.javac.util.Log$DeferredDiagnosticHandler.getDiagnostics()` signature). 1.22.0 is the last GJF release that still supports JRE 11, keeping local dev and the JDK 11 `fmt` CI job working. - Add `scripts/mvn-spotless-apply.sh`, a drop-in wrapper that exports `MAVEN_OPTS` with the `--add-exports=jdk.compiler/com.sun.tools.javac.*=ALL-UNNAMED` flags required by GJF on JDK 16+. It detects the JDK major version and only sets the flags when needed, so older JDKs (including the JDK 8 CI matrix rows) are untouched. `.codegen.json`'s `post_generate` now invokes the wrapper instead of `mvn spotless:apply` directly, mirroring the existing `bash scripts/cleanup-services.sh` pattern. - One-time reformat of 6 files (16 blank lines inserted, 0 deletions) to satisfy GJF 1.22.0's stricter rules around blank lines between documented fields. No semantic changes. ### Why a wrapper script and not `.mvn/jvm.config`? `.mvn/jvm.config` applies to every Maven invocation, and this repo's CI matrix runs `mvn test` / release jobs under JDK 8, where `--add-exports` is an unrecognized arg and Maven would fail to start. Scoping the flags to the one command that actually needs them (`spotless:apply`) avoids that blast radius. ### Impact on CI - `fmt` (JDK 11 → `spotless:check`): GJF 1.22.0 loads fine on JRE 11. - `unit-tests` matrix (JDK 8/11/17/20 → `mvn test`): unaffected, spotless plugin has no `<execution>` binding so it never runs during tests. - `release-build-check` / `package` (JDK 8): unaffected, same reason. - Compiled bytecode target remains Java 8; GJF only reformats source whitespace. ## Test plan - [x] `mvn spotless:check` passes on local JDK 11 after the reformat - [x] `mvn spotless:apply` on clean HEAD (after pom bump) produces the expected 6-file reformat only; subsequent runs are no-ops (idempotent) - [x] `bash scripts/mvn-spotless-apply.sh` on JDK 11 correctly skips the `MAVEN_OPTS` export (`JDK < 16`) and delegates to `mvn spotless:apply` with `BUILD SUCCESS` - [x] CI green across all matrix rows (JDK 8/11/17/20 unit-tests, JDK 11 fmt, JDK 8 release-build-check) NO_CHANGELOG=true
1 parent 547b204 commit f850f56

9 files changed

Lines changed: 52 additions & 2 deletions

File tree

.codegen.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@
1414
"toolchain": {
1515
"require": ["mvn", "java"],
1616
"setup": ["bash scripts/cleanup-services.sh"],
17-
"post_generate": ["mvn spotless:apply","mvn --errors clean test"]
17+
"post_generate": ["bash scripts/mvn-spotless-apply.sh","mvn --errors clean test"]
1818
}
1919
}

databricks-sdk-java/src/main/java/com/databricks/sdk/AccountClient.java

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

databricks-sdk-java/src/main/java/com/databricks/sdk/core/GrpcTranscodingQueryParamsSerializer.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ public String getValue() {
3737
return value;
3838
}
3939
}
40+
4041
/**
4142
* Serializes an object into a map of query parameter values compatible with gRPC-transcoding.
4243
*

databricks-sdk-java/src/main/java/com/databricks/sdk/core/http/Request.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,21 +22,25 @@ public class Request {
2222
private final Map<String, String> headers = new HashMap<>();
2323
private final Map<String, List<String>> query = new TreeMap<>();
2424
private Optional<Boolean> redirectionBehavior = Optional.empty();
25+
2526
/**
2627
* The body of the request for requests with streaming bodies. At most one of {@link #bodyStream}
2728
* and {@link #bodyString} can be non-null.
2829
*/
2930
private final InputStream bodyStream;
31+
3032
/**
3133
* The body of the request for requests with string bodies. At most one of {@link #bodyStream} and
3234
* {@link #bodyString} can be non-null.
3335
*/
3436
private final String bodyString;
37+
3538
/**
3639
* Whether the body of the request is a streaming body. At most one of {@link #isBodyStreaming}
3740
* and {@link #isBodyString} can be true.
3841
*/
3942
private final boolean isBodyStreaming;
43+
4044
/**
4145
* Whether the body of the request is a string body. At most one of {@link #isBodyStreaming} and
4246
* {@link #isBodyString} can be true.

databricks-sdk-java/src/main/java/com/databricks/sdk/core/oauth/DataPlaneTokenSource.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ public class DataPlaneTokenSource {
2121
private final String host;
2222
private final boolean asyncDisabled;
2323
private final ConcurrentHashMap<TokenSourceKey, CachedTokenSource> sourcesCache;
24+
2425
/**
2526
* Caching key for {@link EndpointTokenSource}, based on endpoint and authorization details. This
2627
* is a value object that uniquely identifies a token source configuration.

databricks-sdk-java/src/main/java/com/databricks/sdk/core/oauth/DatabricksOAuthTokenSource.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,25 @@ public class DatabricksOAuthTokenSource implements TokenSource {
2121

2222
/** OAuth client ID used for token exchange. */
2323
private final String clientId;
24+
2425
/** Databricks host URL. */
2526
private final String host;
27+
2628
/** Databricks account ID, used as audience if provided. */
2729
private final String accountId;
30+
2831
/** OpenID Connect endpoints configuration. */
2932
private final OpenIDConnectEndpoints endpoints;
33+
3034
/** Custom audience value for token exchange. */
3135
private final String audience;
36+
3237
/** Source of ID tokens used in token exchange. */
3338
private final IDTokenSource idTokenSource;
39+
3440
/** HTTP client for making token exchange requests. */
3541
private final HttpClient httpClient;
42+
3643
/** Scopes to request during token exchange. */
3744
private final List<String> scopes;
3845

databricks-sdk-java/src/test/java/com/databricks/sdk/service/gentesting/unittests/LroTestingAPITest.java

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pom.xml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,13 @@
8383
<configuration>
8484
<java>
8585
<!-- <cleanthat/> This can be added after we drop java 8 support -->
86-
<googleJavaFormat/>
86+
<googleJavaFormat>
87+
<!-- 1.22.0 is the last GJF release that supports JRE 11 (1.23+ requires JRE 17).
88+
Needed to support newer JDKs (e.g. the code-generator's JDK 25) where the
89+
spotless-bundled default (1.15.0) fails with NoSuchMethodError against
90+
javac internals (Log$DeferredDiagnosticHandler.getDiagnostics). -->
91+
<version>1.22.0</version>
92+
</googleJavaFormat>
8793
<importOrder/>
8894
<removeUnusedImports/>
8995
<formatAnnotations/>

scripts/mvn-spotless-apply.sh

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#!/bin/bash
2+
3+
# Wrapper for `mvn spotless:apply` that exports the javac-internals flags required by
4+
# google-java-format on JDK 16+. Without these, GJF fails on JDK 17+ with either
5+
# IllegalAccessError or NoSuchMethodError when it reaches into com.sun.tools.javac.*.
6+
# On JDK <= 15 the flags are unrecognized and would break Maven startup, so we only
7+
# set them when detected JDK major version is >= 16.
8+
9+
set -euo pipefail
10+
11+
JDK_VERSION_OUTPUT=$(java -version 2>&1 | head -1)
12+
# Matches `"1.8.0_xxx"` (legacy) and `"17.0.1"` / `"25"` (modern) forms.
13+
JDK_MAJOR=$(echo "$JDK_VERSION_OUTPUT" | sed -E 's/.*version "([0-9]+)(\.[0-9]+)?.*/\1/')
14+
if [ "$JDK_MAJOR" = "1" ]; then
15+
JDK_MAJOR=$(echo "$JDK_VERSION_OUTPUT" | sed -E 's/.*version "1\.([0-9]+).*/\1/')
16+
fi
17+
18+
if [ "${JDK_MAJOR:-0}" -ge 16 ]; then
19+
export MAVEN_OPTS="${MAVEN_OPTS:-} \
20+
--add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED \
21+
--add-exports=jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED \
22+
--add-exports=jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED \
23+
--add-exports=jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED \
24+
--add-exports=jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED \
25+
--add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED"
26+
fi
27+
28+
exec mvn spotless:apply

0 commit comments

Comments
 (0)