From: vlsi (@vlsi) <noreply+vlsi@github.com>
To: pgjdbc/pgjdbc <noreply+pgjdbc-pgjdbc@github.com>
Subject: Re: [pgjdbc/pgjdbc] PR #4251: OAuth implementation
Date: Wed, 09 Sep 2026 15:45:36 +0000
Message-ID: <gh-pgjdbc-pgjdbc-4251-rc3970363230@github.com> (raw)
In-Reply-To: <gh-pgjdbc-pgjdbc-4251@github.com>
References: <gh-pgjdbc-pgjdbc-4251@github.com>
(on pgjdbc/src/main/java/org/postgresql/core/v3/ConnectionFactoryImpl.java)
The comment and the code disagree in two ways, and the branch it describes cannot run.
`isOAuthConfigured(info)` guarded this branch, so `resolveOAuthToken` either returns a non-empty token or throws; `null` is unreachable. The comment says the following code "already has support" for the discovery case, and it does not: with `null` the `if` on line 1109 skips `handleAuthenticationSASL`, so nothing is written to the socket, `setFinishedAuthenticationRequests()` is skipped, and the loop blocks on a message the server will never send because it is waiting for the client. The second comment then says "if token was empty", while the code tests `!= null`, and an empty array is rejected earlier by `OAuth token provider returned no token`.
The support for the discovery message does exist, in `buildTokenMessage`, which builds `n,,\x01auth=\x01\x01` for a null token exactly as libpq does. It is this caller that turns it off.
I would drop all three `!= null` tests and both comments, and let the type say what holds:
```java
char[] oauthToken = castNonNull(resolveOAuthToken(info));
try {
oauthAuthenticator.handleAuthenticationSASL(oauthToken);
} finally {
Arrays.fill(oauthToken, (char) 0);
}
// The server answers a valid token with AuthenticationOk, so no further request arrives.
pgStream.setFinishedAuthenticationRequests();
```