{"record":{"id":"7310ba8f7a7ad2b9","repo":"apache/pulsar","slug":"not-implemented-7310ba","errorCode":null,"errorMessage":"not implemented","messagePattern":"not implemented","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"pulsar-functions/api-java/src/main/java/org/apache/pulsar/functions/api/BaseContext.java","lineNumber":205,"sourceCode":"    CompletableFuture<Long> getCounterAsync(String key);\n\n    /**\n     * Record a user defined metric.\n     * @param metricName The name of the metric\n     * @param value The value of the metric\n     */\n    void recordMetric(String metricName, double value);\n\n    /**\n     * Get the pre-configured pulsar client.\n     *\n     * You can use this client to access Pulsar cluster.\n     * The Function will be responsible for disposing this client.\n     *\n     * @return the instance of pulsar client\n     */\n    default PulsarClient getPulsarClient() {\n        throw new UnsupportedOperationException(\"not implemented\");\n    }\n\n    /**\n     * Get the pre-configured pulsar client builder.\n     *\n     * You can use this Builder to setup client to connect to the Pulsar cluster.\n     * But you need to close client properly after using it.\n     *\n     * @return the instance of pulsar client builder.\n     */\n    default ClientBuilder getPulsarClientBuilder() {\n        throw new UnsupportedOperationException(\"not implemented\");\n    }\n\n    /**\n     * Terminate the function instance with a fatal exception.\n     *\n     * @param t the fatal exception to be raised","sourceCodeStart":187,"sourceCodeEnd":223,"githubUrl":"https://github.com/apache/pulsar/blob/820761864ed8e2a7d2e52dd9763ad2ae117c1395/pulsar-functions/api-java/src/main/java/org/apache/pulsar/functions/api/BaseContext.java#L187-L223","documentation":"BaseContext.getPulsarClient() is a default method that throws UnsupportedOperationException('not implemented'). The base context does not have a PulsarClient; only concrete contexts that receive one (e.g. Java function instances) override this.","triggerScenarios":"Calling context.getPulsarClient() from code running with a Context implementation that has not been given a PulsarClient — e.g. a sink/source connector context or unit-test Context stub.","commonSituations":"Shared utility code used both in sinks and functions, mocks/stubs of Context in unit tests that don't override getPulsarClient, or older runtime versions where the client was not injected.","solutions":["Use getPulsarClientBuilder() to build your own client when the runtime doesn't supply one","Catch UnsupportedOperationException and create a PulsarClient manually from config","Run the code inside the Java function instance runtime where the client is injected","In tests, use a Context stub that overrides getPulsarClient (e.g. via Mockito spy or a test Context implementation)"],"exampleFix":"// before\nPulsarClient client = context.getPulsarClient(); // throws\n// after\ntry {\n    client = context.getPulsarClient();\n} catch (UnsupportedOperationException e) {\n    client = context.getPulsarClientBuilder().serviceUrl(url).build();\n}","handlingStrategy":"try-catch","validationCode":"// No pre-check; capability is discovered at call time.","typeGuard":null,"tryCatchPattern":"PulsarClient client;\ntry {\n    client = ctx.getPulsarClient();\n} catch (UnsupportedOperationException e) {\n    client = PulsarClient.builder().serviceUrl(serviceUrl).build();\n}","preventionTips":["Use getPulsarClient() only inside Java function runtimes that inject a client","In shared code, always have a fallback builder path","For unit tests, stub Context with an overriding getPulsarClient"],"tags":["java","pulsar-functions","pulsar-client","unsupported-operation"],"backgroundTag":"operation-not-supported","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"}