hibernate/hibernate-orm · error · IllegalArgumentException
Unquoted count of quotes is invalid
Error message
Unquoted count of quotes is invalid
What it means
StringHelper.countUnquoted(string, character) counts occurrences of a character outside single-quoted regions, so counting the single-quote character itself is meaningless — every quote is both the delimiter and the candidate match. The method therefore rejects the quote character up front with IllegalArgumentException. This is an invariant guard, not a runtime condition you can hit with data.
Source
Thrown at hibernate-core/src/main/java/org/hibernate/internal/util/StringHelper.java:536
return 0;
}
text = text.trim();
if ( text.isEmpty() ) {
return 0;
}
int count = 0;
for ( int i = 0, max = text.length(); i < max; i++ ) {
final char check = text.charAt( i );
if ( check == match ) {
count++;
}
}
return count;
}
public static int countUnquoted(String string, char character) {
if ( '\'' == character ) {
throw new IllegalArgumentException( "Unquoted count of quotes is invalid" );
}
if ( string == null ) {
return 0;
}
// Impl note: takes advantage of the fact that an escaped single quote
// embedded within a quote-block can really be handled as two separate
// quote-blocks for the purposes of this method...
int count = 0;
final int stringLength = string.length();
boolean inQuote = false;
for ( int indx = 0; indx < stringLength; indx++ ) {
char c = string.charAt( indx );
if ( inQuote ) {
if ( '\'' == c ) {
inQuote = false;
}
}
else if ( '\'' == c ) {View on GitHub (pinned to fad1729dce)
Solutions
- If you need the total number of single quotes, use StringHelper.count(string, '\'') instead.
- If you need quotes outside quote-blocks, note that each quote flips in/out of a block — the concept is ill-defined, so rethink the parsing (e.g., a proper tokenizer).
- If iterating over characters, skip '\'' explicitly when delegating to countUnquoted.
Example fix
// before int n = StringHelper.countUnquoted(sql, '\''); // IllegalArgumentException // after int totalQuotes = StringHelper.count(sql, '\'');
Defensive patterns
Strategy: validation
Validate before calling
static int safeCountUnquoted(String text, char c) {
if (c == '\'') {
return StringHelper.count(text, '\''); // quote char not supported by countUnquoted
}
return StringHelper.countUnquoted(text, c);
} Prevention
- Read the helper's contract: the counted character must differ from the quote delimiter.
- When counting delimiters in SQL fragments, pick the counting function per character explicitly.
When it happens
Trigger: Calling StringHelper.countUnquoted(text, '\'') — the check fires immediately regardless of the string argument, before any scanning starts.
Common situations: Generic character-counting utilities that iterate over candidate characters including quotes; copy-paste use of the helper while inspecting SQL fragments for delimiters; code written against count() and adapted to countUnquoted() without dropping the quote case.
Related errors
- json_object must have an even number of arguments, but found
- Length must be great-than-or-equal to zero.
- Length must be great-than-or-equal to zero.
- Length must be greater than or equal to zero
- startTimeNanos [${startTimeNanos}] should be greater than 0
AI-assisted analysis of hibernate/hibernate-orm@fad1729dce (2026-08-22).
Data as JSON: /api/errors/0b3f3b6c7b7c5a1f.
Report an issue: GitHub.