apache/flink · error · InvalidTypesException

Internal error occurred.

Error message

Internal error occurred.

What it means

Thrown by TypeExtractor.getUnaryOperatorReturnType (and similar unary extraction methods) when checkAndExtractLambda throws a TypeExtractionException. This wraps the internal lambda-extraction failure as an InvalidTypesException with a generic 'Internal error occurred' message, chaining the original exception as the cause. It indicates the lambda could not be serialized or its implementing method could not be resolved.

Source

Thrown at flink-core/src/main/java/org/apache/flink/api/java/typeutils/TypeExtractor.java:575

                "Input type argument index was not provided");
        Preconditions.checkArgument(
                outputTypeArgumentIndex >= 0, "Output type argument index was not provided");
        Preconditions.checkArgument(
                lambdaOutputTypeArgumentIndices != null,
                "Indices for output type arguments within lambda not provided");

        // explicit result type has highest precedence
        if (function instanceof ResultTypeQueryable) {
            return ((ResultTypeQueryable<OUT>) function).getProducedType();
        }

        // perform extraction
        try {
            final LambdaExecutable exec;
            try {
                exec = checkAndExtractLambda(function);
            } catch (TypeExtractionException e) {
                throw new InvalidTypesException("Internal error occurred.", e);
            }
            if (exec != null) {

                // parameters must be accessed from behind, since JVM can add additional parameters
                // e.g. when using local variables inside lambda function
                // paramLen is the total number of parameters of the provided lambda, it includes
                // parameters added through closure
                final int paramLen = exec.getParameterTypes().length;

                final Method sam = TypeExtractionUtils.getSingleAbstractMethod(baseClass);

                // number of parameters the SAM of implemented interface has; the parameter indexing
                // applies to this range
                final int baseParametersLen = sam.getParameterCount();

                final Type output;
                if (lambdaOutputTypeArgumentIndices.length > 0) {
                    output =

View on GitHub (pinned to 2f3c205e92)

Solutions

  1. Replace the lambda with an anonymous class implementing the Flink function interface.
  2. Specify the return type explicitly using .returns(TypeInformation.of(...)).
  3. Implement ResultTypeQueryable on a named class.
  4. Check the chained cause exception for the specific failure (ClassNotFoundException, SecurityException, etc.) and address it.
  5. Ensure the thread context classloader can load the lambda's implementing class.

Example fix

// before
ds.map(x -> new MyObject(x))
// after
ds.map(new MapFunction<String, MyObject>() {
    @Override
    public MyObject map(String x) { return new MyObject(x); }
}).returns(TypeInformation.of(MyObject.class));
Defensive patterns

Strategy: fallback

Try / catch

try {
    ds.map(lambdaFn);
} catch (InvalidTypesException e) {
    if ("Internal error occurred.".equals(e.getMessage()) && e.getCause() != null) {
        // lambda extraction failed; inspect e.getCause() for details
        logger.error("Lambda extraction failed", e.getCause());
        ds.map(new MapFunction<IN, OUT>() {
            public OUT map(IN v) { return lambdaFn.map(v); }
        }).returns(TypeInformation.of(OUT.class));
    } else {
        throw e;
    }
}

Prevention

When it happens

Trigger: A lambda passed to a unary operator (MapFunction, FlatMapFunction, FilterFunction, etc.) fails reflective extraction. The lambda's implementing class cannot be loaded. The writeReplace method is inaccessible. The implementing method cannot be matched by name and descriptor.

Common situations: Custom classloader or OSGi environment that doesn't expose lambda implementing classes. Security manager blocking reflective access. Bytecode instrumentation altering method signatures. Rare JVM or compiler edge cases with complex lambda expressions.

Related errors


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