apache/beam · error · IllegalStateException

Text is only available for records with payload type TEXT.

Error message

Text is only available for records with payload type TEXT.

What it means

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.

Solutions

  1. Check `record.getPayloadType()` before calling getText(), and use getPayload()/decode bytes for BINARY records.
  2. Fix the producing application to send text payloads if text access is expected.
  3. Add branching logic that handles both TEXT and BINARY payload types from heterogeneous producers.
  4. If text is desired from binary data, decode getPayload() as UTF-8 yourself with appropriate error handling.

Example fix

// before
String text = record.getText();
// after
String text = record.getPayloadType() == PayloadType.TEXT
    ? record.getText()
    : new String(record.getPayload(), StandardCharsets.UTF_8);
Defensive patterns

Strategy: type-guard

Validate before calling

if (record.getPayloadType() != PayloadType.TEXT) { /* handle as binary */ }

Type guard

boolean hasText(Solace.Record r) { return r.getPayloadType() == PayloadType.TEXT; }

Try / catch

try { return record.getText(); } catch (IllegalStateException e) { return new String(record.getPayload(), StandardCharsets.UTF_8); }

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Background: "Invalid state transition" errors: "status must be X, actually Y", "already rejected/charging/uninstalled", "cannot ... while running" — what they mean when a library rejects your call — this error's family across 31 libraries.

Related errors


AI-assisted analysis of apache/beam@12126d8942 (2026-09-13). Data as JSON: /api/errors/7ef471ab5966445b. Report an issue: GitHub.

Appendix: source

Thrown at sdks/java/io/solace/src/main/java/org/apache/beam/sdk/io/solace/data/Solace.java:282

     * Gets the attachment data of the message as a byte array, if any. This might represent files
     * or other binary content associated with the message.
     *
     * <p>Mapped from {@link BytesXMLMessage#getAttachmentByteBuffer()}
     *
     * @return The attachment data, or an empty byte array if no attachment is present.
     */
    @SuppressWarnings("mutable")
    @SchemaFieldNumber("12")
    public abstract byte[] getAttachmentBytes();

    /** Gets the JCSMP payload representation used for this record. */
    @SchemaFieldNumber("13")
    public abstract PayloadType getPayloadType();

    /** Gets the payload decoded as UTF-8 when this record has type {@link PayloadType#TEXT}. */
    public final String getText() {
      if (getPayloadType() != PayloadType.TEXT) {
        throw new IllegalStateException(
            "Text is only available for records with payload type TEXT.");
      }
      return decodeUtf8(getPayload());
    }

    public static Builder builder() {
      return new AutoValue_Solace_Record.Builder()
          .setExpiration(0L)
          .setPriority(-1)
          .setRedelivered(false)
          .setTimeToLive(0)
          .setAttachmentBytes(new byte[0])
          .setPayloadType(PayloadType.BYTES_XML);
    }

    @AutoValue.Builder
    public abstract static class Builder {
      public abstract Builder setMessageId(String messageId);

View on GitHub (pinned to 12126d8942)