@@ -184,13 +184,10 @@ private static RowToField createRowReader(DataType fieldType, PojoType.Property
184184 private static Object convertTextValue (
185185 DataType fieldType , PojoType .Property prop , BinaryString s ) {
186186 String v = s .toString ();
187- String formattedMessage =
188- String .format (
189- "Field %s expects exactly one character for CHAR type, got length %d." ,
190- prop .name , v .length ());
191187 if (prop .type == String .class ) {
192188 if (fieldType .getTypeRoot () == DataTypeRoot .CHAR && v .length () != 1 ) {
193- throw new IllegalArgumentException (formattedMessage );
189+ throw new IllegalArgumentException (
190+ charLengthExceptionMessage (prop .name , v .length ()));
194191 }
195192 return v ;
196193 } else if (prop .type == Character .class ) {
@@ -201,7 +198,8 @@ private static Object convertTextValue(
201198 prop .name ));
202199 }
203200 if (fieldType .getTypeRoot () == DataTypeRoot .CHAR && v .length () != 1 ) {
204- throw new IllegalArgumentException (formattedMessage );
201+ throw new IllegalArgumentException (
202+ charLengthExceptionMessage (prop .name , v .length ()));
205203 }
206204 return v .charAt (0 );
207205 }
@@ -211,6 +209,12 @@ private static Object convertTextValue(
211209 prop .name ));
212210 }
213211
212+ public static String charLengthExceptionMessage (String fieldName , int length ) {
213+ return String .format (
214+ "Field %s expects exactly one character for CHAR type, got length %d." ,
215+ fieldName , length );
216+ }
217+
214218 /**
215219 * Converts a DECIMAL value from an InternalRow into a BigDecimal using the column's precision
216220 * and scale. The row position is assumed non-null (caller checks), so this never returns null.
0 commit comments