{"record":{"id":"709badec40019d66","repo":"apache/cassandra","slug":"function-s-exists-but-hasn-t-been-loaded-succes","errorCode":null,"errorMessage":"Function '%s' exists but hasn't been loaded successfully for the following reason: %s. Please see the server log for details","messagePattern":"Function '(.+?)' exists but hasn't been loaded successfully for the following reason: (.+?)\\. Please see the server log for details","errorType":"exception","errorClass":"InvalidRequestException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/cql3/functions/UDFunction.java","lineNumber":300,"sourceCode":"                                                  List<ColumnIdentifier> argNames,\n                                                  List<AbstractType<?>> argTypes,\n                                                  AbstractType<?> returnType,\n                                                  boolean calledOnNullInput,\n                                                  String language,\n                                                  String body,\n                                                  InvalidRequestException reason)\n    {\n        return new UDFunction(name, argNames, argTypes, returnType, calledOnNullInput, language, body)\n        {\n            protected ExecutorService executor()\n            {\n                return ImmediateExecutor.INSTANCE;\n            }\n\n            @Override\n            protected Object executeAggregateUserDefined(Object firstParam, Arguments arguments)\n            {\n                throw broken();\n            }\n\n            @Override\n            public ByteBuffer executeUserDefined(Arguments arguments)\n            {\n                throw broken();\n            }\n\n            private InvalidRequestException broken()\n            {\n                return new InvalidRequestException(String.format(\"Function '%s' exists but hasn't been loaded successfully \"\n                                                                 + \"for the following reason: %s. Please see the server log for details\",\n                                                                 this,\n                                                                 reason.getMessage()));\n            }\n        };\n    }\n","sourceCodeStart":282,"sourceCodeEnd":318,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/cql3/functions/UDFunction.java#L282-L318","documentation":"When a user-defined function (UDF) failed to load (e.g. its Java/JavaScript class could not be compiled, the declared body was invalid, or a dependency was missing), Cassandra creates a broken placeholder UDFunction whose aggregate execution path (executeAggregateUserDefined) unconditionally throws broken() — an InvalidRequestException stating the function exists but wasn't loaded, with the original reason embedded.","triggerScenarios":"Calling an aggregate UDF (created via CREATE FUNCTION ... RETURNS NULL ON NULL INPUT with an aggregate/ finalfunc pattern, or applied via aggregate execution paths like SELECT myudf(col) in aggregation) whose runtime class never compiled/loaded after CREATE FUNCTION or after node restart/reload.","commonSituations":"Java runtime version changed after UDF creation (Java 8 code failing on Java 11/17 nodes); sandbox-restricted APIs used in the function body; malformed script body; a schema-restore where the UDF code fails on new nodes.","solutions":["Read the server log for the original load failure reason cited in the message","Fix and re-create the function: DROP FUNCTION then CREATE FUNCTION with corrected code","Ensure all nodes run a JDK compatible with the UDF's language and that cassandra.yaml allows UDFs (enable_user_defined_functions: true)","Check that the body only uses sandbox-permitted APIs and compiles for the cluster's Java version"],"exampleFix":"// before: body fails to compile/load on JDK 17\nCREATE FUNCTION f(x int) RETURNS NULL ON NULL INPUT RETURNS int LANGUAGE java AS 'return x.intValue().longValue();';\n// after\ndatastax session.execute(\"CREATE OR REPLACE FUNCTION f(x int) RETURNS NULL ON NULL INPUT RETURNS int LANGUAGE java AS 'return Long.valueOf(x.longValue());'\");","handlingStrategy":"try-catch","validationCode":"// verify the UDF loaded before use\nconst rows = await session.execute(\"SELECT function_name FROM system_schema.functions WHERE keyspace_name='ks' AND function_name='f'\");\nif (rows.rows.length === 0) throw new Error('UDF f missing');","typeGuard":null,"tryCatchPattern":"try {\n  await session.execute(\"SELECT f(x) FROM ks.t\");\n} catch (e) {\n  if (/hasn't been loaded successfully/.test(e.message)) {\n    console.error('UDF broken, check server log; re-create function', e.message);\n  } else throw e;\n}","preventionTips":["Test every UDF with a smoke query right after CREATE FUNCTION on each node","Keep UDF bodies compatible with the cluster's JDK version","Enable and pin enable_user_defined_functions consistently cluster-wide","Re-validate UDFs after upgrades or schema restores"],"tags":["cql","udf","class-loading"],"backgroundTag":"module-init-failed","analyzedSha":"88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1","analyzedAt":"2026-09-10T07:29:22.284Z","contentChangedAt":"2026-09-10T07:29:22.284Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}