apache/pulsar · error · IOException
(no message; URI missing for data: URL connection)
Error message
(no message; URI missing for data: URL connection)
What it means
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().
Source
Thrown at pulsar-common/src/main/java/org/apache/pulsar/client/api/url/DataURLStreamHandler.java:68
"(?<mimeType>[^;,]+)?(;(?<charset>charset=[^;,]+))?(;(?<base64>base64))?,(?<data>.+)", Pattern.DOTALL);
protected DataURLConnection(URL url) {
super(url);
try {
this.uri = this.url.toURI();
} catch (URISyntaxException e) {
this.uri = null;
}
}
@Override
public void connect() throws IOException {
if (this.parsed) {
return;
}
if (this.uri == null) {
throw new IOException();
}
Matcher matcher = pattern.matcher(this.uri.getSchemeSpecificPart());
if (matcher.matches()) {
this.contentType = matcher.group("mimeType");
if (contentType == null) {
this.contentType = "application/data";
}
if (matcher.group("base64") == null) {
// Support Urlencode but not decode here because already decoded by URI class.
this.data = matcher.group("data").getBytes(StandardCharsets.UTF_8);
} else {
this.data = Base64.getDecoder().decode(matcher.group("data"));
}
} else {
throw new MalformedURLException();
}View on GitHub (pinned to 820761864e)
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.
Example fix
// before
URL url = new URL(null, someUnvalidatedString, new DataURLStreamHandler());
url.openStream();
// after
if (someUnvalidatedString == null || !someUnvalidatedString.startsWith("data:")) {
throw new IllegalArgumentException("not a data URL: " + someUnvalidatedString);
}
URL url = new URI(someUnvalidatedString).toURL(); // ensures URI is resolvable Defensive patterns
Strategy: validation
Validate before calling
if (urlString == null || !urlString.startsWith("data:")) {
throw new IllegalArgumentException("expected a data: URL, got: " + urlString);
} Try / catch
try (InputStream in = dataUrl.openStream()) {
// read
} catch (IOException e) {
// empty message means URI was missing; log the URL string used
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- (no message; malformed data: URL)
- Cursor %s mark-delete position %s is ahead of the last posit
- Timeout during reset cursor
- Timeout during mark-delete operation
- Could not open configuration file
AI-assisted analysis of apache/pulsar@820761864e (2026-09-06).
Data as JSON: /api/errors/a6155ace219af7af.
Report an issue: GitHub.