{"record":{"id":"856c9af971196ff2","repo":"karatelabs/karate","slug":"object-is-null","errorCode":null,"errorMessage":"object is null","messagePattern":"object is null","errorType":"validation","errorClass":"NullPointerException","httpStatus":null,"severity":"error","filePath":"karate-js/src/main/java/io/karatelabs/js/ExternalBridge.java","lineNumber":38,"sourceCode":" * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n * THE SOFTWARE.\n */\npackage io.karatelabs.js;\n\npublic interface ExternalBridge {\n\n    default ExternalAccess forType(String className) {\n        try {\n            return new JavaType(className);\n        } catch (Exception e) {\n            return null;\n        }\n    }\n\n    default ExternalAccess forInstance(Object object) {\n        if (object == null) {\n            throw new NullPointerException(\"object is null\");\n        }\n        return new JavaObject(object);\n    }\n\n}\n","sourceCodeStart":20,"sourceCodeEnd":44,"githubUrl":"https://github.com/karatelabs/karate/blob/a22eb90246d958d15a47bf436693d0121ad2812d/karate-js/src/main/java/io/karatelabs/js/ExternalBridge.java#L20-L44","documentation":"ExternalBridge.forInstance wraps a Java object for JS access and rejects a null argument with a plain NullPointerException. The bridge cannot create a JavaObject view of a nonexistent instance, so null is never accepted.","triggerScenarios":"Calling forInstance(null), or passing a JS-side variable that is actually null/undefined into an API that routes Java objects through ExternalBridge.forInstance.","commonSituations":"JS expressions like `javaObj.someMethod()` where javaObj resolved to null; interop helpers receiving an uninitialized variable; configuration that expected a Java instance but produced null.","solutions":["Ensure the object passed to forInstance (or into the interop call) is non-null before the call","Null-check the Java value at the call site and handle null in JS rather than crossing the bridge","Trace where the null came from — often an earlier API returned null instead of an object","If null is legitimate, avoid bridging and handle it natively"],"exampleFix":"// before\nExternalAccess access = bridge.forInstance(obj); // NPE when obj == null\n// after\nif (obj != null) {\n  ExternalAccess access = bridge.forInstance(obj);\n}","handlingStrategy":"type-guard","validationCode":"if (obj == null) throw new IllegalArgumentException(\"expected a Java instance\");","typeGuard":"boolean isBridgable(Object o) { return o != null; }","tryCatchPattern":null,"preventionTips":["Null-check Java values before bridging to JS","Initialize interop-bound variables before use","Distinguish 'missing object' (null) from 'object with missing data'"],"tags":["javascript","java-interop","null-pointer"],"backgroundTag":"null-argument","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"}