{"record":{"id":"9e5300eddf624f50","repo":"apache/pulsar","slug":"functionid-not-set","errorCode":null,"errorMessage":"FunctionID not set","messagePattern":"FunctionID not set","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"pulsar-functions/utils/src/main/java/org/apache/pulsar/functions/utils/functioncache/FunctionCacheManagerImpl.java","lineNumber":52,"sourceCode":"\n    /** Registered Functions. **/\n    private final Map<String, FunctionCacheEntry> cacheFunctions;\n\n    private ClassLoader rootClassLoader;\n\n    public FunctionCacheManagerImpl(ClassLoader rootClassLoader) {\n        this.cacheFunctions = new ConcurrentHashMap<>();\n        this.rootClassLoader = rootClassLoader;\n    }\n\n    Map<String, FunctionCacheEntry> getCacheFunctions() {\n        return cacheFunctions;\n    }\n\n    @Override\n    public ClassLoader getClassLoader(String fid) {\n        if (fid == null) {\n            throw new IllegalArgumentException(\"FunctionID not set\");\n        }\n\n        synchronized (cacheFunctions) {\n            FunctionCacheEntry entry = cacheFunctions.get(fid);\n            if (entry == null) {\n                throw new IllegalStateException(\"No dependencies are registered for function \" + fid);\n            }\n            return entry.getClassLoader();\n        }\n    }\n\n    @Override\n    public void registerFunctionInstance(String fid,\n                                         String eid,\n                                         List<String> requiredJarFiles,\n                                         List<URL> requiredClasspaths)\n            throws IOException {\n        if (fid == null) {","sourceCodeStart":34,"sourceCodeEnd":70,"githubUrl":"https://github.com/apache/pulsar/blob/820761864ed8e2a7d2e52dd9763ad2ae117c1395/pulsar-functions/utils/src/main/java/org/apache/pulsar/functions/utils/functioncache/FunctionCacheManagerImpl.java#L34-L70","documentation":"FunctionCacheManagerImpl.getClassLoader(fid) resolves a function's cached classloader by function ID. This IllegalArgumentException is thrown when fid is null, because a null function ID can never map to a cache entry and indicates a caller bug (missing function metadata) rather than a cache miss.","triggerScenarios":"Calling getClassLoader(null) — typically because the function's FunctionMetaData/FunctionID was not populated before the instance requested its classloader, e.g. in JavaInstanceRunnable or the function instance runtime setup.","commonSituations":"Constructing a function instance with incomplete FunctionMetaData; custom code embedding the function runtime and forgetting to set the function ID; deserialization of function details that dropped the ID field.","solutions":["Ensure the function's FunctionMetaData is fully populated (non-null function ID) before initializing the instance runtime.","Guard the call site: only call getClassLoader with a non-null fid obtained from getFunctionCacheEntry.","Fix the code path that constructs the function details so the ID is never dropped."],"exampleFix":"// before\nClassLoader cl = cacheManager.getClassLoader(functionDetails.getFunctionId()); // may be null\n// after\nString fid = functionDetails.getFunctionId();\nObjects.requireNonNull(fid, \"FunctionID not set\");\nClassLoader cl = cacheManager.getClassLoader(fid);","handlingStrategy":"validation","validationCode":"if (fid == null || fid.isEmpty()) {\n    throw new IllegalArgumentException(\"Cannot get classloader: function ID missing from function metadata\");\n}","typeGuard":null,"tryCatchPattern":"try {\n    ClassLoader cl = cacheManager.getClassLoader(fid);\n} catch (IllegalArgumentException e) {\n    // function metadata incomplete — fail instance init with actionable message\n    throw new IllegalStateException(\"Function ID was not set on FunctionMetaData; cannot load classloader\", e);\n}","preventionTips":["Assert functionDetails/function metadata is fully populated before constructing the instance runtime.","Use Objects.requireNonNull on the function ID at the call site to fail with clear context.","Validate serialized function configs include the ID field in tests."],"tags":["pulsar-functions","function-cache","null-argument"],"backgroundTag":"missing-required-argument","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"}