From 6169a60ecdf19e75f6b145449c8d0abb606439b1 Mon Sep 17 00:00:00 2001 From: Sanne Grinovero Date: Wed, 16 Mar 2022 20:57:16 +0000 Subject: [PATCH] Always guard for Log level before producing log message parameters --- .../ast/spi/SimpleFromClauseAccessImpl.java | 22 ++++++++++++------- .../sql/ast/tree/expression/SqlTuple.java | 13 ++++++----- 2 files changed, 22 insertions(+), 13 deletions(-) diff --git a/hibernate-core/src/main/java/org/hibernate/sql/ast/spi/SimpleFromClauseAccessImpl.java b/hibernate-core/src/main/java/org/hibernate/sql/ast/spi/SimpleFromClauseAccessImpl.java index 641726528d..e372f60142 100644 --- a/hibernate-core/src/main/java/org/hibernate/sql/ast/spi/SimpleFromClauseAccessImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/sql/ast/spi/SimpleFromClauseAccessImpl.java @@ -13,6 +13,8 @@ import org.hibernate.query.spi.NavigablePath; import org.hibernate.sql.ast.SqlTreeCreationLogger; import org.hibernate.sql.ast.tree.from.TableGroup; +import org.jboss.logging.Logger; + /** * Simple implementation of FromClauseAccess * @@ -47,15 +49,19 @@ public class SimpleFromClauseAccessImpl implements FromClauseAccess { @Override public void registerTableGroup(NavigablePath navigablePath, TableGroup tableGroup) { - SqlTreeCreationLogger.LOGGER.debugf( - "Registration of TableGroup [%s] with identifierForTableGroup [%s] for NavigablePath [%s] ", - tableGroup, - tableGroup.getNavigablePath().getIdentifierForTableGroup(), - navigablePath.getIdentifierForTableGroup() - ); + final Logger logger = SqlTreeCreationLogger.LOGGER; + final boolean debugEnabled = logger.isDebugEnabled(); + if ( debugEnabled ) { + logger.debugf( + "Registration of TableGroup [%s] with identifierForTableGroup [%s] for NavigablePath [%s] ", + tableGroup, + tableGroup.getNavigablePath().getIdentifierForTableGroup(), + navigablePath.getIdentifierForTableGroup() + ); + } final TableGroup previous = tableGroupMap.put( navigablePath, tableGroup ); - if ( previous != null ) { - SqlTreeCreationLogger.LOGGER.debugf( + if ( debugEnabled && previous != null ) { + logger.debugf( "Registration of TableGroup [%s] for NavigablePath [%s] overrode previous registration : %s", tableGroup, navigablePath, diff --git a/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/expression/SqlTuple.java b/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/expression/SqlTuple.java index e50f08dd7c..d98bfed001 100644 --- a/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/expression/SqlTuple.java +++ b/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/expression/SqlTuple.java @@ -32,11 +32,14 @@ public class SqlTuple implements Expression, SqlTupleContainer, DomainResultProd this.expressions = expressions; this.valueMapping = valueMapping; - if ( expressions.size() < 2 ) { - SqlTreeCreationLogger.LOGGER.debugf( - "SqlTuple created with `%s` expression(s)", - expressions.size() - ); + if ( SqlTreeCreationLogger.LOGGER.isDebugEnabled() ) { + final int size = expressions.size(); + if ( size < 2 ) { + SqlTreeCreationLogger.LOGGER.debugf( + "SqlTuple created with `%s` expression(s)", + size + ); + } } }