From 65f94fdf840675e927ddd4ce81447abfe92bd006 Mon Sep 17 00:00:00 2001 From: mposolda Date: Mon, 11 Apr 2016 10:05:32 +0200 Subject: [PATCH] KEYCLOAK-2795 Testsuite fails sometimes with NPE in LockServiceFactory.getLockService --- .../conn/DefaultLiquibaseConnectionProvider.java | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/model/jpa/src/main/java/org/keycloak/connections/jpa/updater/liquibase/conn/DefaultLiquibaseConnectionProvider.java b/model/jpa/src/main/java/org/keycloak/connections/jpa/updater/liquibase/conn/DefaultLiquibaseConnectionProvider.java index ff3747b2a0..b9018f8991 100644 --- a/model/jpa/src/main/java/org/keycloak/connections/jpa/updater/liquibase/conn/DefaultLiquibaseConnectionProvider.java +++ b/model/jpa/src/main/java/org/keycloak/connections/jpa/updater/liquibase/conn/DefaultLiquibaseConnectionProvider.java @@ -69,6 +69,7 @@ public class DefaultLiquibaseConnectionProvider implements LiquibaseConnectionPr protected void baseLiquibaseInitialization() { ServiceLocator sl = ServiceLocator.getInstance(); + sl.setResourceAccessor(new ClassLoaderResourceAccessor(getClass().getClassLoader())); if (!System.getProperties().containsKey("liquibase.scan.packages")) { if (sl.getPackages().remove("liquibase.core")) { @@ -85,6 +86,10 @@ public class DefaultLiquibaseConnectionProvider implements LiquibaseConnectionPr sl.getPackages().remove("liquibase.ext"); sl.getPackages().remove("liquibase.sdk"); + + String lockPackageName = DummyLockService.class.getPackage().getName(); + logger.debugf("Added package %s to liquibase", lockPackageName); + sl.addPackageToScan(lockPackageName); } LogFactory.setInstance(new LogWrapper()); @@ -129,10 +134,6 @@ public class DefaultLiquibaseConnectionProvider implements LiquibaseConnectionPr String changelog = (database instanceof DB2Database) ? LiquibaseJpaUpdaterProvider.DB2_CHANGELOG : LiquibaseJpaUpdaterProvider.CHANGELOG; logger.debugf("Using changelog file: %s", changelog); - // We wrap liquibase update in CustomLockService provided by DBLockProvider. No need to lock inside liquibase itself. - // NOTE: This can't be done in baseLiquibaseInitialization() as liquibase always restarts lock service - LockServiceFactory.getInstance().register(new DummyLockService()); - return new Liquibase(changelog, new ClassLoaderResourceAccessor(getClass().getClassLoader()), database); }