{"record":{"id":"0c3640e5f991e402","repo":"apache/cassandra","slug":"java-source-compilation-failed","errorCode":null,"errorMessage":"Java source compilation failed:\n","messagePattern":"Java source compilation failed:\n","errorType":"validation","errorClass":"InvalidRequestException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/cql3/functions/JavaBasedUDFunction.java","lineNumber":314,"sourceCode":"                                    .append(problem.getSourceLineNumber())\n                                    .append(\" (in generated source): \")\n                                    .append(problem.getMessage())\n                                    .append('\\n');\n                            fullSource = true;\n                        }\n                    }\n                    else\n                    {\n                        problems.append(\"Line \")\n                                .append(Long.toString(ln))\n                                .append(\": \")\n                                .append(problem.getMessage())\n                                .append('\\n');\n                    }\n                }\n\n                if (fullSource)\n                    throw new InvalidRequestException(\"Java source compilation failed:\\n\" + problems + \"\\n generated source:\\n\" + javaSource);\n                else\n                    throw new InvalidRequestException(\"Java source compilation failed:\\n\" + problems);\n            }\n\n            // Verify the UDF bytecode against use of probably dangerous code\n            Set<String> errors = udfByteCodeVerifier.verify(targetClassName, targetClassLoader.classData(targetClassName));\n            String validDeclare = \"not allowed method declared: \" + executeInternalName + '(';\n            for (Iterator<String> i = errors.iterator(); i.hasNext();)\n            {\n                String error = i.next();\n                // we generate a random name of the private, internal execute method, which is detected by the byte-code verifier\n                if (error.startsWith(validDeclare))\n                    i.remove();\n            }\n            if (!errors.isEmpty())\n                throw new InvalidRequestException(\"Java UDF validation failed: \" + errors);\n\n            // Load the class and create a new instance of it","sourceCodeStart":296,"sourceCodeEnd":332,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/cql3/functions/JavaBasedUDFunction.java#L296-L332","documentation":"When a Java UDF (CREATE FUNCTION ... RETURNS NULL ON NULL INPUT / CALLED ...) is created, its generated Java source is compiled in-process. If the compiler reports diagnostics, JavaBasedUDFunction throws this InvalidRequestException listing the problems (and, when full source is enabled, the generated source). It means the UDF's Java body did not compile.","triggerScenarios":"CREATE FUNCTION with a Java body containing syntax errors, wrong types, unknown identifiers, wrong return type, or signature mismatches between the declared (state_type, arg types) and the generated execute method.","commonSituations":"Typos in the Java body; returning the wrong type (e.g. returning int for a bigint function); using imports/classes not on the allowed classpath; missing semicolons; quoting issues in cqlsh breaking the code string.","solutions":["Read the compiler 'problems' list in the error and fix the reported line(s) in the function body.","Ensure the return expression's type matches the declared RETURNS type and parameter usage matches declared arg types.","Drop and recreate the function: DROP FUNCTION name; CREATE FUNCTION ... with corrected body.","Enable full source output (udf fail logs / generated source) to see the actual generated code being compiled.","Test the same logic in plain Java first, then port it into the UDF body."],"exampleFix":"// before\nCREATE FUNCTION f(x int) RETURNS int ... ' return \"hi\"; '\n// after\nCREATE FUNCTION f(x int) RETURNS int ... ' return x + 1; '","handlingStrategy":"validation","validationCode":"// before CREATE FUNCTION, compile the same logic locally:\n// javac -d /tmp MyUdf.java  (mirror body + declared arg/return types)\n// ensure return type of body matches declared RETURNS type","typeGuard":null,"tryCatchPattern":"try { session.execute(createFunctionDdl); } catch (InvalidRequestException e) { if (e.getMessage().contains(\"Java source compilation failed\")) { /* parse 'problems' list and correct body, then re-CREATE */ } else throw e; }","preventionTips":["Test UDF logic as plain Java before embedding in DDL","Keep body return type identical to declared RETURNS type","Avoid complex expressions; keep UDF bodies small","Beware cqlsh quoting mangling the body string"],"tags":["udf","java","compilation"],"backgroundTag":"schema-validation-failed","analyzedSha":"88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1","analyzedAt":"2026-09-10T07:29:22.284Z","contentChangedAt":"2026-09-10T07:29:22.284Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}