{"record":{"id":"7ef471ab5966445b","repo":"apache/beam","slug":"text-is-only-available-for-records-with-payload-type-text","errorCode":null,"errorMessage":"Text is only available for records with payload type TEXT.","messagePattern":"Text is only available for records with payload type TEXT\\.","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"sdks/java/io/solace/src/main/java/org/apache/beam/sdk/io/solace/data/Solace.java","lineNumber":282,"sourceCode":"     * Gets the attachment data of the message as a byte array, if any. This might represent files\n     * or other binary content associated with the message.\n     *\n     * <p>Mapped from {@link BytesXMLMessage#getAttachmentByteBuffer()}\n     *\n     * @return The attachment data, or an empty byte array if no attachment is present.\n     */\n    @SuppressWarnings(\"mutable\")\n    @SchemaFieldNumber(\"12\")\n    public abstract byte[] getAttachmentBytes();\n\n    /** Gets the JCSMP payload representation used for this record. */\n    @SchemaFieldNumber(\"13\")\n    public abstract PayloadType getPayloadType();\n\n    /** Gets the payload decoded as UTF-8 when this record has type {@link PayloadType#TEXT}. */\n    public final String getText() {\n      if (getPayloadType() != PayloadType.TEXT) {\n        throw new IllegalStateException(\n            \"Text is only available for records with payload type TEXT.\");\n      }\n      return decodeUtf8(getPayload());\n    }\n\n    public static Builder builder() {\n      return new AutoValue_Solace_Record.Builder()\n          .setExpiration(0L)\n          .setPriority(-1)\n          .setRedelivered(false)\n          .setTimeToLive(0)\n          .setAttachmentBytes(new byte[0])\n          .setPayloadType(PayloadType.BYTES_XML);\n    }\n\n    @AutoValue.Builder\n    public abstract static class Builder {\n      public abstract Builder setMessageId(String messageId);","sourceCodeStart":264,"sourceCodeEnd":300,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/io/solace/src/main/java/org/apache/beam/sdk/io/solace/data/Solace.java#L264-L300","documentation":"Solace.Record.getText() throws this IllegalStateException when the record's payload type is not PayloadType.TEXT. The `text` field is only meaningful for records whose payload was published as text; calling it on a BINARY (or other) record would misinterpret raw bytes, so the record schema enforces the type check.","triggerScenarios":"Calling `record.getText()` on a Solace.Record whose `getPayloadType()` returns BINARY — typically records read from a queue written by producers sending BytesMessage/binary payloads instead of TextMessage.","commonSituations":"Reading a queue fed by multiple producers with mixed payload types; assuming all messages on a queue are text; migrating code that previously decoded bytes without checking the payload-type field.","solutions":["Check `record.getPayloadType()` before calling getText(), and use getPayload()/decode bytes for BINARY records.","Fix the producing application to send text payloads if text access is expected.","Add branching logic that handles both TEXT and BINARY payload types from heterogeneous producers.","If text is desired from binary data, decode getPayload() as UTF-8 yourself with appropriate error handling."],"exampleFix":"// before\nString text = record.getText();\n// after\nString text = record.getPayloadType() == PayloadType.TEXT\n    ? record.getText()\n    : new String(record.getPayload(), StandardCharsets.UTF_8);","handlingStrategy":"type-guard","validationCode":"if (record.getPayloadType() != PayloadType.TEXT) { /* handle as binary */ }","typeGuard":"boolean hasText(Solace.Record r) { return r.getPayloadType() == PayloadType.TEXT; }","tryCatchPattern":"try { return record.getText(); } catch (IllegalStateException e) { return new String(record.getPayload(), StandardCharsets.UTF_8); }","preventionTips":["Always branch on getPayloadType() before accessing getText()","Handle mixed TEXT/BINARY queues from heterogeneous producers","Prefer getPayload() + explicit decoding for unknown producer types"],"tags":["solace","java","payload-type","state","record"],"backgroundTag":"invalid-state-transition","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"}