{"record":{"id":"bbb8e89466fb6be7","repo":"karatelabs/karate","slug":"no-instance-property","errorCode":null,"errorMessage":"no instance property: ","messagePattern":"no instance property: ","errorType":"exception","errorClass":"JsErrorException","httpStatus":null,"severity":"error","filePath":"karate-js/src/main/java/io/karatelabs/js/JavaUtils.java","lineNumber":232,"sourceCode":"            return getter;\n        }\n        try {\n            return clazz.getField(name);\n        } catch (Exception e) {\n            // no public field of that name — fall through to the method scan\n        }\n        for (Method m : clazz.getMethods()) {\n            if (m.getName().equals(name)) {\n                return METHOD_MARKER;\n            }\n        }\n        return NOT_FOUND;\n    }\n\n    static Object get(Object object, String name) {\n        Object result = getOrNotFound(object, name);\n        if (result == NOT_FOUND) {\n            throw JsErrorException.typeError(\"no instance property: \" + name);\n        }\n        return result;\n    }\n\n    /**\n     * {@link #get} for callers that treat \"no such property\" as an ordinary answer rather than\n     * an error — the JS bridge, which turns it into {@code undefined}. Building a TypeError for\n     * that, stack trace and all, was pure cost on a path that discards it. A getter that throws\n     * still raises, because that is a real failure.\n     */\n    static Object getOrNotFound(Object object, String name) {\n        Object member = resolveMember(object.getClass(), name);\n        if (member == NOT_FOUND) {\n            return NOT_FOUND;\n        }\n        if (member == METHOD_MARKER) {\n            return new JavaObject(object).getMethod(name);\n        }","sourceCodeStart":214,"sourceCodeEnd":250,"githubUrl":"https://github.com/karatelabs/karate/blob/a22eb90246d958d15a47bf436693d0121ad2812d/karate-js/src/main/java/io/karatelabs/js/JavaUtils.java#L214-L250","documentation":"Thrown by JavaUtils.get when a property read on a Java object (field or zero-arg getter) finds no matching member — getOrNotFound returns NOT_FOUND and get escalates it to a JS TypeError 'no instance property: <name>'. Distinguished from getOrNotFound, which callers use when a miss is an acceptable answer.","triggerScenarios":"obj.someName read in a Karate JS block where the object's class has no field or getX()/isX() accessor matching someName.","commonSituations":"Reading a property on a Map-like object without using .get(key); typos in getter-derived property names; expecting JS-object behavior from plain Java objects; response objects whose shape differs between library versions.","solutions":["Confirm a public field or a getX()/isX() getter exists for the property name.","For Java Maps, use obj.get('key') rather than property access.","Use karate.log(obj) or obj.getClass() to verify the object's actual type.","Convert the Java object to a JS value first if you need dynamic property access."],"exampleFix":"// before\nvar map = karate.call('helper.feature').result;\nvar x = map.missingKey; // Java map: no such property\n// after\nvar x = map.get('missingKey'); // or check containsKey first","handlingStrategy":"type-guard","validationCode":"function hasProp(obj, name) { try { obj.getClass().getField(name); return true; } catch (e1) { try { obj.getClass().getMethod('get' + name.charAt(0).toUpperCase() + name.slice(1)); return true; } catch (e2) { return false; } } }","typeGuard":null,"tryCatchPattern":"var v;\ntry { v = obj.prop; } catch (e) { if (String(e).indexOf('no instance property') !== -1) { v = undefined; } else { throw e; } }","preventionTips":["Use map.get('key') for Java Maps, not property access","Verify the object's class exposes a field or getX()/isX() getter","Convert Java objects to JS values when you need dynamic property access","Log the object in CI once to capture its real shape"],"tags":["javascript","java-interop","property-not-found","reflection"],"backgroundTag":"property-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"}