Skip to content

fix: reject null URL in Driver.acceptsURL with a clear NullPointerException - #4205

Merged
vlsi merged 1 commit into
pgjdbc:masterfrom
vlsi:fix/acceptsurl-null-check
Jun 22, 2026
Merged

vlsi merged 1 commit into
pgjdbc:masterfrom
vlsi:fix/acceptsurl-null-check

Conversation

@vlsi

@vlsi vlsi commented Jun 20, 2026

Copy link
Copy Markdown
Member

Why

A misconfigured J2EE container (e.g. Tomcat) can hand the driver a null URL. Driver.connect(null, ...) already rejects this with a clear SQLException("url is null"), but Driver.acceptsURL(null) still falls through to URL parsing and throws an opaque NullPointerException that looks like a driver bug.

This revives the intent of #1317. The original blocker there — Objects.requireNonNull not compiling under Java 1.6 — no longer applies: the driver requires Java 8+ and already uses Objects.requireNonNull throughout.

What

  • acceptsURL now calls Objects.requireNonNull(url, "url") before parsing, so a null URL fails fast with a clear message instead of an opaque NPE. This matches how connect treats a null URL as a caller error.
  • Adds DriverTest.acceptsUrlRejectsNull covering the null case.

How to verify

./gradlew :postgresql:test --tests "org.postgresql.test.jdbc2.DriverTest.acceptsUrlRejectsNull"

Co-authored-by: @yevster, whose original patch in #1317 proposed this check.

@vlsi vlsi mentioned this pull request Jun 20, 2026
2 tasks done
…eption

A misconfigured container can pass a null URL to the driver. In acceptsURL
this previously surfaced as an opaque NullPointerException from URL parsing
that looks like a driver bug. Fail fast with Objects.requireNonNull instead,
matching how connect(null) already rejects a null URL.

Co-authored-by: Yev <[email protected]>
Co-Authored-By: Claude Opus 4.8 <[email protected]>
@vlsi
vlsi force-pushed the fix/acceptsurl-null-check branch from de00b9f to f8d8c52 Compare June 22, 2026 14:28
@vlsi vlsi added the chore label Jun 22, 2026
@vlsi
vlsi merged commit d72f9a3 into pgjdbc:master Jun 22, 2026
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant