{"record":{"id":"01c9365a52264ba8","repo":"apache/flink","slug":"internal-error-occurred","errorCode":null,"errorMessage":"Internal error occurred.","messagePattern":"Internal error occurred\\.","errorType":"exception","errorClass":"InvalidTypesException","httpStatus":null,"severity":"error","filePath":"flink-core/src/main/java/org/apache/flink/api/java/typeutils/TypeExtractor.java","lineNumber":575,"sourceCode":"                \"Input type argument index was not provided\");\n        Preconditions.checkArgument(\n                outputTypeArgumentIndex >= 0, \"Output type argument index was not provided\");\n        Preconditions.checkArgument(\n                lambdaOutputTypeArgumentIndices != null,\n                \"Indices for output type arguments within lambda not provided\");\n\n        // explicit result type has highest precedence\n        if (function instanceof ResultTypeQueryable) {\n            return ((ResultTypeQueryable<OUT>) function).getProducedType();\n        }\n\n        // perform extraction\n        try {\n            final LambdaExecutable exec;\n            try {\n                exec = checkAndExtractLambda(function);\n            } catch (TypeExtractionException e) {\n                throw new InvalidTypesException(\"Internal error occurred.\", e);\n            }\n            if (exec != null) {\n\n                // parameters must be accessed from behind, since JVM can add additional parameters\n                // e.g. when using local variables inside lambda function\n                // paramLen is the total number of parameters of the provided lambda, it includes\n                // parameters added through closure\n                final int paramLen = exec.getParameterTypes().length;\n\n                final Method sam = TypeExtractionUtils.getSingleAbstractMethod(baseClass);\n\n                // number of parameters the SAM of implemented interface has; the parameter indexing\n                // applies to this range\n                final int baseParametersLen = sam.getParameterCount();\n\n                final Type output;\n                if (lambdaOutputTypeArgumentIndices.length > 0) {\n                    output =","sourceCodeStart":557,"sourceCodeEnd":593,"githubUrl":"https://github.com/apache/flink/blob/2f3c205e9266cb30240eb7f4fdab15cad629a70f/flink-core/src/main/java/org/apache/flink/api/java/typeutils/TypeExtractor.java#L557-L593","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Replace the lambda with an anonymous class implementing the Flink function interface.","Specify the return type explicitly using .returns(TypeInformation.of(...)).","Implement ResultTypeQueryable on a named class.","Check the chained cause exception for the specific failure (ClassNotFoundException, SecurityException, etc.) and address it.","Ensure the thread context classloader can load the lambda's implementing class."],"exampleFix":"// before\nds.map(x -> new MyObject(x))\n// after\nds.map(new MapFunction<String, MyObject>() {\n    @Override\n    public MyObject map(String x) { return new MyObject(x); }\n}).returns(TypeInformation.of(MyObject.class));","handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n    ds.map(lambdaFn);\n} catch (InvalidTypesException e) {\n    if (\"Internal error occurred.\".equals(e.getMessage()) && e.getCause() != null) {\n        // lambda extraction failed; inspect e.getCause() for details\n        logger.error(\"Lambda extraction failed\", e.getCause());\n        ds.map(new MapFunction<IN, OUT>() {\n            public OUT map(IN v) { return lambdaFn.map(v); }\n        }).returns(TypeInformation.of(OUT.class));\n    } else {\n        throw e;\n    }\n}","preventionTips":["Avoid lambdas for function classes in environments with custom classloaders.","Always provide .returns() type hints when using lambdas.","Check the chained cause for specific extraction failures."],"tags":["type-extraction","lambda","unary-operator","internal-error"],"backgroundTag":null,"analyzedSha":"2f3c205e9266cb30240eb7f4fdab15cad629a70f","analyzedAt":"2026-08-14T08:48:24.518Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}