Skip to content

Commit

Permalink
Fix another issue with JDBC driver registration and test restart
Browse files Browse the repository at this point in the history
This fix is pretty terrible, but I don't see any other way around
the problem

Fixes: quarkusio#14829
  • Loading branch information
geoand committed Feb 5, 2021
1 parent 3be8fc6 commit 9a733bf
Showing 1 changed file with 18 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.quarkus.bootstrap.classloading;

import java.lang.reflect.Field;
import java.sql.Driver;
import java.sql.DriverManager;
import java.sql.SQLException;
Expand Down Expand Up @@ -29,5 +30,22 @@ public void run() {
log.error("Failed to deregister driver", t);
}
}

// this really sucks because it triggers an illegal access warning, but there is no other way
// to force the DriverManager to re-initialize drivers
try {
Field[] declaredFields = DriverManager.class.getDeclaredFields();
// go through the fields instead of accessing it immediately because in Java 8 this field does not exist
for (Field field : declaredFields) {
if (field.getName().equals("driversInitialized")) {
field.setAccessible(true);
field.set(null, false);
break;
}
}
} catch (IllegalAccessException t) {
log.debug("Failed to clear initialization state of drivers", t);
}

}
}

0 comments on commit 9a733bf

Please sign in to comment.