ClassCastException when usePrepareStatement=true for LoadData

Hi we want migrate some creation of binary bytea data from setup phase in integration tests to Liquibase db initialization.
During this I tried enable on LoadDataChange usePrepareStatement=true. Before this all for us worked without errors.

After enablement I got:

Exception java.lang.ClassCastException("class org.postgresql.jdbc.PgPreparedStatement cannot be cast to class org.postgresql.jdbc.PgPreparedStatement 

(org.postgresql.jdbc.PgPreparedStatement is in unnamed module of loader java.net.URLClassLoader @62b0a58b; 
 org.postgresql.jdbc.PgPreparedStatement is in unnamed module of loader java.net.URLClassLoader @2ee4c028)") 
 breakpoint hit in jdk.internal.reflect.GeneratedMethodAccessor162 at line ? by thread main.

Use case is run test that compare “released” and “snapshot” database schema state.

Environment:
Maven 3.9.2, JDK 17.0.7, Liquibase 4.25.0

Dependency to pgJDBC 42.6.0 is only managed (in parent pom) dependency in maven on project level only =>

  <dependencies>
    <dependency>
      <groupId>org.postgresql</groupId>
      <artifactId>postgresql</artifactId>
      <scope>test</scope>
    </dependency>

Liquibase maven plugin contains several executions:

  1. dropUser-install_released
  2. createUser-install_released
  3. install-install_released
  4. update-install_snapshot
  5. dropUser-install_snapshot
  6. createUser-install_snapshot
  7. install-install_snapshot

Problem happens in last (7) execution. When I debug it, first call in step 3 or 4 It seems that during each execution is own URLClassloader that loads own pgJDBC but later in ExecutablePreparedStatement#executePreparedStatement it lead to this classpath issues.

Probably this static field is shared across executions?

    //Cache the executeWithFlags method to avoid reflection overhead
    private static Method executeWithFlagsMethod;

Is it expected or some known/new bug?

Full stacktrace is here: liquibaseClassCastException.txt

It seems that I’m on right way. I removed static from field declaration and after recompile Liquibase and use 0-SNAPSHOT version all works fine.