SonarSource/sonarqube · error · IllegalStateException
Fail to parse protobuf response of
Error message
Fail to parse protobuf response of
What it means
BaseService.convert() parses a web service response body as protobuf using the supplied parser. If parseFrom fails for any reason (malformed bytes, HTML error page instead of protobuf, truncated stream), it throws IllegalStateException("Fail to parse protobuf response of <url>") wrapping the original exception. The URL is included to identify which endpoint returned the unparseable body.
Source
Thrown at sonar-ws/src/main/java/org/sonarqube/ws/client/BaseService.java:64
return call(request, parser, MediaTypes.PROTOBUF);
}
protected <T extends Message> T call(BaseRequest request, Parser<T> parser, String mediaType) {
request.setMediaType(mediaType);
WsResponse response = call(request);
return convert(response, parser);
}
protected WsResponse call(WsRequest request) {
return wsConnector.call(request).failIfNotSuccessful();
}
public static <T extends Message> T convert(WsResponse response, Parser<T> parser) {
try (InputStream byteStream = response.contentStream()) {
// HTTP header "Content-Type" is not verified. It may be different than protobuf.
return parser.parseFrom(byteStream);
} catch (Exception e) {
throw new IllegalStateException("Fail to parse protobuf response of " + response.requestUrl(), e);
}
}
protected String path() {
return controller;
}
protected String path(String action) {
return String.format("%s/%s", controller, action);
}
@CheckForNull
protected static String inlineMultipleParamValue(@Nullable Collection<String> values) {
return values == null ? null : String.join(",", values);
}
}
View on GitHub (pinned to 184c821202)
Solutions
- Check the wrapped cause and fetch response.requestUrl() manually to see what the server actually returned.
- Verify no proxy/SSO gateway is intercepting the request and returning HTML (check auth/cookies).
- Align the sonar-ws client version with the SonarQube server version.
- Retry the call — transient truncation can also cause parse failures.
Example fix
// before
WsResponse response = wsConnector.call(request);
MyMessage msg = convert(response, MyMessage.parser());
// after
try (WsResponse response = wsConnector.call(request)) {
if (!"application/x-protobuf".contains(response.contentType())) {
throw new IllegalStateException("Unexpected content type from " + response.requestUrl());
}
MyMessage msg = convert(response, MyMessage.parser());
} Defensive patterns
Strategy: try-catch
Validate before calling
if (!"application/x-protobuf".equals(response.contentType())) {
throw new IllegalStateException("Endpoint returned non-protobuf content: " + response.requestUrl());
} Try / catch
try {
MyMessage msg = convert(response, MyMessage.parser());
} catch (IllegalStateException e) {
// cause holds the parse error; log response.requestUrl() and re-check auth/proxy
throw new RuntimeException("Non-protobuf body from " + response.requestUrl(), e);
} Prevention
- Pin sonar-ws client version to match the SonarQube server version.
- Ensure no SSO/proxy gateway intercepts the request and returns HTML.
- Verify the Content-Type header before parsing.
When it happens
Trigger: Calling a generated WS service method (e.g. call()) whose endpoint returned a body that is not valid protobuf for the expected message type — commonly a reverse proxy or auth gateway returning an HTML login/error page, or a server version mismatch changing the message schema.
Common situations: SonarQube behind SSO/LDAP proxy that intercepts requests and returns HTML; calling a newer/older SonarQube server than the client library expects; network middleware rewriting responses; hitting a REST endpoint instead of the protobuf api endpoint.
Understand the failure class
Background: "cannot parse invalid wire-format data", "cannot unmarshal", "failed unmarshalling": protobuf unmarshal errors explained — this error's family across 10 libraries.
Related errors
- Error while executing a call to %s. Return code %s. Error me
- SonarQube was not able to retrieve resources from external s
- generateErrorMessage(body)
- Response from Azure for request [%s] could not be parsed: [%
- Invalid Azure URL
AI-assisted analysis of SonarSource/sonarqube@184c821202 (2026-09-09).
Data as JSON: /api/errors/db892c39ac9ff97e.
Report an issue: GitHub.