apache/cassandra · error · InvalidRequestException
Java source compilation failed:
Error message
Java source compilation failed:
What it means
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.
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.
Example fix
// before CREATE FUNCTION f(x int) RETURNS int ... ' return "hi"; ' // after CREATE FUNCTION f(x int) RETURNS int ... ' return x + 1; '
Defensive patterns
Strategy: validation
Validate before calling
// before CREATE FUNCTION, compile the same logic locally: // javac -d /tmp MyUdf.java (mirror body + declared arg/return types) // ensure return type of body matches declared RETURNS type
Try / catch
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; } Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.
Related errors
- Could not compile function
- Java source compilation failed:\n
- Check your source to not define additional Java methods or…
- Currently only Java UDFs are available in Cassandra. For…
- Function does not declare an argument named
AI-assisted analysis of apache/cassandra@88fd0f6a0e (2026-09-10).
Data as JSON: /api/errors/0c3640e5f991e402.
Report an issue: GitHub.
Appendix: source
Thrown at src/java/org/apache/cassandra/cql3/functions/JavaBasedUDFunction.java:314
.append(problem.getSourceLineNumber())
.append(" (in generated source): ")
.append(problem.getMessage())
.append('\n');
fullSource = true;
}
}
else
{
problems.append("Line ")
.append(Long.toString(ln))
.append(": ")
.append(problem.getMessage())
.append('\n');
}
}
if (fullSource)
throw new InvalidRequestException("Java source compilation failed:\n" + problems + "\n generated source:\n" + javaSource);
else
throw new InvalidRequestException("Java source compilation failed:\n" + problems);
}
// Verify the UDF bytecode against use of probably dangerous code
Set<String> errors = udfByteCodeVerifier.verify(targetClassName, targetClassLoader.classData(targetClassName));
String validDeclare = "not allowed method declared: " + executeInternalName + '(';
for (Iterator<String> i = errors.iterator(); i.hasNext();)
{
String error = i.next();
// we generate a random name of the private, internal execute method, which is detected by the byte-code verifier
if (error.startsWith(validDeclare))
i.remove();
}
if (!errors.isEmpty())
throw new InvalidRequestException("Java UDF validation failed: " + errors);
// Load the class and create a new instance of itView on GitHub (pinned to 88fd0f6a0e)