{"record":{"id":"2c0c4507655e4a15","repo":"apache/pulsar","slug":"window-function-does-not-implement-the-correct-int","errorCode":null,"errorMessage":"Window function does not implement the correct interface","messagePattern":"Window function does not implement the correct interface","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"pulsar-functions/instance/src/main/java/org/apache/pulsar/functions/windowing/WindowFunctionExecutor.java","lineNumber":86,"sourceCode":"    @SuppressWarnings(\"unchecked\")\n    private void initializeUserFunction(WindowConfig windowConfig) {\n        String actualWindowFunctionClassName = windowConfig.getActualWindowFunctionClassName();\n        ClassLoader clsLoader = Thread.currentThread().getContextClassLoader();\n        Object userClassObject = Reflections.createInstance(\n                actualWindowFunctionClassName,\n                clsLoader);\n        if (userClassObject instanceof java.util.function.Function) {\n            Class<?>[] typeArgs = TypeResolver.resolveRawArguments(\n                    java.util.function.Function.class, userClassObject.getClass());\n            if (typeArgs[0].equals(Collection.class)) {\n                bareWindowFunction = (java.util.function.Function<Collection<T>, X>) userClassObject;\n            } else {\n                throw new IllegalArgumentException(\"Window function must take a collection as input\");\n            }\n        } else if (userClassObject instanceof WindowFunction) {\n            windowFunction = (WindowFunction<T, X>) userClassObject;\n        } else {\n            throw new IllegalArgumentException(\"Window function does not implement the correct interface\");\n        }\n    }\n\n    private WindowConfig getWindowConfigs(Context context) {\n\n        if (!context.getUserConfigValue(WindowConfig.WINDOW_CONFIG_KEY).isPresent()) {\n            throw new IllegalArgumentException(\"Window Configs cannot be found\");\n        }\n        WindowConfig windowConfig = new Gson().fromJson(\n                (new Gson().toJson(context.getUserConfigValue(WindowConfig.WINDOW_CONFIG_KEY).get())),\n                WindowConfig.class);\n\n        return windowConfig;\n    }\n\n    private WindowManager<Record<T>> getWindowManager(WindowConfig windowConfig, Context context) {\n\n        WindowLifecycleListener<Event<Record<T>>> lifecycleListener = newWindowLifecycleListener(context);","sourceCodeStart":68,"sourceCodeEnd":104,"githubUrl":"https://github.com/apache/pulsar/blob/820761864ed8e2a7d2e52dd9763ad2ae117c1395/pulsar-functions/instance/src/main/java/org/apache/pulsar/functions/windowing/WindowFunctionExecutor.java#L68-L104","documentation":"initializeUserFunction validates that the user-supplied function object implements one of the supported interfaces: java.util.function.Function (with Collection input) or the Pulsar WindowFunction interface. If the provided object implements neither, this IllegalArgumentException is thrown at instance initialization. It signals user code is incompatible with the windowing executor.","triggerScenarios":"The class configured as the function implements some other functional interface (e.g. custom interface, Consumer, BiFunction) or a raw Object; instanceof checks against both supported interfaces fail during initialize.","commonSituations":"Passing a transformer/processor class from a non-windowing pipeline into a windowed function config; refactoring renamed the base interface; loading a stale jar compiled against a different WindowFunction package.","solutions":["Implement org.apache.pulsar.functions.api.windowing.WindowFunction<T,X> in the user class","Or implement java.util.function.Function<Collection<T>, X> with Collection as the input type","Verify the jar deployed to the function actually contains the updated class (rebuild and redeploy)","Check imports: use the windowing WindowFunction, not a same-named class from another library"],"exampleFix":"// before\nclass MyFunc implements java.util.function.Consumer<String> { ... }\n// after\nclass MyFunc implements WindowFunction<String, Void> {\n    public Void process(Collection<String> input, Window window) { ...; return null; }\n}","handlingStrategy":"type-guard","validationCode":"boolean ok = WindowFunction.class.isAssignableFrom(fnClass)\n    || java.util.function.Function.class.isAssignableFrom(fnClass);\nif (!ok) throw new IllegalArgumentException(\"class must implement WindowFunction or Function<Collection<T>,X>\");","typeGuard":"static boolean isWindowFunctionClass(Class<?> c) {\n    return WindowFunction.class.isAssignableFrom(c)\n        || java.util.function.Function.class.isAssignableFrom(c);\n}","tryCatchPattern":"try {\n    executor.initialize();\n} catch (IllegalArgumentException e) {\n    throw new IllegalStateException(\"function class incompatible with windowing executor: \" + e.getMessage(), e);\n}","preventionTips":["Verify imports resolve to org.apache.pulsar.functions.api.windowing.WindowFunction","Rebuild the jar after refactoring base interfaces","Smoke-test the function deployment in a dev cluster"],"tags":["pulsar-functions","windowing","interface-contract"],"backgroundTag":"wrong-function-interface","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"}