{"record":{"id":"039c9ef69ccd4ceb","repo":"apache/beam","slug":"get-request-for-s-returned-null","errorCode":null,"errorMessage":"GET request for %s returned null","messagePattern":"GET request for (.+?) returned null","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"sdks/java/io/google-cloud-platform/src/main/java/org/apache/beam/sdk/io/gcp/healthcare/FhirIO.java","lineNumber":631,"sourceCode":"                \"Error fetching Fhir resource with ID {} writing to Dead Letter Queue. \",\n                resourceId,\n                e);\n            context.output(FhirIO.Read.DEAD_LETTER, HealthcareIOError.of(resourceId, e));\n          }\n          if (resource != null) {\n            context.output(resource);\n          }\n        }\n\n        private String fetchResource(HealthcareApiClient client, String resourceName)\n            throws IOException, IllegalArgumentException {\n          long startTime = Instant.now().toEpochMilli();\n\n          HttpBody resource = client.readFhirResource(resourceName);\n          READ_RESOURCE_LATENCY_MS.update(Instant.now().toEpochMilli() - startTime);\n\n          if (resource == null) {\n            throw new IOException(String.format(\"GET request for %s returned null\", resourceName));\n          }\n          READ_RESOURCE_SUCCESS.inc();\n          return mapper.writeValueAsString(resource);\n        }\n      }\n    }\n  }\n\n  /** The type Write. */\n  @AutoValue\n  public abstract static class Write extends PTransform<PCollection<String>, Write.AbstractResult> {\n\n    /** The tag for successful writes to FHIR store. */\n    public static final TupleTag<String> SUCCESSFUL_BODY = new TupleTag<String>() {};\n\n    /** The tag for the failed writes to FHIR store. */\n    public static final TupleTag<HealthcareIOError<String>> FAILED_BODY =\n        new TupleTag<HealthcareIOError<String>>() {};","sourceCodeStart":613,"sourceCodeEnd":649,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/io/google-cloud-platform/src/main/java/org/apache/beam/sdk/io/gcp/healthcare/FhirIO.java#L613-L649","documentation":"FhirIoReader.fetchResource calls the Healthcare API client readFhirResource(resourceName) and, because the API can occasionally return a null body even on a successful HTTP call, it converts that null into an explicit IOException naming the resource. This makes the silent-null case observable so the DoFn fails the element and metrics/success counters are not incorrectly incremented.","triggerScenarios":"GET on a FHIR store resource where the Cloud Healthcare API returns null — the resource was deleted between listing and reading, the resourceName is malformed, or a transient API problem yielded an empty response body.","commonSituations":"Race between pipeline listing FHIR resources and their deletion (store re-import/replace); wrong FHIR store path or resource ID casing; intermittent Google API instability where the client swallows the error and returns null.","solutions":["Re-read the resource with a retry (the surrounding pipeline will retry IOExceptions if configured with a failed-inserts/dead-letter sink)","Verify the resourceName points to an existing resource in the correct fhirStore (print/log it and curl the REST endpoint)","Check for deletion races upstream and emit the resource name to a dead-letter output instead of hard-failing","Confirm Cloud Healthcare API quotas/health and regional endpoint correctness"],"exampleFix":"// before\nHttpBody resource = client.readFhirResource(resourceName);\nreturn mapper.writeValueAsString(resource); // NPE risk\n// after\nHttpBody resource = client.readFhirResource(resourceName);\nif (resource == null) {\n  throw new IOException(String.format(\"GET request for %s returned null\", resourceName));\n}\nreturn mapper.writeValueAsString(resource);","handlingStrategy":"retry","validationCode":"// pre-flight existence check via Healthcare REST API before batch reads\n// GET https://healthcare.googleapis.com/v1/{resourceName} and verify 200 + non-empty body","typeGuard":"boolean isUsableResource(HttpBody body) { return body != null && body.getData() != null; }","tryCatchPattern":"try {\n  String json = reader.fetchResource(resourceName);\n} catch (IOException e) {\n  if (e.getMessage().contains(\"returned null\")) {\n    // re-fetch with backoff or route resourceName to dead-letter output\n  } else throw e;\n}","preventionTips":["Emit failed resource names to a dead-letter PCollection instead of letting them fail the bundle silently","Check that resources are not being deleted concurrently with the pipeline","Monitor Cloud Healthcare API error rates/quotas"],"tags":["java","fhir","healthcare-api","null-response"],"backgroundTag":"empty-api-response","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}