Subject: [pgjdbc/pgjdbc] PR #3762: Fix: BaseDataSource.getProperty mirrors BaseDataSource.setProperty.

From: "simon-greatrix (@simon-greatrix)" <[email-masked]>
Date: Wed, 13 Aug 2025 23:00:02 +0000

The setProperty method of BaseDataSource allows all properties to be set. The getProperty method does not allow the retrieval of: PG_HOST, PG_PORT, PG_DBNAME, USER, and PASSWORD. All properties that can be set should also be readable.

Fixes: https://github.com/pgjdbc/pgjdbc/issues/3761

---

From: "simon-greatrix (@simon-greatrix)" <[email-masked]>
Date: Mon, 18 Aug 2025 11:27:12 +0000

In writing a unit test I have discovered a related issue:

PGSimpleDataSource dataSource = new PGSimpleDataSource();
dataSource.setLoadBalanceHosts(false);
assertFalse( dataSource.getLoadBalanceHosts() );
The getLoadBalanceHosts() method returns true if any value is set, even if the value is false.

Should we create a new issue for this or expand the scope of this one to cover it?

---

From: "davecramer (@davecramer)" <[email-masked]>
Date: Mon, 18 Aug 2025 11:31:04 +0000

Just fix it here

---

From: "simon-greatrix (@simon-greatrix)" <[email-masked]>
Date: Mon, 18 Aug 2025 14:45:12 +0000

I've been pondering how `setService(String)` interacts with `getUrl()` and `setUrl(String)`. 

After setting a service the URL looks like this:

`jdbc:postgresql://localhost/?service=test-service1`

If you call `setUrl` with this value it sets all the properties values from the service including defaults. Something like this:

`jdbc:postgresql://localhost:5432/test_dbname?adaptiveFetch=false&...&useSpnego=false&xmlFactoryFactory=`

Everything is set *except* for `service`.

Is the correct and expected behaviour:

1) Just like this - this is perfect

2) Calling `setService(String)` should set all the property values for the service, so the first URL should have them all set.

3) Calling getUrl() should never include a "service=" element as it is non-portable.

4) Calling setUrl() should preserve the service property.

Personally, I would like `setService` to load the service defaults, and the non-portable "service=" value in the URL to be removed.

PS: I've pushed the unit tests and additional fix. The unit tests include this case and hence currently fail as I'm not sure what the correct behaviour is.

---

From: "simon-greatrix (@simon-greatrix)" <[email-masked]>
Date: Mon, 18 Aug 2025 16:31:30 +0000

By the way, I've noticed that with Java 21.0.7 the `TimestampTest` is failing. This is due to a Java quirk. The test is initialising a value as `1950-02-07 15:00:00 PST` and parsing it with SimpleDateFormat.

Whilst we expect PST to match Pacific Standard Time, it also matches Philippine Standard Time. I do not know what determines which matches 'PST' first. My locale is Europe/London which might affect things, but I would still expect PST to be Pacific Standard Time rather than Philippine Standard Time.

Would you mind if I fixed this too? All I want to do is to change the "PST" to "Pacific Standard Time" in the test case :)

---

From: "davecramer (@davecramer)" <[email-masked]>
Date: Mon, 18 Aug 2025 18:58:39 +0000

> Would you mind if I fixed this too? All I want to do is to change the "PST" to "Pacific Standard Time" in the test case :)

Can you do this in another PR. It will be small and we can just merge it quickly

---

From: "davecramer (@davecramer)" <[email-masked]>
Date: Mon, 18 Aug 2025 19:07:26 +0000

> Everything is set _except_ for `service`.
> 
> 1. Just like this - this is perfect
> 2. Calling `setService(String)` should set all the property values for the service, so the first URL should have them all set.
> 3. Calling getUrl() should never include a "service=" element as it is non-portable.
> 4. Calling setUrl() should preserve the service property.
> 

I guess there is no reason not to load the settings when setService is called. If however someone calls setUrl with a different service we should honour the settings for that service.

---

From: "simon-greatrix (@simon-greatrix)" <[email-masked]>
Date: Tue, 19 Aug 2025 14:30:10 +0000

Accidentally closed as I messed up my git repo. I should never have been merging from main! 

Re-opened using a fix branch on https://github.com/pgjdbc/pgjdbc/pull/3776