{"record":{"id":"6518100a12d3246f","repo":"karatelabs/karate","slug":"no-such-method-settername","errorCode":null,"errorMessage":"no such method: <setterName>","messagePattern":"no such method: <setterName>","errorType":"exception","errorClass":"java.lang.RuntimeException","httpStatus":null,"severity":"error","filePath":"karate-js/src/main/java/io/karatelabs/js/JavaUtils.java","lineNumber":267,"sourceCode":"            return new JavaObject(object).getMethod(name);\n        }\n        try {\n            if (member instanceof Field field) {\n                return field.get(object);\n            }\n            return ((Method) member).invoke(object, EMPTY);\n        } catch (Exception e) {\n            throw JsErrorException.typeError(\"cannot get .\" + name + \" (on \" + jsTypeName(object.getClass()) + \")\");\n        }\n    }\n\n    static void set(Object object, String name, Object value) {\n        String setterName = \"set\" + name.substring(0, 1).toUpperCase() + name.substring(1);\n        Object[] args = new Object[]{value};\n        try {\n            Method method = findMethod(object.getClass(), setterName, args);\n            if (method == null) {\n                throw new RuntimeException(\"no such method: \" + setterName);\n            }\n            method.invoke(object, args);\n        } catch (Exception e) {\n            throw JsErrorException.typeError(\"cannot set .\" + name + \" (on \" + jsTypeName(object.getClass()) + \")\");\n        }\n    }\n\n    //==================================================================================================================\n    //\n    static final Object[] EMPTY = new Object[0];\n\n    private static Class<?>[] paramTypes(Object[] args) {\n        Class<?>[] paramTypes = new Class[args.length];\n        for (int i = 0; i < args.length; i++) {\n            Object arg = args[i];\n            paramTypes[i] = arg == null ? Object.class : arg.getClass();\n        }\n        return paramTypes;","sourceCodeStart":249,"sourceCodeEnd":285,"githubUrl":"https://github.com/karatelabs/karate/blob/a22eb90246d958d15a47bf436693d0121ad2812d/karate-js/src/main/java/io/karatelabs/js/JavaUtils.java#L249-L285","documentation":"JavaUtils.set assigns a Java bean property from JS by constructing the setter name ('set' + capitalized field) and reflectively finding it. If no matching setter method exists it throws 'no such method: <setterName>', which is then converted to a JS typeError 'cannot set .<name>'.","triggerScenarios":"Setting a property on a Java object from JS where the bean has no setter for that name — e.g. `obj.someField = value` on a Java instance whose class lacks setSomeField, or the field is read-only/final.","commonSituations":"Assuming JS property assignment works like direct field access on Java objects; Java classes with fluent/builder APIs instead of bean setters; property name casing mismatches; records or immutable objects without setters.","solutions":["Add a standard bean setter (setXxx) to the Java class, or use an existing mutator method explicitly","Call the mutation method directly from JS instead of property assignment syntax","Check property-name capitalization — the setter name is derived from the first letter capitalized","If the object is meant to be immutable, construct a new instance with the desired value instead"],"exampleFix":"// before\nobj.name = 'x'; // no such method: setName\n// after\nobj.setName('x'); // or add setName to the class","handlingStrategy":"validation","validationCode":"function hasSetter(obj, prop) {\n  var setter = 'set' + prop.charAt(0).toUpperCase() + prop.slice(1);\n  return obj[setter] !== undefined;\n}\n// call only if hasSetter(obj, 'name')","typeGuard":null,"tryCatchPattern":"try {\n  obj.name = value;\n} catch (e) {\n  if (String(e).includes('cannot set')) karate.log('no bean setter for', 'name');\n  else throw e;\n}","preventionTips":["Ensure Java classes expose standard bean setters","Use explicit method calls instead of property assignment on Java objects","Watch property-name capitalization when mapping JS names to setters"],"tags":["java-interop","reflection","setter","bean"],"backgroundTag":"method-not-found","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"}