apache/flink · critical · InvalidProgramException

Program cannot be compiled. This is a bug. Please file an is

Error message

Program cannot be compiled. This is a bug. Please file an issue.

What it means

flink-protobuf generates Java source at runtime and compiles it with Janino (SimpleCompiler). If cooking fails — syntax errors or constructs Janino cannot compile in the generated code — the full source is logged and InvalidProgramException('Program cannot be compiled. This is a bug. Please file an issue.') is thrown. By design this always indicates a bug in flink-protobuf's code generator, not user data.

Source

Thrown at flink-formats/flink-protobuf/src/main/java/org/apache/flink/formats/protobuf/util/PbCodegenUtils.java:262

        appender.appendLine(flinkElementVar + " = " + flinkContainerElementCode);
        PbCodegenSerializer codegenSer =
                PbCodegenSerializeFactory.getPbCodegenSer(
                        elementPbFd, elementDataType, pbFormatContext);
        String code = codegenSer.codegen(resultPbVar, flinkElementVar, appender.currentIndent());
        appender.appendSegment(code);
        appender.end("}");
        return appender.code();
    }

    public static Class compileClass(ClassLoader classloader, String className, String code)
            throws ClassNotFoundException {
        SimpleCompiler simpleCompiler = new SimpleCompiler();
        simpleCompiler.setParentClassLoader(classloader);
        try {
            simpleCompiler.cook(code);
        } catch (Throwable t) {
            LOG.error("Protobuf codegen compile error: \n" + code);
            throw new InvalidProgramException(
                    "Program cannot be compiled. This is a bug. Please file an issue.", t);
        }
        return simpleCompiler.getClassLoader().loadClass(className);
    }

    public static boolean needToSplit(int noSplitCodeSize) {
        return noSplitCodeSize >= PbConstant.CODEGEN_SPLIT_THRESHOLD;
    }
}

View on GitHub (pinned to 2f3c205e92)

Solutions

  1. Grab the generated source from the LOG.error output ('Protobuf codegen compile error') — it pinpoints the failing construct.
  2. Upgrade flink-protobuf to the latest patch release; many codegen compile bugs are fixed there.
  3. Work around by splitting very large messages into smaller ones or reducing nesting depth.
  4. Rename proto identifiers that collide with Java keywords.
  5. File a Flink JIRA (flink-formats / Protobuf) with the .proto and the logged generated code.
Defensive patterns

Strategy: fallback

Validate before calling

// Pre-check size to anticipate Janino limits:
if (PbCodegenUtils.needToSplit(noSplitCodeSize)) {
    // ensure you are on a flink-protobuf version where split codegen compiles
}

Try / catch

try {
    clazz = PbCodegenUtils.compileClass(cl, className, code);
} catch (InvalidProgramException e) {
    // capture LOG output 'Protobuf codegen compile error' for the bug report;
    // mitigation: shrink/split the proto schema, then retry
    throw e;
}

Prevention

When it happens

Trigger: Very large or deeply nested protobuf schemas generating code that exceeds Janino limits or contains unsupported syntax; schema shapes (e.g. specific keyword-colliding identifiers) that produce invalid Java; known codegen bugs in specific flink-protobuf versions.

Common situations: Wide enterprise .proto files (hundreds of fields, deep nesting) hitting Janino compiler limits; identifiers in proto that collide with Java keywords; upgrading protobuf schema hits an untested codegen path.

Related errors


AI-assisted analysis of apache/flink@2f3c205e92 (2026-08-14). Data as JSON: /api/errors/948222dd6ff1d984. Report an issue: GitHub.