{"record":{"id":"e9f0ae455c82de9d","repo":"prestodb/presto","slug":"function-implementation-error-e9f0ae","errorCode":"FUNCTION_IMPLEMENTATION_ERROR","errorMessage":"Failed to get function body for method [%s]","messagePattern":"Failed to get function body for method \\[(.+?)\\]","errorType":"error_code","errorClass":"PrestoException","httpStatus":null,"severity":"error","filePath":"presto-main-base/src/main/java/com/facebook/presto/operator/scalar/annotations/SqlInvokedScalarFromAnnotationsParser.java","lineNumber":161,"sourceCode":"                    .collect(toImmutableList());\n        }\n        else {\n            parameters = ImmutableList.of();\n        }\n\n        // Routine characteristics\n        RoutineCharacteristics routineCharacteristics = RoutineCharacteristics.builder()\n                .setLanguage(RoutineCharacteristics.Language.SQL)\n                .setDeterminism(functionHeader.deterministic() ? DETERMINISTIC : NOT_DETERMINISTIC)\n                .setNullCallClause(functionHeader.calledOnNullInput() ? CALLED_ON_NULL_INPUT : RETURNS_NULL_ON_NULL_INPUT)\n                .build();\n\n        String body;\n        try {\n            body = (String) method.invoke(null);\n        }\n        catch (ReflectiveOperationException e) {\n            throw new PrestoException(FUNCTION_IMPLEMENTATION_ERROR, format(\"Failed to get function body for method [%s]\", method), e);\n        }\n\n        List<TypeVariableConstraint> typeVariableConstraints = stream(method.getAnnotationsByType(TypeParameter.class))\n                .map(t -> withVariadicBound(t.value(), t.boundedBy().isEmpty() ? null : t.boundedBy()))\n                .collect(toImmutableList());\n\n        return Stream.concat(Stream.of(functionHeader.value()), stream(functionHeader.alias()))\n                .map(name -> new SqlInvokedFunction(\n                        QualifiedObjectName.valueOf(defaultNamespace, name),\n                        parameters,\n                        typeVariableConstraints,\n                        emptyList(),\n                        returnType,\n                        functionDescription,\n                        routineCharacteristics,\n                        body,\n                        false,\n                        notVersioned(),","sourceCodeStart":143,"sourceCodeEnd":179,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-main-base/src/main/java/com/facebook/presto/operator/scalar/annotations/SqlInvokedScalarFromAnnotationsParser.java#L143-L179","documentation":"For SQL-invoked scalar functions (declared with @SqlInvokedScalarFunction), the parser reflectively invokes a static method to retrieve the SQL function body string. If that invocation fails with a ReflectiveOperationException, the parser throws FUNCTION_IMPLEMENTATION_ERROR stating it failed to get the function body for the method. This occurs at function-registration/catalog-initialization time, before any query runs.","triggerScenarios":"A function-definition class where the body-providing method is not static/public, has unexpected parameters, or throws when invoked; class initialization failures inside the function-definition class also surface here.","commonSituations":"Hand-written SQL function plugins with a typo in the method contract; bytecode/dependency issues preventing class loading; Presto version upgrades changing the @SqlInvokedScalarFunction contract; shaded jars hiding required classes.","solutions":["Inspect the server log for the cause chain attached to this PrestoException.","Ensure the body method is public static, takes no arguments, and returns String.","Verify the function definition class is on the plugin classpath and loads without errors.","Rebuild the plugin against the server's Presto version to align with API changes."],"exampleFix":"// before (instance method, wrong contract)\nprivate String myFuncBody() { return \"...\"; }\n// after\npublic static String myFuncBody() { return \"...\"; }","handlingStrategy":"try-catch","validationCode":null,"typeGuard":"// pre-check body method contract\nboolean validBodyMethod(java.lang.reflect.Method m) {\n    return java.lang.reflect.Modifier.isStatic(m.getModifiers())\n        && m.getParameterCount() == 0\n        && m.getReturnType() == String.class;\n}","tryCatchPattern":"try { catalog.registerFunctions(funcClasses); } catch (PrestoException e) { if (e.getErrorCode().getName().equals(\"FUNCTION_IMPLEMENTATION_ERROR\")) { log.error(\"SQL function body extraction failed: \" + e.getCause(), e); throw e; } }","preventionTips":["Make body-provider methods public static, zero-arg, returning String.","Compile plugins against the exact server Presto version.","Avoid shading JDK/core classes needed by function-definition classes.","Smoke-test function registration at startup before serving queries."],"tags":["presto","function-implementation","sql-functions","reflection","plugin"],"backgroundTag":"function-implementation-error","analyzedSha":"55bb57d202de3b926896fa966c2c4a44c779634e","analyzedAt":"2026-09-04T12:50:26.162Z","contentChangedAt":"2026-09-04T12:50:26.162Z","schemaVersion":2},"datasetVersion":"2026-09-11T21:17:09.523Z"}