{"record":{"id":"dbfe69b4a4fed7db","repo":"karatelabs/karate","slug":"no-such-api-on-java-name","errorCode":null,"errorMessage":"no such api on Java: {name}","messagePattern":"no such api on Java: (.+?)","errorType":"exception","errorClass":"JsErrorException","httpStatus":null,"severity":"error","filePath":"karate-js/src/main/java/io/karatelabs/js/JsJava.java","lineNumber":61,"sourceCode":"                // null-as-sentinel contract is needed by PropertyAccess for\n                // the dotted-FQN probe, so we keep it. But here the script\n                // explicitly asked for this class; a null result must surface\n                // as a real error rather than silently propagating and\n                // failing later as \"cannot read properties of null\".\n                ExternalAccess type = bridge.forType(className);\n                if (type == null) {\n                    throw JsErrorException.typeError(\"Java.type: class not found: \" + className);\n                }\n                return type;\n            };\n            case \"to\" -> (JsInvokable) args -> {\n                if (args[0] instanceof ExternalAccess ja) {\n                    return ja.getJavaValue();\n                }\n                // TODO regex, functions, lambdas\n                return null;\n            };\n            default -> throw JsErrorException.typeError(\"no such api on Java: \" + name);\n        };\n    }\n\n}\n","sourceCodeStart":43,"sourceCodeEnd":66,"githubUrl":"https://github.com/karatelabs/karate/blob/a22eb90246d958d15a47bf436693d0121ad2812d/karate-js/src/main/java/io/karatelabs/js/JsJava.java#L43-L66","documentation":"The Java bridge object in JS only exposes a fixed set of named APIs (e.g. 'type', 'to'); requesting an unknown member name throws this TypeError from the switch default in jsGet. It means the script accessed Java.<name> for a name the bridge does not implement.","triggerScenarios":"Writing Java.import('...') or Java.somethingElse(...) where the bridge only supports Java.type(...)/Java.to(...); typos like Java.Type(); porting Nashorn code that used APIs Karate's bridge does not provide.","commonSituations":"Migrating legacy Nashorn/GraalJS scripts that used Java.import or Java.extend; guessing at the bridge surface without checking documentation; case-sensitivity mistakes.","solutions":["Use Java.type('fully.qualified.ClassName') to obtain the class, then call static members on it.","Check the supported bridge API surface (jsGet cases in JsJava.java) and use only those names.","For collections, use Java.to(...) instead of Nashorn-era helpers.","Fix capitalization/typos in the member name after Java."],"exampleFix":"// before\nvar List = Java.import('java.util.ArrayList'); // no such api\n// after\nvar ArrayList = Java.type('java.util.ArrayList');\nvar list = new ArrayList();","handlingStrategy":"validation","validationCode":"// only Java.type / Java.to (and documented cases) are valid; check the member name against the JsJava bridge surface before use","typeGuard":null,"tryCatchPattern":"try { var C = Java.type(name); } catch (e) { if (String(e).indexOf('no such api on Java') !== -1) { karate.log('use Java.type(...), not Java.' + name); } else { throw e; } }","preventionTips":["Use Java.type() for classes and Java.to() for arrays; nothing else on the Java object","Do not carry over Nashorn APIs (Java.import, Java.extend) unmodified","Watch capitalization: Java.Type is not Java.type"],"tags":["javascript","java-interop","unsupported-api"],"backgroundTag":"unsupported-operation","analyzedSha":"a22eb90246d958d15a47bf436693d0121ad2812d","analyzedAt":"2026-09-12T09:01:00.220Z","contentChangedAt":"2026-09-12T09:01:00.220Z","schemaVersion":2},"datasetVersion":"2026-09-19T12:17:13.211Z"}