Skip to content

refactor(jdbc): split URL parsing into named steps - #229

Merged
magnusp merged 1 commit into
mainfrom
refactor/i213-url-parser-steps
Oct 24, 2026
Merged

magnusp merged 1 commit into
mainfrom
refactor/i213-url-parser-steps

Conversation

@magnusp

@magnusp magnusp commented Oct 24, 2026

Copy link
Copy Markdown
Owner

Fixes #213

What

LibsqlUrlParser.parse was a 98-line method doing prefix stripping, URI
construction, credential resolution, TLS override, encoding validation,
timeout resolution, and endpoint rebuilding. The precedence rules were
invisible.

It is now a 16-line orchestrator (12 statements) over six named steps:

Step Concern
normalizeUri strip jdbc:libsql: / jdbc:sqlite:, default the scheme, build the URI
resolveAuthToken query authToken → query jwt → Properties.authToken → Properties.password
resolveScheme tls / ssl upgrade only, http→https, ws→wss
resolveEncoding alias/case handling for json / protobuf / proto, ws-only check
resolveDuration query beats Properties beats default, for both timeouts
buildEndpoint scheme + host, port only when positive, null path as empty

LibsqlDriver.connect is untouched. The optional client-construction seam
there is eight lines of codec selection, not the clean three-line seam the
issue asked for.

Behavior preserved

No precedence rule, message, or exception type changed. In particular:

  • query parameters beat Properties; jwt aliases authToken; password is last resort
  • tls/ssl only upgrade, and the upgrade still runs before the encoding check, so ws + TLS + protobuf stays legal
  • unknown encodings still throw SQLException with the same message
  • a null path is empty, and the port is kept only when positive
  • the socketTimeout guard from socketTimeout alone in a JDBC URL throws NumberFormatException #196 is unchanged (query connectTimeout only)

Tests and pom.xml are untouched.

Probe (run, failed, reverted)

Reordered the steps so the TLS upgrade ran after the encoding check and the
endpoint was rebuilt from the pre-upgrade scheme:

[ERROR] Tests run: 13, Failures: 1, Errors: 0, Skipped: 0
[ERROR] LibsqlUrlParserTest.testTlsUpgradesWebSocketToSecureWebSocket
expected: "wss://localhost:8080"
 but was: "ws://localhost:8080"

Command: ./mvnw -pl libsql-jdbc -am -Dtest=LibsqlUrlParserTest -Dsurefire.failIfNoSpecifiedTests=false test. File restored, re-run green.

Line counts

  • parse: 98 lines on main → 16 lines (signature + 12 statements + brace)
  • LibsqlUrlParser.java: 142 → 146 lines, 63 insertions / 59 deletions

Lanes

  • unit — ./mvnw test — BUILD SUCCESS; libsql-jdbc 398 tests, libsql-hrana-codec 35, 0 failures, 0 errors.
  • spotless — ./mvnw spotless:check — BUILD SUCCESS.
  • conformance — ./mvnw -pl libsql-conformance -am verify — BUILD SUCCESS; 272 tests, 0 failures, 0 errors, 7 skipped (pinned sqld image).

Fixes #213

`LibsqlUrlParser.parse` was a 98-line method that stripped the prefix,
built the URI, resolved credentials, overrode TLS, validated the encoding,
resolved timeouts, and rebuilt the endpoint. The precedence rules were
invisible.

Extract `normalizeUri`, `resolveAuthToken`, `resolveScheme`,
`resolveEncoding`, `resolveDuration`, and `buildEndpoint`, leaving `parse`
as a 16-line orchestrator. No behavior change: query parameters still beat
`Properties`, `jwt` is still an alias for `authToken`, `password` is still
the last resort, `tls`/`ssl` only upgrade and still run before the encoding
check, unknown encodings still throw `SQLException`, and a null path is
still empty with the port kept only when positive.

`LibsqlDriver.connect` is untouched; the client-construction seam there is
eight lines of codec selection, not the clean three-line seam the issue
asked for.
@magnusp
magnusp merged commit 0651efb into main Oct 24, 2026
6 checks passed
@magnusp
magnusp deleted the refactor/i213-url-parser-steps branch October 24, 2026 17:54
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.

Split LibsqlUrlParser.parse into named steps

1 participant