{"record":{"id":"fa058ded190a8813","repo":"karatelabs/karate","slug":"cause-message-javautils","errorCode":null,"errorMessage":"<cause message>","messagePattern":"<cause message>","errorType":"exception","errorClass":"java.lang.RuntimeException","httpStatus":null,"severity":"error","filePath":"karate-js/src/main/java/io/karatelabs/js/JavaUtils.java","lineNumber":71,"sourceCode":"        }\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) {\n        Method method = findMethod(object.getClass(), name, args);\n        if (method == null) {\n            throw JsErrorException.typeError(\".\" + name + \" is not a function (called on \" + jsTypeName(object.getClass()) + \")\");\n        }\n        try {\n            return invoke(object, method, args);\n        } catch (InvocationTargetException e) {\n            // Unwrap so the underlying Java exception (and its message) reaches the caller\n            // and can become a JS-catchable JsError at the host-function boundary.\n            Throwable cause = e.getCause();\n            if (cause instanceof RuntimeException re) {\n                throw re;","sourceCodeStart":53,"sourceCodeEnd":89,"githubUrl":"https://github.com/karatelabs/karate/blob/a22eb90246d958d15a47bf436693d0121ad2812d/karate-js/src/main/java/io/karatelabs/js/JavaUtils.java#L53-L89","documentation":"JavaUtils.invokeStatic reflects a static method call; any InvocationTargetException is unwrapped: RuntimeExceptions and Errors are rethrown as-is, and anything else becomes a RuntimeException carrying the cause's message (cause == null falls back to e.getMessage()). So this error surfaces the target method's own failure.","triggerScenarios":"A static Java method invoked from JS (e.g. Java.type('X').staticMethod(...)) throws a checked exception; JavaUtils unwraps the InvocationTargetException and rethrows it as RuntimeException with the cause message.","commonSituations":"Java utility methods throwing checked exceptions (IOException etc.) when called from a Karate feature; user-written Java helpers failing on bad input; IllegalAccessException variants are handled separately as typeError, so this specifically means the method itself threw.","solutions":["Read the cause message — the root failure is inside the invoked Java method, not the bridge","Fix the inputs or state that make the Java method throw","Wrap the Java method so it converts checked exceptions to meaningful RuntimeExceptions","Catch the exception in JS with a JS try/catch if the failure is an expected business condition"],"exampleFix":"// before\npublic static Config load(String path) throws IOException {\n  return read(path); // surfaces as RuntimeException: <cause message>\n}\n// after\npublic static Config load(String path) {\n  try {\n    return read(path);\n  } catch (IOException e) {\n    throw new RuntimeException(\"config load failed: \" + path, e);\n  }\n}","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  Java.type('Utils').staticMethod(arg);\n} catch (e) {\n  // e carries the Java method's own failure; inspect and decide\n  karate.log('java static call failed:', e.message);\n}","preventionTips":["Validate arguments in JS before crossing into Java","Make Java helpers throw descriptive unchecked exceptions","Read the cause chain when diagnosing"],"tags":["java-interop","reflection","wrapped-exception"],"backgroundTag":"invalid-argument-value","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"}