{"record":{"id":"171a278ff196d5f8","repo":"karatelabs/karate","slug":"is-not-accessible-on","errorCode":null,"errorMessage":". is not accessible (on )","messagePattern":"\\. is not accessible \\(on \\)","errorType":"exception","errorClass":"JsErrorException","httpStatus":null,"severity":"error","filePath":"karate-js/src/main/java/io/karatelabs/js/JavaUtils.java","lineNumber":73,"sourceCode":"\n    static Object invokeStatic(Class<?> clazz, String name, Object[] args) {\n        Method method = findMethod(clazz, name, args);\n        if (method == null) {\n            throw JsErrorException.typeError(\".\" + name + \" is not a function (called on \" + jsTypeName(clazz) + \")\");\n        }\n        try {\n            return invoke(null, method, args);\n        } catch (InvocationTargetException e) {\n            Throwable cause = e.getCause();\n            if (cause instanceof RuntimeException re) {\n                throw re;\n            }\n            if (cause instanceof Error err) {\n                throw err;\n            }\n            throw new RuntimeException(cause == null ? e.getMessage() : cause.getMessage(), cause);\n        } catch (IllegalAccessException e) {\n            throw JsErrorException.typeError(\".\" + name + \" is not accessible (on \" + jsTypeName(clazz) + \")\");\n        }\n    }\n\n    static Object invoke(Object object, String name, Object[] args) {\n        Method method = findMethod(object.getClass(), name, args);\n        if (method == null) {\n            throw JsErrorException.typeError(\".\" + name + \" is not a function (called on \" + jsTypeName(object.getClass()) + \")\");\n        }\n        try {\n            return invoke(object, method, args);\n        } catch (InvocationTargetException e) {\n            // Unwrap so the underlying Java exception (and its message) reaches the caller\n            // and can become a JS-catchable JsError at the host-function boundary.\n            Throwable cause = e.getCause();\n            if (cause instanceof RuntimeException re) {\n                throw re;\n            }\n            if (cause instanceof Error err) {","sourceCodeStart":55,"sourceCodeEnd":91,"githubUrl":"https://github.com/karatelabs/karate/blob/a22eb90246d958d15a47bf436693d0121ad2812d/karate-js/src/main/java/io/karatelabs/js/JavaUtils.java#L55-L91","documentation":"Thrown by JavaUtils.invokeStatic when a matching static method exists but calling it raises IllegalAccessException — i.e. the method is not accessible from the calling context (non-public, or in a non-exported package under the JPMS module system). It is surfaced as a JS TypeError '.<name> is not accessible (on <TypeName>)'.","triggerScenarios":"Invoking a package-private/protected static method via JS interop, or calling into JDK-internal classes (e.g. sun.misc, jdk.internal.*) that JPMS does not export.","commonSituations":"JDK upgrade where previously reflective calls to internal APIs are now blocked by strong encapsulation (Java 9+); attempting to call internal library helpers not marked public.","solutions":["Use a public API equivalent of the internal method instead.","If you must call it, add JVM flags like --add-opens / --add-exports for the relevant module/package.","Downgrade expectations: check whether the library exposes a supported public wrapper.","Confirm you're not targeting a class inside a sealed/final non-public package."],"exampleFix":"// before\nvar Unsafe = Java.type('sun.misc.Unsafe');\nvar u = Unsafe.getUnsafe();\n// after (public API)\nvar ByteBuffer = Java.type('java.nio.ByteBuffer');\nvar buf = ByteBuffer.allocateDirect(1024);","handlingStrategy":"try-catch","validationCode":"var m = Clz.getClass().getMethod('methodName');\nif (!java.lang.reflect.Modifier.isPublic(m.getModifiers())) karate.log('method not public, will fail under JPMS');","typeGuard":null,"tryCatchPattern":"try { return Clz.internalMethod(); } catch (e) { if (String(e).indexOf('not accessible') !== -1) { return publicFallback(); } throw e; }","preventionTips":["Stick to public documented APIs only","Never target jdk.internal or sun.* packages from feature scripts","If needed, add --add-opens/--add-exports to the JVM command line deliberately","Test interop calls after every JDK upgrade"],"tags":["javascript","java-interop","access-modifier","jpms"],"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-19T12:17:13.211Z"}