Skip to content

Fix selectSparkVersion() crash on non-SemVer runtime keys#832

Merged
Divyansh-db merged 1 commit into
mainfrom
fix-select-spark-version-non-semver-key
Jun 15, 2026
Merged

Fix selectSparkVersion() crash on non-SemVer runtime keys#832
Divyansh-db merged 1 commit into
mainfrom
fix-select-spark-version-non-semver-key

Conversation

@Divyansh-db

@Divyansh-db Divyansh-db commented Jun 15, 2026

Copy link
Copy Markdown
Contributor

Summary

WorkspaceClient.clusters().selectSparkVersion(...) throws IllegalArgumentException: Not a valid SemVer: ... when the Spark versions API returns a runtime key that is not a valid SemVer. This makes the sort that picks the latest runtime resilient to such keys, mirroring the behavior of the Go SDK.

Why

selectSparkVersion(latest) gathers the matching runtime keys and sorts them to pick the newest:

versions.sort((v1, v2) -> SemVer.parse(v2).compareTo(SemVer.parse(v1)));

SemVer.parse throws IllegalArgumentException on any string it cannot parse, and because that happens inside the sort comparator, a single unparseable key aborts the entire selection. The clusters API recently started returning the key v18.x-scala2.13 — two version segments (18.x) plus a leading v — which the SemVer regex (it expects major.minor.patch) rejects. As a result, every caller of selectSparkVersion(latest) in such a workspace fails, and the ClustersIT.latestRuntime integration test started failing across all clouds.

The Go SDK does not have this problem: its comparator uses golang.org/x/mod/semver.Compare, which is total and never throws — invalid versions simply sort lowest and are effectively ignored when picking "latest". This PR brings the Java behavior in line, which also keeps the two SDKs consistent and makes selection robust to any future malformed key, not just this specific shape.

What changed

Interface changes

  • SemVer.parseOrNull(String) — parses a version string, returning null instead of throwing when the input is not a valid SemVer.

Behavioral changes

  • selectSparkVersion(latest) no longer throws when the API returns a non-SemVer runtime key. Unparseable keys are ranked lowest and the latest parseable runtime is returned, matching the Go SDK. (Previously every such call threw IllegalArgumentException.)

Internal changes

  • The version sort in ClustersExt.selectSparkVersion now uses a null-safe comparator (compareSparkVersionsDescending) built on SemVer.parseOrNull.

How is this tested?

Unit tests (run via mvn):

  • SemVerTestparseOrNull returns null for the v18.x-scala2.13 shape, malformed input, null, and empty string, and still parses valid versions.
  • ClustersExtTest — new regression test feeds a versions list containing v18.x-scala2.13 and asserts selectSparkVersion(latest) does not throw and returns the latest parseable runtime (15.4.x-scala2.12). This test fails on the pre-fix code.

NO_CHANGELOG=true

selectSparkVersion(latest) sorts candidate runtime keys with SemVer.parse(),
which throws IllegalArgumentException on any key that is not a valid SemVer.
The clusters API started returning "v18.x-scala2.13" (two version segments and
a leading "v"), which broke version selection for every caller and turned the
nightly ClustersIT.latestRuntime red across all clouds.

Make the sort non-throwing and rank unparseable keys lowest, mirroring
databricks-sdk-go (golang.org/x/mod/semver.Compare), which ignores such keys
for "latest" rather than failing. Add SemVer.parseOrNull() and regression tests.
@github-actions

Copy link
Copy Markdown
Contributor

If integration tests don't run automatically, an authorized user can run them manually by following the instructions below:

Trigger:
go/deco-tests-run/sdk-java

Inputs:

  • PR number: 832
  • Commit SHA: 1493ad1b8887d63a19cbfbda10c794195b0cb338

Checks will be approved automatically on success.

@Divyansh-db Divyansh-db requested a review from rauchy June 15, 2026 12:37
@Divyansh-db Divyansh-db added this pull request to the merge queue Jun 15, 2026
Merged via the queue into main with commit eeb87de Jun 15, 2026
17 of 18 checks passed
@Divyansh-db Divyansh-db deleted the fix-select-spark-version-non-semver-key branch June 15, 2026 14:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants