{"record":{"id":"5f134be102546424","repo":"apache/beam","slug":"latest-message-in-has-null-or-empty-sendtime-defaulting-to","errorCode":null,"errorMessage":"Latest message in {} has null or empty sendTime defaulting to now.","messagePattern":"Latest message in (.+?) has null or empty sendTime defaulting to now\\.","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"sdks/java/io/google-cloud-platform/src/main/java/org/apache/beam/sdk/io/gcp/healthcare/HttpHealthcareApiClient.java","lineNumber":349,"sourceCode":"            .hl7V2Stores()\n            .messages()\n            .list(hl7v2Store)\n            .setFilter(filter)\n            .set(\"view\", \"full\") // needed to retrieve the value for sendTime\n            .setOrderBy(\"sendTime desc\")\n            // https://cloud.google.com/apis/design/design_patterns#sorting_order\n            .setPageSize(1) // Only interested in the earliest sendTime\n            .execute();\n    if (response.isEmpty()) {\n      throw new IllegalArgumentException(\n          String.format(\n              \"Could not find latest send time. The filter %s  matched no results on \"\n                  + \"HL7v2 Store: %s\",\n              filter, hl7v2Store));\n    }\n    String sendTime = response.getHl7V2Messages().get(0).getSendTime();\n    if (Strings.isNullOrEmpty(sendTime)) {\n      LOG.warn(\"Latest message in {} has null or empty sendTime defaulting to now.\", hl7v2Store);\n\n      return Instant.now();\n    }\n    // sendTime is conveniently RFC3339 UTC \"Zulu\"\n    // https://cloud.google.com/healthcare/docs/reference/rest/v1/projects.locations.datasets.hl7V2Stores.messages#Message\n    return Instant.parse(sendTime);\n  }\n\n  @Override\n  public ListMessagesResponse makeSendTimeBoundHL7v2ListRequest(\n      String hl7v2Store,\n      Instant start,\n      @Nullable Instant end,\n      @Nullable String otherFilter,\n      @Nullable String orderBy,\n      @Nullable String pageToken)\n      throws IOException {\n    String filter;","sourceCodeStart":331,"sourceCodeEnd":367,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/io/google-cloud-platform/src/main/java/org/apache/beam/sdk/io/gcp/healthcare/HttpHealthcareApiClient.java#L331-L367","documentation":"In getLatestHL7v2SendTime, the newest HL7v2 message returned by the Healthcare API for the given filter has a null or empty sendTime field. The method logs a warning and falls back to using the current instant instead of the message's actual send time. This is not fatal; downstream polling logic will use 'now' as the latest send time.","triggerScenarios":"Calling getLatestHL7v2SendTime(hl7v2Store, filter) where the HL7v2 store contains a message whose sendTime metadata is missing or empty (e.g. the message was ingested without a sendTime, or the API returned a Message resource without the field populated).","commonSituations":"Healthcare HL7v2 ingest pipelines where messages arrive via legacy senders that do not populate MSH-7 (message timestamp); messages imported via bulk import APIs without send time; querying stores with such messages in a WriteToPubSub / HL7v2 polling pipeline.","solutions":["Fix the upstream HL7v2 message ingestion so sendTime (MSH-7) is always populated.","Accept the fallback: verify your pipeline tolerates Instant.now() as the latest send time (may re-read or skip messages).","Adjust the query filter to only match messages with a non-empty sendTime so the null-time message is not selected.","Log/alert on this warning to identify which stores/senders produce time-less messages and re-ingest them."],"exampleFix":"// before: relying on possibly-empty sendTime\nString sendTime = response.getHl7V2Messages().get(0).getSendTime();\n// after: ensure messages are ingested with sendTime set (MSH-7), or guard client-side\nInstant latest = Strings.isNullOrEmpty(sendTime)\n    ? Instant.now()\n    : Instant.parse(sendTime);","handlingStrategy":"fallback","validationCode":"// before invoking, ensure messages carry sendTime by querying the store:\n// HL7V2Store filter: \"sendTime != \"\" — or validate MSH-7 presence at ingest time.\nif (messages.isEmpty() || Strings.isNullOrEmpty(messages.get(0).getSendTime())) {\n  // expect now() fallback; plan windowing accordingly\n}","typeGuard":"boolean hasSendTime(Hl7V2Message m) { return m != null && !Strings.isNullOrEmpty(m.getSendTime()); }","tryCatchPattern":"// Not thrown, only warned; add a log alert on 'defaulting to now' to detect affected stores.\n// Downstream: treat Instant.now() result as 'unknown' and widen poll windows.","preventionTips":["Require MSH-7 (message datetime) in HL7v2 senders feeding the store.","Filter queries on sendTime != \"\" so null-time messages never win 'latest'.","Monitor logs for 'defaulting to now' per store and re-ingest offenders."],"tags":["java","healthcare","hl7v2","missing-timestamp","fallback"],"backgroundTag":"empty-required-field","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-20T03:17:13.778Z"}