{"record":{"id":"81d489239facee2a","repo":"jhy/jsoup","slug":"the-supplied-url-s-is-malformed-make-sure-it","errorCode":null,"errorMessage":"The supplied URL, '%s', is malformed. Make sure it is an absolute URL, and starts with 'http://' or 'https://'. See https://jsoup.org/cookbook/extracting-data/working-with-urls","messagePattern":"The supplied URL, '(.+?)', is malformed\\. Make sure it is an absolute URL, and starts with 'http://' or 'https://'\\. See https://jsoup\\.org/cookbook/extracting-data/working-with-urls","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/main/java/org/jsoup/helper/HttpConnection.java","lineNumber":154,"sourceCode":"    /** Create a new Connection that just wraps the provided Request and Response */\n    private HttpConnection(Request req, Response res) {\n        this.req = req;\n        this.res = res;\n    }\n\n    @Override\n    public Connection url(URL url) {\n        req.url(url);\n        return this;\n    }\n\n    @Override\n    public Connection url(String url) {\n        Validate.notEmptyParam(url, \"url\");\n        try {\n            req.url(new URL(url));\n        } catch (MalformedURLException e) {\n            throw new IllegalArgumentException(String.format(\"The supplied URL, '%s', is malformed. Make sure it is an absolute URL, and starts with 'http://' or 'https://'. See https://jsoup.org/cookbook/extracting-data/working-with-urls\", url), e);\n        }\n        return this;\n    }\n\n    @Override\n    public Connection proxy(@Nullable Proxy proxy) {\n        req.proxy(proxy);\n        return this;\n    }\n\n    @Override\n    public Connection proxy(String host, int port) {\n        req.proxy(host, port);\n        return this;\n    }\n\n    @Override\n    public Connection userAgent(String userAgent) {","sourceCodeStart":136,"sourceCodeEnd":172,"githubUrl":"https://github.com/jhy/jsoup/blob/9851ac5d9c576c6888910b5a51a2362bbc978959/src/main/java/org/jsoup/helper/HttpConnection.java#L136-L172","documentation":"Jsoup's HttpConnection.url(String) wraps java.net.MalformedURLException in an IllegalArgumentException with this message. The library requires an absolute http(s) URL to build its request; relative paths, missing schemes, or unknown protocols cannot be turned into a java.net.URL. This is a fail-fast input validation so the connection is never executed with an unusable URL.","triggerScenarios":"Calling Jsoup.connect(\"example.com\") (no scheme), Jsoup.connect(\"/relative/path\"), Jsoup.connect(\"ftp://host/file\"), or HttpConnection.url(String) with an empty-with-whitespace-but-nonempty string that URL parsing rejects.","commonSituations":"Hardcoding URLs without the http:// prefix; reading a link from config/user input that is relative; assuming JSoup resolves relative URLs like a browser; typos like 'http:/' or 'htp://'.","solutions":["Prefix the URL with https:// (or http://) so it is absolute","Validate the scheme before calling, e.g. url.startsWith(\"http://\")||url.startsWith(\"https://\")","Resolve relative URLs against a base: new URL(new URL(baseUrl), relative)","Use new URI(url).toURL() in a try/catch to pre-check parseability"],"exampleFix":"// before\nDocument doc = Jsoup.connect(\"example.com/news\").get();\n// after\nDocument doc = Jsoup.connect(\"https://example.com/news\").get();","handlingStrategy":"validation","validationCode":"if (url == null || !(url.startsWith(\"http://\") || url.startsWith(\"https://\"))) throw new IllegalArgumentException(\"Absolute http(s) URL required: \" + url);","typeGuard":"boolean isAbsoluteHttpUrl(String u) { try { String p = new URL(u).getProtocol(); return p.equals(\"http\") || p.equals(\"https\"); } catch (MalformedURLException e) { return false; } }","tryCatchPattern":"try { Document doc = Jsoup.connect(url).get(); } catch (IllegalArgumentException e) { /* malformed URL: log and skip/fix */ }","preventionTips":["Always store full absolute URLs in configuration","Normalize/resolve relative links against a base URL before connecting","Trim whitespace and strip stray characters from user-provided URLs"],"tags":["java","jsoup","url","input-validation"],"backgroundTag":"invalid-url-format","analyzedSha":"9851ac5d9c576c6888910b5a51a2362bbc978959","analyzedAt":"2026-09-08T15:22:04.931Z","contentChangedAt":"2026-09-08T15:22:04.931Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}