From bc81eb6d197698efc078e030f520089dd16ef972 Mon Sep 17 00:00:00 2001 From: Gavin Date: Sat, 10 Jun 2023 23:13:19 +0200 Subject: [PATCH] fix error reported for empty HQL string --- .../query/hql/internal/StandardHqlTranslator.java | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/hibernate-core/src/main/java/org/hibernate/query/hql/internal/StandardHqlTranslator.java b/hibernate-core/src/main/java/org/hibernate/query/hql/internal/StandardHqlTranslator.java index 88389b31c6..5a4d9a8fd3 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/hql/internal/StandardHqlTranslator.java +++ b/hibernate-core/src/main/java/org/hibernate/query/hql/internal/StandardHqlTranslator.java @@ -159,9 +159,14 @@ public class StandardHqlTranslator implements HqlTranslator { } if ( e instanceof NoViableAltException ) { errorText += message.substring( 0, message.indexOf("'") ); - String lineText = hql.lines().collect( toList() ).get( line -1 ); - String text = lineText.substring( 0, charPositionInLine) + "*" + lineText.substring(charPositionInLine); - errorText += "'" + text + "'"; + if ( hql.isEmpty() ) { + errorText += "'*' (empty query string)"; + } + else { + String lineText = hql.lines().collect( toList() ).get( line -1 ); + String text = lineText.substring( 0, charPositionInLine) + "*" + lineText.substring(charPositionInLine); + errorText += "'" + text + "'"; + } } else if ( e instanceof InputMismatchException ) { errorText += message.substring( 0, message.length()-1 )