{"record":{"id":"cafa22fe0aa7fd02","repo":"karatelabs/karate","slug":"is-not-a-function-called-on","errorCode":null,"errorMessage":". is not a function (called on )","messagePattern":"\\. is not a function \\(called on \\)","errorType":"exception","errorClass":"JsErrorException","httpStatus":null,"severity":"error","filePath":"karate-js/src/main/java/io/karatelabs/js/JavaUtils.java","lineNumber":59,"sourceCode":"        if (clazz == Boolean.class || clazz == boolean.class) return \"Boolean\";\n        if (clazz == Character.class || clazz == char.class) return \"String\";\n        if (Set.class.isAssignableFrom(clazz)) return \"Set\";\n        return clazz.getSimpleName();\n    }\n\n    static Object construct(Class<?> clazz, Object[] args) {\n        try {\n            Constructor<?> constructor = findConstructor(clazz, args);\n            return constructor.newInstance(args);\n        } catch (Exception e) {\n            throw JsErrorException.typeError(jsTypeName(clazz) + \" is not a constructor\");\n        }\n    }\n\n    static Object invokeStatic(Class<?> clazz, String name, Object[] args) {\n        Method method = findMethod(clazz, name, args);\n        if (method == null) {\n            throw JsErrorException.typeError(\".\" + name + \" is not a function (called on \" + jsTypeName(clazz) + \")\");\n        }\n        try {\n            return invoke(null, method, args);\n        } catch (InvocationTargetException e) {\n            Throwable cause = e.getCause();\n            if (cause instanceof RuntimeException re) {\n                throw re;\n            }\n            if (cause instanceof Error err) {\n                throw err;\n            }\n            throw new RuntimeException(cause == null ? e.getMessage() : cause.getMessage(), cause);\n        } catch (IllegalAccessException e) {\n            throw JsErrorException.typeError(\".\" + name + \" is not accessible (on \" + jsTypeName(clazz) + \")\");\n        }\n    }\n\n    static Object invoke(Object object, String name, Object[] args) {","sourceCodeStart":41,"sourceCodeEnd":77,"githubUrl":"https://github.com/karatelabs/karate/blob/a22eb90246d958d15a47bf436693d0121ad2812d/karate-js/src/main/java/io/karatelabs/js/JavaUtils.java#L41-L77","documentation":"Thrown by JavaUtils.invokeStatic when a static method with the given name and compatible argument types cannot be found on the Java class. The JS engine surfaces it as a TypeError '.<name> is not a function (called on <TypeName>' so script authors see a familiar JS-style message for Java interop failures.","triggerScenarios":"Calling SomeClass.someStatic(...) from a Karate JS block where the class has no static method of that name, or where the arguments match no overload.","commonSituations":"Method renamed/moved across JDK or library versions; calling an instance method as if static; argument type mismatch (JS number vs int/long overload).","solutions":["Verify the method exists as a static member of that exact class (check javadoc for your JDK/library version).","Ensure arguments' types match an overload; wrap numbers with java.lang.Integer or java.lang.Long as needed.","If it's an instance method, get an instance first and call it on that object.","Use class.getMethods()-style inspection (or karate.log on the Java.type result) to list available methods."],"exampleFix":"// before\nvar System = Java.type('java.lang.System');\nvar val = System.getenv('MY_VAR');\n// after (method exists but must be called on env map for non-simple names)\nvar System = Java.type('java.lang.System');\nvar env = System.getenv();\nvar val = env.get('MY_VAR');","handlingStrategy":"type-guard","validationCode":"var System = Java.type('java.lang.System');\nif (!System.getenv) karate.fail('System.getenv not available in this interop context');","typeGuard":"function hasStatic(clazz, name) { try { var m = clazz.getClass().getMethod(name); return java.lang.reflect.Modifier.isStatic(m.getModifiers()); } catch (e) { return false; } }","tryCatchPattern":"try { return Clz.method(args); } catch (e) { if (String(e).indexOf('is not a function') !== -1) { karate.log('missing static method on', Clz); return null; } throw e; }","preventionTips":["Verify method name and case against javadoc for your exact version","Ensure arguments match an existing overload's types","Don't call instance methods through the class handle","Wrap experimental interop calls in try-catch with a karate.log fallback"],"tags":["javascript","java-interop","reflection","method-not-found"],"backgroundTag":"not-a-function","analyzedSha":"a22eb90246d958d15a47bf436693d0121ad2812d","analyzedAt":"2026-09-12T09:01:00.220Z","contentChangedAt":"2026-09-12T09:01:00.220Z","schemaVersion":2},"datasetVersion":"2026-09-16T19:17:19.609Z"}