gemini-code-assist[bot] commented on code in PR #39098:
URL: https://github.com/apache/beam/pull/39098#discussion_r3471537437
##########
sdks/java/core/src/test/java/org/apache/beam/sdk/transforms/JsonToRowTest.java:
##########
@@ -274,6 +274,31 @@ public void
testParsesErrorWithErrorMsgWithRequireNullDeadLetter() throws Except
pipeline.run();
}
+ @Test
+ @Category(NeedsRunner.class)
+ public void testDownstreamExceptionIsNotReportedAsParseError() {
+ PCollection<String> jsonPersons = pipeline.apply("jsonPersons",
Create.of(JSON_PERSON.get(0)));
+
+ ParseResult results =
jsonPersons.apply(JsonToRow.withExceptionReporting(PERSON_SCHEMA));
+
+ results
+ .getResults()
+ .apply(
+ "throwingDownstream",
+ ParDo.of(
+ new DoFn<Row, Row>() {
+ @ProcessElement
+ public void processElement(ProcessContext context) {
+ throw new RuntimeException("downstream failure");
+ }
+ }));
Review Comment:

Using an anonymous inner class for `DoFn` inside a test method captures the
enclosing `JsonToRowTest` instance. Since test classes are not `Serializable`,
this can cause `NotSerializableException` when running the pipeline with
runners that enforce serialization (such as the `DirectRunner` in some
configurations).
To avoid this, you can use `MapElements` with a lambda expression, which
does not capture the enclosing class instance unless it references its members.
```java
MapElements.into(org.apache.beam.sdk.values.TypeDescriptors.rows())
.via(
(Row row) -> {
throw new RuntimeException("downstream failure");
}));
```
--
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]