Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2105,9 +2105,10 @@ public static <T> void readSource(
// the same order.
BoundedSource.BoundedReader<T> reader = streamSource.createReader(options);

T current = null;
try {
if (reader.start()) {
outputReceiver.get(rowTag).output(reader.getCurrent());
current = reader.getCurrent();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

If reader.getCurrent() returns null, the current implementation will silently skip outputting the element without throwing an exception or routing it to error handling, whereas previously it would have thrown a NullPointerException inside the try block. To preserve the original behavior and avoid silent data loss, use java.util.Objects.requireNonNull to ensure a NullPointerException is thrown and caught if the reader returns null.

Suggested change
current = reader.getCurrent();
current = java.util.Objects.requireNonNull(reader.getCurrent(), "Reader returned null element");

} else {
return;
}
Expand All @@ -2120,11 +2121,15 @@ public static <T> void readSource(
(Exception) e.getCause(),
"Unable to parse record reading from BigQuery");
}
if (current != null) {
outputReceiver.get(rowTag).output(current);
}

while (true) {
current = null;
try {
if (reader.advance()) {
outputReceiver.get(rowTag).output(reader.getCurrent());
current = reader.getCurrent();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

Similar to the reader.start() block, if reader.getCurrent() returns null during advancement, it will be silently skipped. Use java.util.Objects.requireNonNull to ensure any null elements are caught and handled by the try-catch block.

Suggested change
current = reader.getCurrent();
current = java.util.Objects.requireNonNull(reader.getCurrent(), "Reader returned null element");

} else {
return;
}
Expand All @@ -2137,6 +2142,9 @@ public static <T> void readSource(
(Exception) e.getCause(),
"Unable to parse record reading from BigQuery");
}
if (current != null) {
outputReceiver.get(rowTag).output(current);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -602,8 +602,9 @@ public void instantiateHealthcareClient() throws IOException {
@ProcessElement
public void processElement(ProcessContext context) {
String resourceId = context.element();
String resource = null;
try {
context.output(fetchResource(this.client, resourceId));
resource = fetchResource(this.client, resourceId);
Comment thread
Aryankn29 marked this conversation as resolved.
Outdated
} catch (Exception e) {
READ_RESOURCE_ERRORS.inc();
LOG.warn(
Expand All @@ -612,6 +613,9 @@ public void processElement(ProcessContext context) {
e);
context.output(FhirIO.Read.DEAD_LETTER, HealthcareIOError.of(resourceId, e));
}
if (resource != null) {
context.output(resource);
}
}

private String fetchResource(HealthcareApiClient client, String resourceName)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -365,11 +365,15 @@ public void instantiateHealthcareClient() throws IOException {
@ProcessElement
public void processElement(ProcessContext context) {
String msgId = context.element();
HL7v2Message message = null;
try {
context.output(client.fetchMessage(msgId));
message = client.fetchMessage(msgId);
Comment thread
Aryankn29 marked this conversation as resolved.
Outdated
} catch (Exception e) {
context.output(HL7v2IO.Read.DEAD_LETTER, HealthcareIOError.of(msgId, e));
}
if (message != null) {
context.output(message);
}
}
}
}
Expand Down Expand Up @@ -487,15 +491,18 @@ public void instantiateHealthcareClient() throws IOException {
@ProcessElement
public void processElement(ProcessContext context) {
String msgId = context.element().getHl7v2MessageId();
HL7v2ReadResponse response = null;
try {
HL7v2ReadResponse response =
response =
HL7v2ReadResponse.of(context.element().getMetadata(), client.fetchMessage(msgId));
Comment thread
Aryankn29 marked this conversation as resolved.
Outdated
context.output(response);
} catch (Exception e) {
HealthcareIOError<HL7v2ReadParameter> error =
HealthcareIOError.of(context.element(), e);
context.output(HL7v2IO.HL7v2Read.DEAD_LETTER, error);
}
if (response != null) {
context.output(response);
}
}
}
}
Expand Down
Loading