oscerd opened a new issue, #1799:
URL: https://github.com/apache/camel-kafka-connector/issues/1799
## Description
`connectors/camel-file-kafka-connector/src/main/java/org/apache/camel/kafkaconnector/file/transformers/FileTransforms.java`
still carries an Eclipse-generated catch stub and several robustness gaps:
```java
public R apply(R r) {
Object value = r.value();
if (r.value() instanceof GenericFile) {
GenericFile<File> message = (GenericFile<File>)r.value();
String c = null;
try {
c = FileUtils.readFileToString(message.getFile(),
StandardCharsets.UTF_8);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return r.newRecord(r.topic(), r.kafkaPartition(), null, r.key(),
SchemaHelper.buildSchemaBuilderForType(c), c, r.timestamp());
} else {
LOG.debug("Unexpected message type: {}", r.value().getClass());
return r;
}
}
```
1. The `IOException` is swallowed: it is printed with `e.printStackTrace()`
(bypassing the module's
logger) and then execution continues.
2. After a failed read, `c` is still `null`, so the transform emits a record
with a `null` value and
a schema derived from `null` — a read failure is silently converted into
a bad record instead of
failing the task.
3. The `else` branch dereferences `r.value()` after the local `value`
variable has already been read,
and throws `NullPointerException` when the record value is `null`.
4. The local `value` variable is assigned and never used.
5. `FileUtils.readFileToString` materialises the whole file as a single
`String`.
## Expected Behavior
A file that cannot be read fails the transform with a meaningful
`ConnectException`/`DataException`
(so Kafka Connect's error handling and DLQ apply), a `null` record value is
handled without an NPE,
and failures are reported through the class logger.
## Actual Behavior
A read failure is logged only to stderr via `printStackTrace()` and produces
a record with a `null`
value; a `null` record value throws `NullPointerException`.
## Additional Context
Related cleanup: #1786 removed the open TODO/XXX comments in the `core`
module; this one lives in a
connector module and was not covered.
--
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]