{"record":{"id":"3e87c30c23dbed93","repo":"karatelabs/karate","slug":"options-cannot-be-null","errorCode":null,"errorMessage":"options cannot be null","messagePattern":"options cannot be null","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"karate-core/src/main/java/io/karatelabs/driver/cdp/CdpLauncher.java","lineNumber":91,"sourceCode":"        this.process = process;\n        this.host = host;\n        this.port = port;\n        ACTIVE.add(this);\n    }\n\n    /**\n     * Close all active browser instances.\n     */\n    public static void closeAll() {\n        ACTIVE.forEach(CdpLauncher::close);\n    }\n\n    /**\n     * Launch Chrome browser and return launcher instance.\n     */\n    public static CdpLauncher start(CdpDriverOptions options) {\n        if (options == null) {\n            throw new IllegalArgumentException(\"options cannot be null\");\n        }\n\n        String executable = resolveExecutable(options.getExecutable());\n        int port = options.getPort() > 0 ? options.getPort() : PortUtils.findFreePort();\n        String host = options.getHost();\n        if (host == null || host.isEmpty()) {\n            host = \"localhost\";\n        }\n\n        // Ensure timeout is reasonable (minimum 1 second)\n        int timeout = Math.max(options.getTimeout(), 1000);\n\n        List<String> args = buildArgs(executable, port, options);\n        logger.debug(\"launching chrome: {}\", args);\n\n        ProcessHandle process = ProcessHandle.start(\n                ProcessBuilder.create()\n                        .args(args)","sourceCodeStart":73,"sourceCodeEnd":109,"githubUrl":"https://github.com/karatelabs/karate/blob/a22eb90246d958d15a47bf436693d0121ad2812d/karate-core/src/main/java/io/karatelabs/driver/cdp/CdpLauncher.java#L73-L109","documentation":"CdpLauncher.start() requires a CdpDriverOptions object to know which Chrome executable, port, and host to use. This is a fail-fast precondition check: null options would cause an NPE deeper inside launch logic. The library throws IllegalArgumentException immediately so the caller knows the configuration object itself is missing.","triggerScenarios":"Calling CdpLauncher.start(null) directly, or a driver bootstrap path that constructs the CDP launcher without first building a CdpDriverOptions from config.","commonSituations":"Programmatic launcher use where options are conditionally built and a branch leaves them unset; refactoring code that previously read config into options; tests that pass null to shortcut configuration.","solutions":["Construct a CdpDriverOptions (or build it from your karate driver config) before calling start()","Null-check / default the options object at the call site before invoking CdpLauncher.start","If using Karate's driver layer, ensure the driver config actually selects the chrome/cdp driver so options are auto-created"],"exampleFix":"// before\nCdpLauncher launcher = CdpLauncher.start(null);\n// after\nCdpDriverOptions options = new CdpDriverOptions();\noptions.setExecutable(\"/usr/bin/google-chrome\");\nCdpLauncher launcher = CdpLauncher.start(options);","handlingStrategy":"validation","validationCode":"if (options == null) {\n    options = new CdpDriverOptions(); // or load from config\n}\nCdpLauncher.start(options);","typeGuard":"boolean optionsReady(CdpDriverOptions o) { return o != null; }","tryCatchPattern":"try {\n    CdpLauncher.start(options);\n} catch (IllegalArgumentException e) {\n    // options was null — build defaults and retry once\n    CdpLauncher.start(new CdpDriverOptions());\n}","preventionTips":["Build CdpDriverOptions in one factory method so it is never conditionally null","Never pass nullable option objects into launchers","Initialize driver options from karate config at startup, not lazily"],"tags":["null-argument","browser-launch","configuration"],"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"}