pgjdbc/pgjdbc GitHub issues and pull requests (mirror)  
help / color / mirror / Atom feed
From: mblakley-casana (@mblakley-casana) <[email protected]>
To: pgjdbc/pgjdbc <[email protected]>
Subject: [pgjdbc/pgjdbc] PR #4069: Avoid direct java.lang.management dependency in maxResultBuffer parser
Date: Wed, 13 May 2026 21:03:28 +0000
Message-ID: <[email protected]> (raw)

Fixes #4068

### All Submissions:

* [x] Have you followed the guidelines in our [Contributing](https://github.com/pgjdbc/pgjdbc/blob/master/CONTRIBUTING.md) document?
* [x] Have you checked to ensure there aren't other open [Pull Requests](../../pulls) for the same update/change?

I checked for existing issues/PRs with `ManagementFactory`, `java.lang.management`, `Android`, and `PGPropertyMaxResultBufferParser` and did not find a matching open PR.

<!-- You can erase any parts of this template not applicable to your Pull Request. -->

### Changes to Existing Features:

* [x] Does this break existing behaviour? If so please explain.

No. On Java SE runtimes where `java.lang.management` is available, percentage values are still calculated from max heap and large explicit byte values are still capped to 90% of max heap.

On runtimes without `java.lang.management`, behavior changes only for the heap-introspection paths:

- unset `maxResultBuffer` remains disabled
- explicit byte values are accepted as provided
- percentage values fail with a `PSQLException` explaining that percentage values require `java.lang.management.ManagementFactory`

* [x] Have you added an explanation of what your changes do and why you'd like us to include them?

Android's ART runtime does not include the Java SE `java.lang.management` package. Because `PGPropertyMaxResultBufferParser` directly references `ManagementFactory`, Android can fail class resolution while loading the driver class graph, even when `maxResultBuffer` is unset and the percentage-based syntax is not used.

The management API is only needed to compute percentage values like `10pct` and to cap explicit byte sizes to 90% of max heap. This change removes the verifier-visible `java.lang.management.ManagementFactory` reference and resolves `ManagementFactory`, `MemoryMXBean`, and `MemoryUsage` reflectively only when max-heap introspection is needed.

* [x] Have you written new tests for your core changes, as applicable?

Yes. `PGPropertyMaxResultBufferParserRuntimeTest` covers a runtime where the management classes cannot be resolved:

- unset value parses as disabled
- explicit byte value parses
- percentage value throws `PSQLException`
- max heap lookup reports unavailable

* [x] Have you successfully run tests with your changes locally?

Yes:

```text
./gradlew :postgresql:styleCheck
./gradlew :postgresql:test --tests org.postgresql.test.util.PGPropertyMaxResultBufferParserTest --tests org.postgresql.util.PGPropertyMaxResultBufferParserRuntimeTest
./gradlew -PenableErrorprone -PenableCheckerframework :postgresql:classes
git diff --check
```

I also validated the patched driver on Android API 34:

- published the local patched driver as `org.postgresql:postgresql:42.7.12-SNAPSHOT`
- substituted it into an Android instrumentation test runtime
- loaded `org.postgresql.Driver`
- reached `org.postgresql.jdbc.PgConnection`
- executed a simple JDBC query successfully

The Android instrumentation result was `OK (1 test)`.

I attempted the targeted pgjdbc tests with `-PjdkTestVersion=8`, but this local machine does not have a Java 8 toolchain configured and Gradle toolchain download repositories are not configured, so that run could not start. CI should cover the supported JDK matrix.


view thread (3+ messages)  latest in thread

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: github://pgjdbc/pgjdbc
  Cc: [email protected], [email protected]
  Subject: Re: [pgjdbc/pgjdbc] PR #4069: Avoid direct java.lang.management dependency in maxResultBuffer parser
  In-Reply-To: <<[email protected]>>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox