Copilot commented on code in PR #4152:
URL: https://github.com/apache/gobblin/pull/4152#discussion_r2481745972
##########
gobblin-utility/src/main/java/org/apache/gobblin/util/AvroUtils.java:
##########
@@ -340,8 +343,22 @@ private static void getFieldHelper(Map<String, Object>
retVal,
return;
}
- AvroUtils.getFieldHelper(retVal, ((GenericRecord)
data).get(pathList.get(field)), pathList, ++field);
- return;
+ if (data instanceof GenericRecord) {
+ Object next = getSafeField((GenericRecord) data, pathList.get(field));
+ getFieldHelper(retVal, next, pathList, field + 1);
+ }
+ }
+
+ private static Object getSafeField(GenericRecord record, String fieldName) {
+ if (record == null || fieldName == null) return null;
+ Schema.Field schemaField = record.getSchema().getField(fieldName);
+ if (schemaField == null) return null;
+ try {
+ return record.get(fieldName);
+ } catch (Exception e) {
Review Comment:
The catch block swallows all exceptions silently. This can hide legitimate
errors such as `AvroRuntimeException` or other unexpected failures. Consider
either catching only specific expected exceptions, or at minimum logging the
exception before returning null to aid in debugging unexpected issues.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]