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:
- dropUser-install_released
- createUser-install_released
- install-install_released
- update-install_snapshot
- dropUser-install_snapshot
- createUser-install_snapshot
- 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