File tree Expand file tree Collapse file tree 2 files changed +35
-8
lines changed
main/java/org/apache/fluss/client/utils
test/java/org/apache/fluss/client/utils Expand file tree Collapse file tree 2 files changed +35
-8
lines changed Original file line number Diff line number Diff line change @@ -483,10 +483,11 @@ public GenericRow toRow(T pojo) {
483483 try {
484484 value = fieldToRowConverters [i ].convert (pojo );
485485 } catch (IllegalAccessException e ) {
486- LOG .warn (
487- "Failed to access field {} in POJO class {}." ,
488- rowType .getFieldNames ().get (i ),
489- pojoClass .getName (),
486+ throw new IllegalStateException (
487+ String .format (
488+ "Failed to access field %s in POJO class %s." ,
489+ rowType .getFieldNames ().get (i ),
490+ pojoClass .getName ()),
490491 e );
491492 }
492493 row .setField (i , value );
@@ -517,10 +518,11 @@ public T fromRow(InternalRow row) {
517518 pojoFields [i ].set (pojo , value );
518519 }
519520 } catch (IllegalAccessException e ) {
520- LOG .warn (
521- "Failed to set field {} in POJO class {}." ,
522- rowType .getFieldNames ().get (i ),
523- pojoClass .getName (),
521+ throw new IllegalStateException (
522+ String .format (
523+ "Failed to set field %s in POJO class %s." ,
524+ rowType .getFieldNames ().get (i ),
525+ pojoClass .getName ()),
524526 e );
525527 }
526528 }
Original file line number Diff line number Diff line change @@ -224,6 +224,22 @@ public void testRowWithMissingFields() {
224224 assertThat (convertedPojo .offsetDateTimeField ).isNull ();
225225 }
226226
227+ @ Test
228+ public void testFieldAccessFailureThrows () {
229+ RowType rowType = RowType .builder ().field ("intField" , DataTypes .INT ()).build ();
230+
231+ ConverterUtils <FinalFieldPojo > converter =
232+ ConverterUtils .getConverter (FinalFieldPojo .class , rowType );
233+
234+ GenericRow row = new GenericRow (1 );
235+ row .setField (0 , 42 );
236+
237+ assertThatThrownBy (() -> converter .fromRow (row ))
238+ .isInstanceOf (IllegalStateException .class )
239+ .hasMessageContaining ("Failed to set field" )
240+ .hasMessageContaining ("intField" );
241+ }
242+
227243 @ Test
228244 public void testWriteAndReadPojos () throws Exception {
229245 TablePath tablePath = new TablePath ("test_db" , "pojo_table" );
@@ -466,4 +482,13 @@ private RowType createTestPojoRowType() {
466482 .field ("offsetDateTimeField" , DataTypes .TIMESTAMP_LTZ ())
467483 .build ();
468484 }
485+
486+ /** POJO with a final field to trigger IllegalAccessException on setting. */
487+ public static class FinalFieldPojo {
488+ private final int intField ;
489+
490+ public FinalFieldPojo () {
491+ this .intField = 0 ;
492+ }
493+ }
469494}
You can’t perform that action at this time.
0 commit comments