karatelabs/karate · error · JsErrorException

no instance property:

Error message

no instance property: 

What it means

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.

Solutions

  1. Confirm a public field or a getX()/isX() getter exists for the property name.
  2. For Java Maps, use obj.get('key') rather than property access.
  3. Use karate.log(obj) or obj.getClass() to verify the object's actual type.
  4. Convert the Java object to a JS value first if you need dynamic property access.

Example fix

// before
var map = karate.call('helper.feature').result;
var x = map.missingKey; // Java map: no such property
// after
var x = map.get('missingKey'); // or check containsKey first
Defensive patterns

Strategy: type-guard

Validate before calling

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; } } }

Try / catch

var v;
try { v = obj.prop; } catch (e) { if (String(e).indexOf('no instance property') !== -1) { v = undefined; } else { throw e; } }

Prevention

When it happens

Trigger: obj.someName read in a Karate JS block where the object's class has no field or getX()/isX() accessor matching someName.

Common situations: 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.

Related errors


AI-assisted analysis of karatelabs/karate@a22eb90246 (2026-09-12). Data as JSON: /api/errors/bbb8e89466fb6be7. Report an issue: GitHub.

Appendix: source

Thrown at karate-js/src/main/java/io/karatelabs/js/JavaUtils.java:232

            return getter;
        }
        try {
            return clazz.getField(name);
        } catch (Exception e) {
            // no public field of that name — fall through to the method scan
        }
        for (Method m : clazz.getMethods()) {
            if (m.getName().equals(name)) {
                return METHOD_MARKER;
            }
        }
        return NOT_FOUND;
    }

    static Object get(Object object, String name) {
        Object result = getOrNotFound(object, name);
        if (result == NOT_FOUND) {
            throw JsErrorException.typeError("no instance property: " + name);
        }
        return result;
    }

    /**
     * {@link #get} for callers that treat "no such property" as an ordinary answer rather than
     * an error — the JS bridge, which turns it into {@code undefined}. Building a TypeError for
     * that, stack trace and all, was pure cost on a path that discards it. A getter that throws
     * still raises, because that is a real failure.
     */
    static Object getOrNotFound(Object object, String name) {
        Object member = resolveMember(object.getClass(), name);
        if (member == NOT_FOUND) {
            return NOT_FOUND;
        }
        if (member == METHOD_MARKER) {
            return new JavaObject(object).getMethod(name);
        }

View on GitHub (pinned to a22eb90246)