From 669d23319dc59a355fd5632348241d8c2ec1843a Mon Sep 17 00:00:00 2001 From: Christian Beikov Date: Tue, 15 Mar 2022 13:30:30 +0100 Subject: [PATCH] Show an issue with BasicFormatterImpl --- .../engine/jdbc/spi/SqlStatementLogger.java | 13 +++++++++---- .../orm/test/jdbc/util/BasicFormatterTest.java | 8 ++++++++ 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/hibernate-core/src/main/java/org/hibernate/engine/jdbc/spi/SqlStatementLogger.java b/hibernate-core/src/main/java/org/hibernate/engine/jdbc/spi/SqlStatementLogger.java index 3e7de1f179..ae8f66f876 100644 --- a/hibernate-core/src/main/java/org/hibernate/engine/jdbc/spi/SqlStatementLogger.java +++ b/hibernate-core/src/main/java/org/hibernate/engine/jdbc/spi/SqlStatementLogger.java @@ -112,11 +112,16 @@ public class SqlStatementLogger { @AllowSysOut public void logStatement(String statement, Formatter formatter) { if ( logToStdout || LOG.isDebugEnabled() ) { - if ( format ) { - statement = formatter.format( statement ); + try { + if ( format ) { + statement = formatter.format( statement ); + } + if ( highlight ) { + statement = FormatStyle.HIGHLIGHT.getFormatter().format( statement ); + } } - if ( highlight ) { - statement = FormatStyle.HIGHLIGHT.getFormatter().format( statement ); + catch (RuntimeException ex) { + LOG.warn( "Couldn't format statement", ex ); } } LOG.debug( statement ); diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/jdbc/util/BasicFormatterTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/jdbc/util/BasicFormatterTest.java index ab473c68c5..86d31ce18d 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/jdbc/util/BasicFormatterTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/jdbc/util/BasicFormatterTest.java @@ -11,6 +11,8 @@ import java.util.StringTokenizer; import org.junit.Test; import org.hibernate.engine.jdbc.internal.FormatStyle; + +import org.hibernate.testing.FailureExpected; import org.hibernate.testing.junit4.BaseUnitTestCase; import static org.junit.Assert.assertEquals; @@ -50,6 +52,12 @@ public class BasicFormatterTest extends BaseUnitTestCase { assertNoLoss( "select group0.[order] as order0 from [Group] group0 where group0.[order]=?1" ); } + @Test + @FailureExpected( jiraKey = "HHH-15125") + public void testProblematic() { + assertNoLoss( "select * from ((select e.id from Entity e union all select e.id from Entity e) union select e.id from Entity e) grp" ); + } + private void assertNoLoss(String query) { String formattedQuery = FormatStyle.BASIC.getFormatter().format( query ); StringTokenizer formatted = new StringTokenizer( formattedQuery, " \t\n\r\f()" );