{"record":{"id":"e071c964c8de45e5","repo":"apache/pulsar","slug":"no-message-malformed-data-url","errorCode":null,"errorMessage":"(no message; malformed data: URL)","messagePattern":"\\(no message; malformed data: URL\\)","errorType":"exception","errorClass":"MalformedURLException","httpStatus":null,"severity":"error","filePath":"pulsar-common/src/main/java/org/apache/pulsar/client/api/url/DataURLStreamHandler.java","lineNumber":85,"sourceCode":"            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            }\n            parsed = true;\n        }\n\n        @Override\n        public long getContentLengthLong() {\n            long length;\n            try {\n                this.connect();\n                length = this.data.length;\n            } catch (IOException e) {\n                length = -1;\n            }\n            return length;\n        }\n\n        @Override\n        public String getContentType() {","sourceCodeStart":67,"sourceCodeEnd":103,"githubUrl":"https://github.com/apache/pulsar/blob/820761864ed8e2a7d2e52dd9763ad2ae117c1395/pulsar-common/src/main/java/org/apache/pulsar/client/api/url/DataURLStreamHandler.java#L67-L103","documentation":"After connect() obtains the URI, it validates the scheme-specific part against a regex that captures optional mime type, base64 flag, and payload. If the data: URL does not match the expected grammar (e.g. missing comma separator, invalid base64, stray characters), it throws MalformedURLException.","triggerScenarios":"Calling getInputStream/getContentType/getContentLengthLong on a connection whose data: URI doesn't match pattern 'data:[<mediatype>][;base64],<data>' — missing comma, whitespace, unescaped characters, or invalid base64 payload.","commonSituations":"Hand-built data URLs missing the comma before payload; base64 payloads containing newlines/padding errors; URLs that were double-encoded or contain spaces; truncation when building the URL string.","solutions":["Validate the data URL format before use: must contain a ',' separating metadata from payload, e.g. data:text/plain;base64,SGVsbG8=.","If the payload is base64, ensure it is valid base64 (correct padding, no whitespace/newlines); otherwise use the plain (URL-encoded) form.","Catch MalformedURLException and log/inspect the full URI to spot the malformed part; fix or regenerate the URL string.","Percent-encode special characters in the data portion instead of embedding raw binary or spaces."],"exampleFix":"// before\nString bad = \"data:text/plain;base64\" + payload; // missing comma\nURL url = new URL(null, bad, new DataURLStreamHandler());\n// after\nString good = \"data:text/plain;base64,\" + Base64.getEncoder().encodeToString(bytes);\nURL url = new URL(null, good, new DataURLStreamHandler());","handlingStrategy":"validation","validationCode":"int comma = urlString.indexOf(',');\nif (!urlString.startsWith(\"data:\") || comma < 5) {\n    throw new IllegalArgumentException(\"malformed data URL, missing metadata/payload comma: \" + urlString);\n}","typeGuard":null,"tryCatchPattern":"try {\n    URLConnection c = dataUrl.openConnection(); c.connect();\n} catch (MalformedURLException e) {\n    // data URL didn't match grammar; inspect and rebuild the URL\n}","preventionTips":["Always include the comma separator between metadata and payload.","Ensure base64 payloads are valid (padding, no whitespace/newlines).","Percent-encode special characters instead of embedding raw bytes or spaces."],"tags":["url","data-url","malformed-input","base64"],"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"}