Skip to content

Commit 2924fe8

Browse files
committed
treat an empty string as a null character in CharacterJavaType conversion
an empty string should not be converted to a space char Signed-off-by: Gavin King <[email protected]>
1 parent 26988dd commit 2924fe8

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

hibernate-core/src/main/java/org/hibernate/type/descriptor/java/CharacterJavaType.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,13 @@ public <X> Character wrap(X value, WrapperOptions options) {
6767
if (value instanceof Character character) {
6868
return character;
6969
}
70-
if ( value instanceof String ) {
71-
if ( value.equals( "" ) ) {
72-
return ' ';
73-
}
74-
final String str = (String) value;
75-
return str.charAt( 0 );
70+
if (value instanceof String string) {
71+
// Note that this conversion is "dangerous",
72+
// since it is not invertible, and can in
73+
// principle result in accidental loss of data.
74+
// It might be better to throw if the incoming
75+
// string does not have length one.
76+
return string.isEmpty() ? null : string.charAt( 0 );
7677
}
7778
if (value instanceof Number number) {
7879
return (char) number.shortValue();

0 commit comments

Comments
 (0)