{"record":{"id":"7d0577137c8263c7","repo":"apache/pulsar","slug":"context-does-not-provide-subscriptiontype","errorCode":null,"errorMessage":"Context does not provide SubscriptionType","messagePattern":"Context does not provide SubscriptionType","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"warning","filePath":"pulsar-io/core/src/main/java/org/apache/pulsar/io/core/SinkContext.java","lineNumber":63,"sourceCode":"     *\n     * @return a list of all input topics\n     */\n    Collection<String> getInputTopics();\n\n    /**\n     * Get sink config at startup.\n     *\n     * @return sink config\n     */\n    SinkConfig getSinkConfig();\n\n    /**\n     * Get subscription type used by the source providing data for the sink.\n     *\n     * @return subscription type\n     */\n    default SubscriptionType getSubscriptionType() {\n        throw new UnsupportedOperationException(\"Context does not provide SubscriptionType\");\n    }\n\n    /**\n     * Reset the subscription associated with this topic and partition to a specific message id.\n     *\n     * @param topic - topic name\n     * @param partition - partition id (0 for non-partitioned topics)\n     * @param messageId to reset to\n     * @throws PulsarClientException\n     */\n    default void seek(String topic, int partition, MessageId messageId) throws PulsarClientException {\n        throw new UnsupportedOperationException(\"not implemented\");\n    }\n\n    /**\n     * Stop requesting new messages for given topic and partition until {@link #resume(String topic, int partition)}\n     * is called.\n     *","sourceCodeStart":45,"sourceCodeEnd":81,"githubUrl":"https://github.com/apache/pulsar/blob/820761864ed8e2a7d2e52dd9763ad2ae117c1395/pulsar-io/core/src/main/java/org/apache/pulsar/io/core/SinkContext.java#L45-L81","documentation":"SinkContext.getSubscriptionType() is a default interface method that throws UnsupportedOperationException because the base SinkContext contract does not expose the subscription type of the consuming subscription. It is thrown only when the concrete runtime context (e.g. the functions instance) does not override it. A sink calling this method on such a context cannot learn the SubscriptionType.","triggerScenarios":"Calling sinkContext.getSubscriptionType() inside a Pulsar IO sink when the runtime implementation of SinkContext has not implemented this method (older broker/worker version or a test/mock context).","commonSituations":"Connector code using the newer SinkContext API against an older Pulsar runtime; unit tests using a stub SinkContext that doesn't override getSubscriptionType (e.g. testGetSubscriptionType failures); embedding the sink outside a real functions runtime.","solutions":["Upgrade the Pulsar runtime/worker to a version whose SinkContext implementation provides getSubscriptionType.","In connector code, catch UnsupportedOperationException and fall back to a configured or default subscription type.","In tests, use a stub that overrides getSubscriptionType with the expected value."],"exampleFix":"// before\nSubscriptionType type = ctx.getSubscriptionType();\n// after\nSubscriptionType type;\ntry {\n    type = ctx.getSubscriptionType();\n} catch (UnsupportedOperationException e) {\n    type = SubscriptionType.Shared; // configurable fallback\n}","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n    SubscriptionType t = ctx.getSubscriptionType();\n} catch (UnsupportedOperationException e) {\n    SubscriptionType t = SubscriptionType.Shared; // documented fallback\n}","preventionTips":["Pin connector runtime compatibility with the broker/worker Pulsar version","Never assume SinkContext optional methods exist; code defensively","Test connectors against a real functions runtime, not only stubs"],"tags":["pulsar-io","unsupported-operation","api-compatibility","sink-context"],"backgroundTag":"method-not-implemented","analyzedSha":"820761864ed8e2a7d2e52dd9763ad2ae117c1395","analyzedAt":"2026-09-06T00:14:20.138Z","contentChangedAt":"2026-09-06T00:14:20.138Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}