karatelabs/karate · error · JsErrorException
. is not a property (on )
Error message
. is not a property (on )
What it means
Thrown by JavaUtils.getStatic when the requested name matches no static field, no static getter method, no static method reference, and no nested class on the Java type. It means the property simply does not exist on the class: '.<name> is not a property (on <TypeName>)'.
Solutions
- Verify the exact name of the static field/constant in the class's javadoc.
- Check whether the member is instance-level and needs an object instead of the class handle.
- Confirm the class/package for the constant hasn't changed across library versions.
- Enumerate available members by inspecting the class before access.
Example fix
// before
var Math = Java.type('java.lang.Math');
var x = Math.pie;
// after
var x = Math.PI; Defensive patterns
Strategy: type-guard
Validate before calling
function hasStaticMember(clazz, name) { try { return clazz.getClass().getField(name) != null; } catch (e) { return false; } } Type guard
function safeGetStatic(clazz, name) { try { return clazz[name]; } catch (e) { return undefined; } } Try / catch
try { var v = Clz.CONST; } catch (e) { if (String(e).indexOf('not a property') !== -1) { karate.log('constant missing on', Clz); v = fallback; } else { throw e; } } Prevention
- Copy constant names from javadoc, not memory
- Check whether the member is instance-level, not static
- Confirm the owning class/package across library version changes
- Use an IDE or javap to enumerate statics before scripting
When it happens
Trigger: Reading ClassName.missingField in a Karate JS block where no such static field/getter/method/nested class exists.
Common situations: Typos (Math.PII), assuming constants exist in a different class (Color.RED vs java.awt.Color variants), accessing instance members as static, version drift where a constant moved packages.
Related errors
- cannot set . (on )
- no instance property:
- toBean() needs two arguments: object and class name
- object is null
- java bridge not enabled
AI-assisted analysis of karatelabs/karate@a22eb90246 (2026-09-12).
Data as JSON: /api/errors/64dba3141f767461.
Report an issue: GitHub.
Appendix: source
Thrown at karate-js/src/main/java/io/karatelabs/js/JavaUtils.java:129
} catch (Exception ex) {
throw JsErrorException.typeError("." + name + " is not a function (called on " + jsTypeName(clazz) + ")");
}
}
// Fall back to method reference
for (Method m : clazz.getMethods()) {
if (m.getName().equals(name)) {
JavaType jc = new JavaType(clazz);
return jc.getMethod(name);
}
}
// Static nested class / enum: e.g. Foo.Bar where Bar is a member type
for (Class<?> nested : clazz.getClasses()) {
if (nested.getSimpleName().equals(name)) {
return new JavaType(nested);
}
}
}
throw JsErrorException.typeError("." + name + " is not a property (on " + jsTypeName(clazz) + ")");
}
}
private static Method findStaticGetter(Class<?> clazz, String name) {
String getterSuffix = name.substring(0, 1).toUpperCase() + name.substring(1);
Method method = findStaticMethod(clazz, "get" + getterSuffix);
if (method == null) {
method = findStaticMethod(clazz, "is" + getterSuffix);
}
return method;
}
private static Method findStaticMethod(Class<?> clazz, String name) {
for (Method method : clazz.getMethods()) {
if (method.getName().equals(name) && Modifier.isStatic(method.getModifiers())
&& method.getParameterCount() == 0) {
return method;
}View on GitHub (pinned to a22eb90246)