quarkusio/quarkus · error · ClassCastException
Cannot compare
Error message
Cannot compare
What it means
MultiByteHttpData.compareTo(InterfaceHttpData) requires the other object to also be a MultiByteHttpData; otherwise it throws ClassCastException. This mirrors Netty's ordering contract where mixed data types cannot be meaningfully ordered.
Source
Thrown at independent-projects/resteasy-reactive/client/runtime/src/main/java/org/jboss/resteasy/reactive/client/impl/multipart/MultiByteHttpData.java:301
public FileUpload touch(Object hint) {
buffer.touch(hint);
return this;
}
@Override
public int hashCode() {
return System.identityHashCode(this);
}
@Override
public boolean equals(Object o) {
return System.identityHashCode(this) == System.identityHashCode(o);
}
@Override
public int compareTo(InterfaceHttpData o) {
if (!(o instanceof MultiByteHttpData)) {
throw new ClassCastException("Cannot compare " + getHttpDataType() +
" with " + o.getHttpDataType());
}
return compareTo((MultiByteHttpData) o);
}
public int compareTo(MultiByteHttpData o) {
return Integer.compare(System.identityHashCode(this), System.identityHashCode(o));
}
@Override
public HttpDataType getHttpDataType() {
return HttpDataType.FileUpload;
}
@Override
public String getFilename() {
return filename;
}View on GitHub (pinned to e1c734241f)
Solutions
- Ensure compared parts are all MultiByteHttpData, or implement a Comparator that falls back to comparing by name/type
- Use IdentityHashMap or a list instead of sorted collections for mixed parts
- Catch ClassCastException and fall back to name-based comparison
Example fix
// before parts.sort(Comparator.naturalOrder()); // after parts.sort(Comparator.comparing(InterfaceHttpData::getName));
Defensive patterns
Strategy: type-guard
Validate before calling
if (!(a instanceof MultiByteHttpData) || !(b instanceof MultiByteHttpData)) { /* use name-based comparator */ } Type guard
boolean bothMultiByte(InterfaceHttpData a, InterfaceHttpData b) { return a instanceof MultiByteHttpData && b instanceof MultiByteHttpData; } Try / catch
try { return data.compareTo(other); } catch (ClassCastException e) { return data.getName().compareTo(other.getName()); } Prevention
- Never sort collections mixing different InterfaceHttpData types
- Always supply an explicit Comparator for mixed part lists
- Prefer HashMap/ArrayList over TreeMap/TreeSet for multipart parts
When it happens
Trigger: Sorting or comparing multipart HttpData collections that mix MultiByteHttpData with other InterfaceHttpData types (e.g. MemoryFileUpload, attributes).
Common situations: Using TreeSet/TreeMap or Collections.sort on multipart parts; Netty's internal HttpData ordering when a request mixes plain and multi-byte parts.
Related errors
- setting content of MultiByteHttpData is not supported
- adding content to MultiByteHttpData is not supported
- getting all the contents of a MultiByteHttpData is not suppo
- Reading MultiByteHttpData as String is not supported
- Renaming destination file for MultiByteHttpData is not suppo
AI-assisted analysis of quarkusio/quarkus@e1c734241f (2026-09-05).
Data as JSON: /api/errors/e4234427f7ea81c4.
Report an issue: GitHub.