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.

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 it

View on GitHub (pinned to 88fd0f6a0e)

Solutions

  1. Read the compiler 'problems' list in the error and fix the reported line(s) in the function body.
  2. Ensure the return expression's type matches the declared RETURNS type and parameter usage matches declared arg types.
  3. Drop and recreate the function: DROP FUNCTION name; CREATE FUNCTION ... with corrected body.
  4. Enable full source output (udf fail logs / generated source) to see the actual generated code being compiled.
  5. 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

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


AI-assisted analysis of apache/cassandra@88fd0f6a0e (2026-09-10). Data as JSON: /api/errors/0c3640e5f991e402. Report an issue: GitHub.