{"record":{"id":"777b48f5b590c4b8","repo":"karatelabs/karate","slug":"uri-cannot-be-null","errorCode":null,"errorMessage":"URI cannot be null","messagePattern":"URI cannot be null","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"karate-core/src/main/java/io/karatelabs/http/WsClientOptions.java","lineNumber":170,"sourceCode":"    public static class Builder {\n\n        private final URI uri;\n        private Map<String, String> headers;\n        private String subProtocol;\n        private boolean compression = false;\n        private int maxPayloadSize = HttpUtils.MEGABYTE;\n        private Duration connectTimeout = Duration.ofSeconds(30);\n        private Duration pingInterval = Duration.ofSeconds(30);\n        private boolean trustAllCerts = true;\n        private SslContext sslContext;\n        private ExecutorService callbackExecutor;\n        private Consumer<WsFrame> messageListener;\n        private Runnable closeListener;\n        private Consumer<Throwable> errorListener;\n\n        private Builder(URI uri) {\n            if (uri == null) {\n                throw new IllegalArgumentException(\"URI cannot be null\");\n            }\n            this.uri = uri;\n        }\n\n        public Builder headers(Map<String, String> headers) {\n            this.headers = headers;\n            return this;\n        }\n\n        public Builder header(String name, String value) {\n            if (this.headers == null) {\n                this.headers = new LinkedHashMap<>();\n            }\n            this.headers.put(name, value);\n            return this;\n        }\n\n        /** The WebSocket subprotocol to negotiate during the handshake (Sec-WebSocket-Protocol). */","sourceCodeStart":152,"sourceCodeEnd":188,"githubUrl":"https://github.com/karatelabs/karate/blob/a22eb90246d958d15a47bf436693d0121ad2812d/karate-core/src/main/java/io/karatelabs/http/WsClientOptions.java#L152-L188","documentation":"WsClientOptions.Builder's constructor validates its URI argument and throws IllegalArgumentException when null is passed. The builder cannot construct meaningful WebSocket client options without a target URI, so it fails fast at builder-creation time rather than at connect time.","triggerScenarios":"Calling WsClientOptions.builder(null), or passing a variable/expression that resolved to null (e.g. missing config value) into the builder.","commonSituations":"Reading the ws URL from config/env and getting null because the key is missing; conditional logic that skips URL assignment; refactoring that changed a method to return null on failure.","solutions":["Pass a non-null URI, e.g. URI.create(\"ws://host:port/path\")","Validate/parse the URL from config before building options and fail with a clear config error","Use Objects.requireNonNull(uri, \"...\") at your own call site to surface which config key was missing"],"exampleFix":"// before\nString url = config.get(\"ws.url\"); // null\nWsClientOptions.builder(URI.create(url));\n// after\nString url = Objects.requireNonNull(config.get(\"ws.url\"), \"ws.url not configured\");\nWsClientOptions.builder(URI.create(url));","handlingStrategy":"validation","validationCode":"if (uri == null) throw new IllegalArgumentException(\"ws uri not configured\");","typeGuard":"boolean ok = uri != null && (\"ws\".equals(uri.getScheme()) || \"wss\".equals(uri.getScheme()));","tryCatchPattern":"try { WsClientOptions.builder(uri); } catch (IllegalArgumentException e) { throw new ConfigException(\"invalid websocket uri: \" + e.getMessage(), e); }","preventionTips":["Validate config-supplied ws URLs before constructing the builder","Use URI.create() early so malformed URLs fail with a clear message","Apply Objects.requireNonNull with a key name for config lookups"],"tags":["null-argument","websocket","config","validation"],"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"}