From 611b6c01795edb3d84b6cd0254c6e89bcc7ebd35 Mon Sep 17 00:00:00 2001 From: Gavin King Date: Fri, 10 Dec 2021 19:40:43 +0100 Subject: [PATCH] don't do things that can fail in static initializers because the failure gets swallowed by a nasty NCDFE and is impossible to track down --- .../testing/junit4/BaseUnitTestCase.java | 17 ++++++++++++++++- .../testing/orm/junit/DialectContext.java | 9 ++++++--- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/hibernate-testing/src/main/java/org/hibernate/testing/junit4/BaseUnitTestCase.java b/hibernate-testing/src/main/java/org/hibernate/testing/junit4/BaseUnitTestCase.java index 06a91e8b6f..e8ab6c4dfe 100644 --- a/hibernate-testing/src/main/java/org/hibernate/testing/junit4/BaseUnitTestCase.java +++ b/hibernate-testing/src/main/java/org/hibernate/testing/junit4/BaseUnitTestCase.java @@ -16,6 +16,7 @@ import jakarta.transaction.SystemException; import org.hibernate.engine.transaction.internal.jta.JtaStatusHelper; import org.hibernate.testing.AfterClassOnce; +import org.hibernate.testing.BeforeClassOnce; import org.hibernate.testing.cleaner.DatabaseCleaner; import org.hibernate.testing.jdbc.leak.ConnectionLeakUtil; import org.hibernate.testing.jta.TestingJtaPlatformImpl; @@ -35,8 +36,22 @@ import org.jboss.logging.Logger; @RunWith( CustomRunner.class ) public abstract class BaseUnitTestCase { + private static Throwable schemaClearError; + static { - DatabaseCleaner.clearSchemas(); + try { + DatabaseCleaner.clearSchemas(); + } + catch (Throwable t) { + schemaClearError = t; + } + } + + @BeforeClassOnce + public static void checkClearSchema() throws Throwable { + if (schemaClearError!=null) { + throw schemaClearError; + } } protected final Logger log = Logger.getLogger( getClass() ); diff --git a/hibernate-testing/src/main/java/org/hibernate/testing/orm/junit/DialectContext.java b/hibernate-testing/src/main/java/org/hibernate/testing/orm/junit/DialectContext.java index 8f90d8b9e8..997550274c 100644 --- a/hibernate-testing/src/main/java/org/hibernate/testing/orm/junit/DialectContext.java +++ b/hibernate-testing/src/main/java/org/hibernate/testing/orm/junit/DialectContext.java @@ -23,9 +23,9 @@ import org.hibernate.internal.util.ReflectHelper; */ public final class DialectContext { - private static final Dialect dialect; + private static Dialect dialect; - static { + static void init() { final Properties properties = Environment.getProperties(); final String dialectName = properties.getProperty( Environment.DIALECT ); if ( dialectName == null ) { @@ -53,7 +53,10 @@ public final class DialectContext { private DialectContext() { } - public static Dialect getDialect() { + public static synchronized Dialect getDialect() { + if (dialect==null) { + init(); + } return dialect; } }