apache/cassandra · error · InvalidRequestException

Java source compilation failed:\n

Error message

Java source compilation failed:\n

What it means

This is the second branch of the same compilation-failure path in JavaBasedUDFunction: when full source is NOT enabled, the exception carries only 'Java source compilation failed:\n' plus the compiler problems, without the generated source. It means the UDF Java body failed to compile and the server omits generated code from the message.

Source

Thrown at src/java/org/apache/cassandra/cql3/functions/JavaBasedUDFunction.java:316

                                    .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
            Thread thread = Thread.currentThread();
            ClassLoader orig = thread.getContextClassLoader();

View on GitHub (pinned to 88fd0f6a0e)

Solutions

  1. Fix the code based on the compiler diagnostics in the message.
  2. If diagnostics are insufficient, temporarily enable showing generated source (cassandra.yaml udf settings / cassandra.u df source logging) to inspect the generated file.
  3. DROP and re-CREATE the function with the corrected body.
  4. Validate the body logic and types offline in plain Java first.

Example fix

// before
CREATE FUNCTION f(x bigint) RETURNS bigint ... ' return x.substring(1); '
// after
CREATE FUNCTION f(x text) RETURNS text ... ' return x.substring(1); '
Defensive patterns

Strategy: validation

Validate before calling

// compile the body offline first:
// javac with same types; only run CREATE FUNCTION after clean compile

Try / catch

try { session.execute(createFunctionDdl); } catch (InvalidRequestException e) { if (e.getMessage().contains("Java source compilation failed")) { /* diagnostics-only message: fix listed problems, optionally enable generated-source dump to debug */ } else throw e; }

Prevention

When it happens

Trigger: CREATE FUNCTION with a Java body that fails javac compilation while the cluster is configured without generated-source dumping (fullSource false), so only diagnostics are returned.

Common situations: Production clusters (source dump disabled) rejecting UDF bodies; same root causes as the full-source variant: type errors, bad syntax, wrong signatures.

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/752bfc5e95e82386. Report an issue: GitHub.