{"record":{"id":"aec7299d98636120","repo":"apache/flink","slug":"given-class-is-not-a-functionalinterface-it-d","errorCode":null,"errorMessage":"Given class: {} is not a FunctionalInterface. It does not have any abstract methods.","messagePattern":"Given class: (.+?) is not a FunctionalInterface\\. It does not have any abstract methods\\.","errorType":"exception","errorClass":"InvalidTypesException","httpStatus":null,"severity":"error","filePath":"flink-core/src/main/java/org/apache/flink/api/java/typeutils/TypeExtractionUtils.java","lineNumber":257,"sourceCode":"                    \"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) {\n            throw new InvalidTypesException(\n                    \"Given class: \"\n                            + baseClass\n                            + \" is not a FunctionalInterface. It does not have any abstract methods.\");\n        }\n\n        return sam;\n    }\n\n    /** Returns all declared methods of a class including methods of superclasses. */\n    public static List<Method> getAllDeclaredMethods(Class<?> clazz) {\n        List<Method> result = new ArrayList<>();\n        while (clazz != null) {\n            Method[] methods = clazz.getDeclaredMethods();\n            Collections.addAll(result, methods);\n            clazz = clazz.getSuperclass();\n        }\n        return result;\n    }","sourceCodeStart":239,"sourceCodeEnd":275,"githubUrl":"https://github.com/apache/flink/blob/2f3c205e9266cb30240eb7f4fdab15cad629a70f/flink-core/src/main/java/org/apache/flink/api/java/typeutils/TypeExtractionUtils.java#L239-L275","documentation":"Thrown by TypeExtractionUtils.getSingleAbstractMethod when the interface is valid (isInterface() == true) but has zero abstract methods. This can happen with a marker interface (e.g. Serializable) or an interface that only contains default and static methods. Without an abstract method, there is no SAM to extract from.","triggerScenarios":"Passing a marker interface (like Serializable or Cloneable) as the baseClass for type extraction. An interface that only contains default methods. An interface where all methods are inherited as defaults from parent interfaces.","commonSituations":"Custom function base class is accidentally an empty or marker interface. Refactoring removes the abstract method from a previously-valid functional interface but leaves default methods. Using a configuration or options interface instead of a function interface.","solutions":["Ensure the interface has at least one abstract method (the function to implement).","Implement the correct Flink function interface (MapFunction, FilterFunction, etc.) which has a defined SAM.","Implement ResultTypeQueryable to provide type information without relying on SAM extraction."],"exampleFix":"// before\npublic interface MyConfig extends Serializable { // no abstract methods\n    default int getBatchSize() { return 100; }\n}\n// after\npublic class MyMapper implements MapFunction<String, Integer> {\n    public Integer map(String s) { return s.length(); }\n}","handlingStrategy":"type-guard","validationCode":"long abstractCount = Arrays.stream(baseClass.getMethods())\n    .filter(m -> Modifier.isAbstract(m.getModifiers()))\n    .count();\nif (abstractCount == 0) {\n    throw new IllegalArgumentException(\n        baseClass + \" has no abstract methods; cannot extract SAM\");\n}","typeGuard":"static boolean hasAtLeastOneAbstractMethod(Class<?> clazz) {\n    if (!clazz.isInterface()) return false;\n    return Arrays.stream(clazz.getMethods())\n        .anyMatch(m -> Modifier.isAbstract(m.getModifiers()));\n}","tryCatchPattern":null,"preventionTips":["Ensure function interfaces declare at least one abstract method.","Do not pass marker interfaces (Serializable, Cloneable) as function base classes.","Use Flink's built-in function interfaces which all have a well-defined SAM."],"tags":["type-extraction","functional-interface","lambda","sam"],"backgroundTag":null,"analyzedSha":"2f3c205e9266cb30240eb7f4fdab15cad629a70f","analyzedAt":"2026-08-14T08:48:24.518Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}