karatelabs/karate · error · NullPointerException
object is null
Error message
object is null
What it means
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.
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
Example fix
// before
ExternalAccess access = bridge.forInstance(obj); // NPE when obj == null
// after
if (obj != null) {
ExternalAccess access = bridge.forInstance(obj);
} Defensive patterns
Strategy: type-guard
Validate before calling
if (obj == null) throw new IllegalArgumentException("expected a Java instance"); Type guard
boolean isBridgable(Object o) { return o != null; } Prevention
- Null-check Java values before bridging to JS
- Initialize interop-bound variables before use
- Distinguish 'missing object' (null) from 'object with missing data'
When it happens
Trigger: Calling forInstance(null), or passing a JS-side variable that is actually null/undefined into an API that routes Java objects through ExternalBridge.forInstance.
Common situations: 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.
Related errors
- toBean() needs two arguments: object and class name
- java bridge not enabled
- cannot delete property on
- is not a constructor
- . is not a function (called on )
AI-assisted analysis of karatelabs/karate@a22eb90246 (2026-09-12).
Data as JSON: /api/errors/856c9af971196ff2.
Report an issue: GitHub.
Appendix: source
Thrown at karate-js/src/main/java/io/karatelabs/js/ExternalBridge.java:38
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package io.karatelabs.js;
public interface ExternalBridge {
default ExternalAccess forType(String className) {
try {
return new JavaType(className);
} catch (Exception e) {
return null;
}
}
default ExternalAccess forInstance(Object object) {
if (object == null) {
throw new NullPointerException("object is null");
}
return new JavaObject(object);
}
}
View on GitHub (pinned to a22eb90246)