{"record":{"id":"564057919b6434a4","repo":"apache/flink","slug":"given-class-is-not-a-functionalinterface","errorCode":null,"errorMessage":"Given class: {}is not a FunctionalInterface.","messagePattern":"Given class: (.+?)is not a FunctionalInterface\\.","errorType":"exception","errorClass":"InvalidTypesException","httpStatus":null,"severity":"error","filePath":"flink-core/src/main/java/org/apache/flink/api/java/typeutils/TypeExtractionUtils.java","lineNumber":238,"sourceCode":"            }\n        } else {\n            throw new InvalidTypesException(\n                    \"The given type \" + t + \" is not a parameterized type.\");\n        }\n    }\n\n    /**\n     * Extracts a Single Abstract Method (SAM) as defined in Java Specification (4.3.2. The Class\n     * Object, 9.8 Functional Interfaces, 9.4.3 Interface Method Body) from given class.\n     *\n     * @param baseClass a class that is a FunctionalInterface to retrieve a SAM from\n     * @throws InvalidTypesException if the given class does not implement FunctionalInterface\n     * @return single abstract method of the given class\n     */\n    public static Method getSingleAbstractMethod(Class<?> baseClass) {\n\n        if (!baseClass.isInterface()) {\n            throw new InvalidTypesException(\n                    \"Given class: \" + baseClass + \"is not a FunctionalInterface.\");\n        }\n\n        Method sam = null;\n        for (Method method : baseClass.getMethods()) {\n            if (Modifier.isAbstract(method.getModifiers())) {\n                if (sam == null) {\n                    sam = method;\n                } else {\n                    throw new InvalidTypesException(\n                            \"Given class: \"\n                                    + baseClass\n                                    + \" is not a FunctionalInterface. It has more than one abstract method.\");\n                }\n            }\n        }\n\n        if (sam == null) {","sourceCodeStart":220,"sourceCodeEnd":256,"githubUrl":"https://github.com/apache/flink/blob/2f3c205e9266cb30240eb7f4fdab15cad629a70f/flink-core/src/main/java/org/apache/flink/api/java/typeutils/TypeExtractionUtils.java#L220-L256","documentation":"Thrown by TypeExtractionUtils.getSingleAbstractMethod when the baseClass is not an interface (baseClass.isInterface() returns false). The method expects a functional interface (which by definition is an interface with a single abstract method). Passing a concrete class or an abstract class triggers this error. Note: the message has a missing space between the class name and 'is'.","triggerScenarios":"Calling getSingleAbstractMethod with a concrete class instead of an interface. Passing an abstract class that is not annotated @FunctionalInterface. The type extraction logic encounters a function that is not based on an interface (e.g. extending an abstract class instead of implementing an interface).","commonSituations":"Developer creates a custom function by extending an abstract class rather than implementing Flink's function interfaces. Using a class-based (non-interface) function implementation that bypasses the standard SAM extraction path.","solutions":["Ensure your function implements the appropriate Flink interface (e.g. MapFunction, FlatMapFunction).","If you need class-based inheritance, implement ResultTypeQueryable to provide type information directly.","Specify the type explicitly using .returns(TypeInformation.of(...))."],"exampleFix":"// before\npublic abstract class MyMapper extends RichMapFunction { ... }\nds.map(new MyMapper() { ... })\n// after\npublic class MyMapper implements MapFunction<String, Integer> {\n    public Integer map(String s) { return s.length(); }\n}","handlingStrategy":"type-guard","validationCode":"if (!baseClass.isInterface()) {\n    throw new IllegalArgumentException(\n        baseClass + \" must be an interface for SAM extraction\");\n}","typeGuard":"static boolean isFunctionalInterfaceCandidate(Class<?> clazz) {\n    return clazz.isInterface() && clazz.getAnnotation(FunctionalInterface.class) != null;\n}","tryCatchPattern":null,"preventionTips":["Implement Flink's function interfaces (which are all interfaces), not abstract classes.","Annotate custom interfaces with @FunctionalInterface for compile-time validation.","Implement ResultTypeQueryable if you must use class-based inheritance."],"tags":["type-extraction","functional-interface","lambda","reflection"],"backgroundTag":null,"analyzedSha":"2f3c205e9266cb30240eb7f4fdab15cad629a70f","analyzedAt":"2026-08-14T08:48:24.518Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}