SonarSource/sonarqube · error · IllegalStateException
Can not parse message
Error message
Can not parse message
What it means
Protobuf2.parseFrom wraps InvalidProtocolBufferException into an IllegalStateException with message "Can not parse message". It means the bytes in the input stream are not a valid protobuf message for the expected parser/type.
Source
Thrown at server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/util/Protobuf2.java:59
throw new IllegalStateException("Can not write message " + msg, e);
}
return this;
}
public Protobuf2 writeDelimitedTo(Message msg, OutputStream output) {
try {
msg.writeDelimitedTo(output);
} catch (IOException e) {
throw new IllegalStateException("Can not write message " + msg, e);
}
return this;
}
public <M extends Message> M parseFrom(Parser<M> parser, InputStream input) {
try {
return parser.parseFrom(input);
} catch (InvalidProtocolBufferException e) {
throw new IllegalStateException("Can not parse message", e);
}
}
@CheckForNull
public <M extends Message> M parseDelimitedFrom(Parser<M> parser, InputStream input) {
try {
return parser.parseDelimitedFrom(input);
} catch (InvalidProtocolBufferException e) {
throw new IllegalStateException("Can not parse message", e);
}
}
}
View on GitHub (pinned to 184c821202)
Solutions
- Verify the data was written by a compatible protobuf schema version
- Check the stream is not truncated or empty before parsing
- Regenerate or re-fetch the corrupted data
- Confirm the parser matches the message type that was serialized
Example fix
// before
MyMessage msg = protobuf2.parseFrom(MyMessage.parser(), input);
// after
if (input.available() == 0) {
throw new IllegalStateException("Empty input, nothing to parse");
}
MyMessage msg = protobuf2.parseFrom(MyMessage.parser(), input); Defensive patterns
Strategy: try-catch
Validate before calling
byte[] data = input.readAllBytes();
if (data.length == 0) {
throw new IllegalArgumentException("No data to parse");
}
input = new ByteArrayInputStream(data); Try / catch
try {
MyMessage msg = protobuf2.parseFrom(MyMessage.parser(), input);
} catch (IllegalStateException e) {
LOGGER.warn("Corrupt or incompatible protobuf data", e.getCause());
// discard record or fail with clear user-facing message
} Prevention
- Pin compatible protobuf schema versions between writer and reader
- Validate checksums on stored protobuf files
- Never parse streams of unknown/non-protobuf content
- Handle empty inputs before parsing
When it happens
Trigger: Calling parseFrom(parser, input) when the stream contains truncated, corrupted, empty, or wrong-type protobuf bytes.
Common situations: Version mismatch between writer and reader of the data (schema changed); corrupted files on disk; reading a non-protobuf file; truncated transfer.
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
- Fail to read locations from DB for issue %s
- Fail to read message formattings from DB for issue %s
- Can not read file
- Can not write message ${msg}
- Error while deserializing GraphQL payload: %s. %s
AI-assisted analysis of SonarSource/sonarqube@184c821202 (2026-09-09).
Data as JSON: /api/errors/894318e4c6815108.
Report an issue: GitHub.