apache/beam · error · JmsIOException

An error occurred

Error message

An error occurred

What it means

JmsIO's write transform catches NullPointerExceptions arising from user-supplied getValueMapper or getTopicNameMapper functions and rethrows them as a JmsIOException with the message "An error occurred" plus the original NPE as cause. This surfaces mapper NPEs (e.g. getValueMapper returning null) as a distinct IO error rather than letting the NPE propagate raw.

Solutions

  1. Inspect the chained cause NPE stack trace to find which mapper (value or topic name) returned null.
  2. Make getValueMapper/getTopicNameMapper null-safe or filter null inputs before the write transform.
  3. Add a pre-write validation step (e.g. MapElements with a check) that rejects/defaults null values with a clear error.

Example fix

// before
.valueMapper(row -> row.getString("payload"))
// after
.valueMapper(row -> {
  String p = row.getString("payload");
  if (p == null) throw new IllegalArgumentException("payload is null for row: " + row);
  return p;
})
Defensive patterns

Strategy: try-catch

Validate before calling

// pre-validate mappers on sample inputs
Objects.requireNonNull(valueMapper.apply(sampleInput), "valueMapper returned null");
Objects.requireNonNull(topicNameMapper.apply(sampleInput), "topicNameMapper returned null");

Try / catch

try { pc.apply(JmsIO.write()...); } catch (JmsIOException e) {
  if (e.getCause() instanceof NullPointerException) {
    // inspect NPE stack trace; a mapper returned null
  }
}

Prevention

When it happens

Trigger: Calling JmsIO.write() where getValueMapper().apply(input) returns null (e.g. reading a null field from a Row) or getTopicNameMapper().apply(input) returns null or the value mapper NPEs while producing the message.

Common situations: Schema fields that are nullable being mapped without null checks; records missing the mapped key; topic name mapper returning null for out-of-scope inputs.

Related errors


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

Appendix: source

Thrown at sdks/java/io/jms/src/main/java/org/apache/beam/sdk/io/jms/JmsIO.java:1415

          } else if (spec.getTopic() != null) {
            this.destination = session.createTopic(spec.getTopic());
          }
        }
      }

      @SuppressFBWarnings("DCN_NULLPOINTER_EXCEPTION") // TODO(#35312)
      void publishMessage(T input) throws JMSException, JmsIOException {
        Destination destinationToSendTo = destination;
        try {
          Message message = spec.getValueMapper().apply(input, session);
          if (spec.getTopicNameMapper() != null) {
            destinationToSendTo = session.createTopic(spec.getTopicNameMapper().apply(input));
          }
          producer.send(destinationToSendTo, message);
        } catch (JMSException | JmsIOException | NullPointerException exception) {
          // Handle NPE in case of getValueMapper or getTopicNameMapper returns NPE
          if (exception instanceof NullPointerException) {
            throw new JmsIOException("An error occurred", exception);
          }
          throw exception;
        }
      }

      void startProducer() throws JMSException {
        this.producer = this.session.createProducer(null);
      }

      void closeProducer() throws JMSException {
        if (producer != null) {
          producer.close();
          producer = null;
        }
      }

      void close() {
        try {

View on GitHub (pinned to 12126d8942)