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
This commit is contained in:
Gavin King 2021-12-10 19:40:43 +01:00
parent e13cf2e0d1
commit 611b6c0179
2 changed files with 22 additions and 4 deletions

View File

@ -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,9 +36,23 @@ import org.jboss.logging.Logger;
@RunWith( CustomRunner.class )
public abstract class BaseUnitTestCase {
private static Throwable schemaClearError;
static {
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() );

View File

@ -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;
}
}