karatelabs/karate · error · JsErrorException
cannot get . (on )
Error message
cannot get . (on )
What it means
Thrown by JavaUtils.getOrNotFound when a member (field or getter method) was found by name on the Java object but the reflective read itself fails — IllegalAccessException, InvocationTargetException, etc. Reported as 'cannot get .<name> (on <TypeName>)'.
Solutions
- Call the underlying getter method explicitly to see the real wrapped exception.
- Ensure the object is fully initialized before reading its properties.
- Use the public interface of the object rather than reflective access to non-public members.
- Add --add-opens JVM flags if JPMS blocks an unavoidable internal access.
Example fix
// before var val = config.connection; // getter throws inside // after var val = config.getConnection(); // surfaces real cause directly
Defensive patterns
Strategy: try-catch
Validate before calling
try { obj.getClass().getMethod('getProp').invoke(obj); } catch (e) { karate.log('getter fails:', e); } Try / catch
try { return obj.prop; } catch (e) { if (String(e).indexOf('cannot get') !== -1) { return safeDefault; } throw e; } Prevention
- Initialize the object fully before reading properties
- Call getters explicitly first to surface their real exceptions
- Access objects through public interfaces, not internal classes
- Check for JPMS restrictions if errors appear only on newer JDKs
When it happens
Trigger: Reading obj.someName where the field/getter exists but is not accessible, or the getter throws when invoked (lazy init failure, state-dependent getters).
Common situations: Getters that throw due to uninitialized state or missing environment; JPMS-encapsulated classes; reading fields on package-private implementation classes.
Related errors
- is not a constructor
- . is not a function (called on )
- no instance property:
- toBean() needs two arguments: object and class name
- object is null
AI-assisted analysis of karatelabs/karate@a22eb90246 (2026-09-12).
Data as JSON: /api/errors/f13af81c2a92f76a.
Report an issue: GitHub.
Appendix: source
Thrown at karate-js/src/main/java/io/karatelabs/js/JavaUtils.java:257
* 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);
}
try {
if (member instanceof Field field) {
return field.get(object);
}
return ((Method) member).invoke(object, EMPTY);
} catch (Exception e) {
throw JsErrorException.typeError("cannot get ." + name + " (on " + jsTypeName(object.getClass()) + ")");
}
}
static void set(Object object, String name, Object value) {
String setterName = "set" + name.substring(0, 1).toUpperCase() + name.substring(1);
Object[] args = new Object[]{value};
try {
Method method = findMethod(object.getClass(), setterName, args);
if (method == null) {
throw new RuntimeException("no such method: " + setterName);
}
method.invoke(object, args);
} catch (Exception e) {
throw JsErrorException.typeError("cannot set ." + name + " (on " + jsTypeName(object.getClass()) + ")");
}
}
//==================================================================================================================View on GitHub (pinned to a22eb90246)