{"record":{"id":"f13af81c2a92f76a","repo":"karatelabs/karate","slug":"cannot-get-on","errorCode":null,"errorMessage":"cannot get . (on )","messagePattern":"cannot get \\. \\(on \\)","errorType":"exception","errorClass":"JsErrorException","httpStatus":null,"severity":"error","filePath":"karate-js/src/main/java/io/karatelabs/js/JavaUtils.java","lineNumber":257,"sourceCode":"     * 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        }\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    //==================================================================================================================","sourceCodeStart":239,"sourceCodeEnd":275,"githubUrl":"https://github.com/karatelabs/karate/blob/a22eb90246d958d15a47bf436693d0121ad2812d/karate-js/src/main/java/io/karatelabs/js/JavaUtils.java#L239-L275","documentation":"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>)'.","triggerScenarios":"Reading obj.someName where the field/getter exists but is not accessible, or the getter throws when invoked (lazy init failure, state-dependent getters).","commonSituations":"Getters that throw due to uninitialized state or missing environment; JPMS-encapsulated classes; reading fields on package-private implementation classes.","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."],"exampleFix":"// before\nvar val = config.connection; // getter throws inside\n// after\nvar val = config.getConnection(); // surfaces real cause directly","handlingStrategy":"try-catch","validationCode":"try { obj.getClass().getMethod('getProp').invoke(obj); } catch (e) { karate.log('getter fails:', e); }","typeGuard":null,"tryCatchPattern":"try { return obj.prop; } catch (e) { if (String(e).indexOf('cannot get') !== -1) { return safeDefault; } throw e; }","preventionTips":["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"],"tags":["javascript","java-interop","reflection","getter"],"backgroundTag":"java-member-not-accessible","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"}