{"record":{"id":"7f3efd05aeb9c660","repo":"apache/beam","slug":"text-payload-is-not-valid-utf-8","errorCode":null,"errorMessage":"Text payload is not valid UTF-8.","messagePattern":"Text payload is not valid UTF-8\\.","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"sdks/java/io/solace/src/main/java/org/apache/beam/sdk/io/solace/data/Solace.java","lineNumber":347,"sourceCode":"\n      public abstract Builder setReplicationGroupMessageId(\n          @Nullable String replicationGroupMessageId);\n\n      public abstract Builder setAttachmentBytes(byte[] attachmentBytes);\n\n      public abstract Record build();\n    }\n\n    private static String decodeUtf8(byte[] payload) {\n      try {\n        return StandardCharsets.UTF_8\n            .newDecoder()\n            .onMalformedInput(CodingErrorAction.REPORT)\n            .onUnmappableCharacter(CodingErrorAction.REPORT)\n            .decode(ByteBuffer.wrap(payload))\n            .toString();\n      } catch (CharacterCodingException e) {\n        throw new IllegalArgumentException(\"Text payload is not valid UTF-8.\", e);\n      }\n    }\n  }\n\n  /**\n   * The result of writing a message to Solace. This will be returned by the {@link\n   * org.apache.beam.sdk.io.solace.SolaceIO.Write} connector.\n   *\n   * <p>This class provides a builder to create instances, but you will probably not need it. The\n   * write connector will create and return instances of {@link Solace.PublishResult}.\n   *\n   * <p>If the message has been published, {@link Solace.PublishResult#getPublished()} will be true.\n   * If it is false, it means that the message could not be published, and {@link\n   * Solace.PublishResult#getError()} will contain more details about why the message could not be\n   * published.\n   */\n  @AutoValue\n  @DefaultSchema(AutoValueSchema.class)","sourceCodeStart":329,"sourceCodeEnd":365,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/io/solace/src/main/java/org/apache/beam/sdk/io/solace/data/Solace.java#L329-L365","documentation":"Solace.decodeUtf8 throws this IllegalArgumentException when the record's payload bytes cannot be decoded as UTF-8 (the UTF-8 decoder is configured with CodingErrorAction.REPORT). It guards getText(): a record claiming PayloadType.TEXT must contain valid UTF-8, otherwise the bytes are malformed or corrupted.","triggerScenarios":"Calling `getText()` on a TEXT-typed record whose payload bytes are not valid UTF-8 — e.g. a producer sent Latin-1/GBK encoded text, or binary data mislabeled as TEXT.","commonSituations":"Producers on non-JVM platforms using a legacy charset; messages serialized with a different default encoding; corrupted or truncated messages on the queue; mixed-language pipelines assuming UTF-8 everywhere.","solutions":["Fix the producing side to encode text as UTF-8 before sending to Solace.","If payloads are genuinely non-UTF-8, send them as BINARY payload type and decode with the correct charset on the consumer side.","On the consumer, catch IllegalArgumentException from getText() and fall back to raw getPayload() with the proper charset.","Validate sample queue payloads with a hex dump to confirm the actual encoding in use."],"exampleFix":"// before\nString text = record.getText(); // throws on non-UTF-8\n// after\nString text;\ntry {\n  text = record.getText();\n} catch (IllegalArgumentException e) {\n  text = new String(record.getPayload(), Charset.forName(\"ISO-8859-1\"));\n}","handlingStrategy":"try-catch","validationCode":"try { StandardCharsets.UTF_8.newDecoder().decode(ByteBuffer.wrap(record.getPayload())); } catch (CharacterCodingException e) { /* not UTF-8: handle as binary or alternate charset */ }","typeGuard":"boolean isUtf8(byte[] b) {\n  try { StandardCharsets.UTF_8.newDecoder().decode(ByteBuffer.wrap(b)); return true; }\n  catch (CharacterCodingException e) { return false; }\n}","tryCatchPattern":"try { text = record.getText(); } catch (IllegalArgumentException e) { text = new String(record.getPayload(), fallbackCharset); }","preventionTips":["Ensure producers encode text as UTF-8 before publishing","Publish non-UTF-8 data as BINARY payload type","Detect source charset when integrating non-JVM producers"],"tags":["solace","java","utf-8","encoding","charset"],"backgroundTag":"invalid-argument-format","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"}