{"record":{"id":"aed812577480243b","repo":"apache/beam","slug":"an-error-occurred","errorCode":null,"errorMessage":"An error occurred","messagePattern":"An error occurred","errorType":"exception","errorClass":"JmsIOException","httpStatus":null,"severity":"error","filePath":"sdks/java/io/jms/src/main/java/org/apache/beam/sdk/io/jms/JmsIO.java","lineNumber":1415,"sourceCode":"          } else if (spec.getTopic() != null) {\n            this.destination = session.createTopic(spec.getTopic());\n          }\n        }\n      }\n\n      @SuppressFBWarnings(\"DCN_NULLPOINTER_EXCEPTION\") // TODO(#35312)\n      void publishMessage(T input) throws JMSException, JmsIOException {\n        Destination destinationToSendTo = destination;\n        try {\n          Message message = spec.getValueMapper().apply(input, session);\n          if (spec.getTopicNameMapper() != null) {\n            destinationToSendTo = session.createTopic(spec.getTopicNameMapper().apply(input));\n          }\n          producer.send(destinationToSendTo, message);\n        } catch (JMSException | JmsIOException | NullPointerException exception) {\n          // Handle NPE in case of getValueMapper or getTopicNameMapper returns NPE\n          if (exception instanceof NullPointerException) {\n            throw new JmsIOException(\"An error occurred\", exception);\n          }\n          throw exception;\n        }\n      }\n\n      void startProducer() throws JMSException {\n        this.producer = this.session.createProducer(null);\n      }\n\n      void closeProducer() throws JMSException {\n        if (producer != null) {\n          producer.close();\n          producer = null;\n        }\n      }\n\n      void close() {\n        try {","sourceCodeStart":1397,"sourceCodeEnd":1433,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/io/jms/src/main/java/org/apache/beam/sdk/io/jms/JmsIO.java#L1397-L1433","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Inspect the chained cause NPE stack trace to find which mapper (value or topic name) returned null.","Make getValueMapper/getTopicNameMapper null-safe or filter null inputs before the write transform.","Add a pre-write validation step (e.g. MapElements with a check) that rejects/defaults null values with a clear error."],"exampleFix":"// before\n.valueMapper(row -> row.getString(\"payload\"))\n// after\n.valueMapper(row -> {\n  String p = row.getString(\"payload\");\n  if (p == null) throw new IllegalArgumentException(\"payload is null for row: \" + row);\n  return p;\n})","handlingStrategy":"try-catch","validationCode":"// pre-validate mappers on sample inputs\nObjects.requireNonNull(valueMapper.apply(sampleInput), \"valueMapper returned null\");\nObjects.requireNonNull(topicNameMapper.apply(sampleInput), \"topicNameMapper returned null\");","typeGuard":null,"tryCatchPattern":"try { pc.apply(JmsIO.write()...); } catch (JmsIOException e) {\n  if (e.getCause() instanceof NullPointerException) {\n    // inspect NPE stack trace; a mapper returned null\n  }\n}","preventionTips":["Null-check optional schema fields inside getValueMapper.","Make getTopicNameMapper return a default topic instead of null.","Filter out records with null mapped values before the write stage."],"tags":["jms","null","mapper"],"backgroundTag":"null-argument","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"}