{"record":{"id":"a6155ace219af7af","repo":"apache/pulsar","slug":"no-message-uri-missing-for-data-url-connection","errorCode":null,"errorMessage":"(no message; URI missing for data: URL connection)","messagePattern":"\\(no message; URI missing for data: URL connection\\)","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"pulsar-common/src/main/java/org/apache/pulsar/client/api/url/DataURLStreamHandler.java","lineNumber":68,"sourceCode":"              \"(?<mimeType>[^;,]+)?(;(?<charset>charset=[^;,]+))?(;(?<base64>base64))?,(?<data>.+)\", Pattern.DOTALL);\n\n        protected DataURLConnection(URL url) {\n            super(url);\n            try {\n                this.uri = this.url.toURI();\n            } catch (URISyntaxException e) {\n                this.uri = null;\n            }\n        }\n\n        @Override\n        public void connect() throws IOException {\n            if (this.parsed) {\n                return;\n            }\n\n            if (this.uri == null) {\n                throw new IOException();\n            }\n\n            Matcher matcher = pattern.matcher(this.uri.getSchemeSpecificPart());\n            if (matcher.matches()) {\n                this.contentType = matcher.group(\"mimeType\");\n                if (contentType == null) {\n                    this.contentType = \"application/data\";\n                }\n\n                if (matcher.group(\"base64\") == null) {\n                    // Support Urlencode but not decode here because already decoded by URI class.\n                    this.data = matcher.group(\"data\").getBytes(StandardCharsets.UTF_8);\n                } else {\n                    this.data = Base64.getDecoder().decode(matcher.group(\"data\"));\n                }\n            } else {\n                throw new MalformedURLException();\n            }","sourceCodeStart":50,"sourceCodeEnd":86,"githubUrl":"https://github.com/apache/pulsar/blob/820761864ed8e2a7d2e52dd9763ad2ae117c1395/pulsar-common/src/main/java/org/apache/pulsar/client/api/url/DataURLStreamHandler.java#L50-L86","documentation":"DataURLStreamHandler's connection lazily parses the data: URL on connect(). If the connection was created without a URI (no URL was actually supplied), it throws a bare IOException with no message. Callers like getInputStream, getContentType, and getContentLengthLong all funnel through connect().","triggerScenarios":"Invoking openConnection/openStream/getContent on a data: URLStreamHandler where URL.getURL's URI is null — typically constructing the URL without a valid context or with an empty/unsupported spec so URI resolution fails.","commonSituations":"Programmatically constructing a URL with new URL(null, spec, new DataURLStreamHandler()) where the spec cannot be converted to a URI; framework code passing an unset/empty data payload; URL encoding issues that break URI parsing.","solutions":["Verify the URL string is a well-formed data: URL (data:[<mime>[;base64]],<data>) before opening the connection.","Construct the URL from a proper spec string so URI resolution succeeds, e.g. new URL(\"data:text/plain;base64,SGVsbG8=\").","If building the handler manually, ensure the URL passed to openConnection actually carries a URI; catch the IOException and log the source URL for diagnosis."],"exampleFix":"// before\nURL url = new URL(null, someUnvalidatedString, new DataURLStreamHandler());\nurl.openStream();\n// after\nif (someUnvalidatedString == null || !someUnvalidatedString.startsWith(\"data:\")) {\n    throw new IllegalArgumentException(\"not a data URL: \" + someUnvalidatedString);\n}\nURL url = new URI(someUnvalidatedString).toURL(); // ensures URI is resolvable","handlingStrategy":"validation","validationCode":"if (urlString == null || !urlString.startsWith(\"data:\")) {\n    throw new IllegalArgumentException(\"expected a data: URL, got: \" + urlString);\n}","typeGuard":null,"tryCatchPattern":"try (InputStream in = dataUrl.openStream()) {\n    // read\n} catch (IOException e) {\n    // empty message means URI was missing; log the URL string used\n}","preventionTips":["Always build data: URLs from a full, well-formed spec string so URI resolution succeeds.","Validate the data: prefix and payload before opening a connection.","Prefer new URI(spec).toURL() over manual URL(handler) construction."],"tags":["url","data-url","io","malformed-input"],"backgroundTag":"malformed-data-url","analyzedSha":"820761864ed8e2a7d2e52dd9763ad2ae117c1395","analyzedAt":"2026-09-06T00:14:20.138Z","contentChangedAt":"2026-09-06T00:14:20.138Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}