{"record":{"id":"e4234427f7ea81c4","repo":"quarkusio/quarkus","slug":"cannot-compare","errorCode":null,"errorMessage":"Cannot compare ","messagePattern":"Cannot compare ","errorType":"exception","errorClass":"ClassCastException","httpStatus":null,"severity":"error","filePath":"independent-projects/resteasy-reactive/client/runtime/src/main/java/org/jboss/resteasy/reactive/client/impl/multipart/MultiByteHttpData.java","lineNumber":301,"sourceCode":"    public FileUpload touch(Object hint) {\n        buffer.touch(hint);\n        return this;\n    }\n\n    @Override\n    public int hashCode() {\n        return System.identityHashCode(this);\n    }\n\n    @Override\n    public boolean equals(Object o) {\n        return System.identityHashCode(this) == System.identityHashCode(o);\n    }\n\n    @Override\n    public int compareTo(InterfaceHttpData o) {\n        if (!(o instanceof MultiByteHttpData)) {\n            throw new ClassCastException(\"Cannot compare \" + getHttpDataType() +\n                    \" with \" + o.getHttpDataType());\n        }\n        return compareTo((MultiByteHttpData) o);\n    }\n\n    public int compareTo(MultiByteHttpData o) {\n        return Integer.compare(System.identityHashCode(this), System.identityHashCode(o));\n    }\n\n    @Override\n    public HttpDataType getHttpDataType() {\n        return HttpDataType.FileUpload;\n    }\n\n    @Override\n    public String getFilename() {\n        return filename;\n    }","sourceCodeStart":283,"sourceCodeEnd":319,"githubUrl":"https://github.com/quarkusio/quarkus/blob/e1c734241f34c7919086ceb4c9262b4a58f6de44/independent-projects/resteasy-reactive/client/runtime/src/main/java/org/jboss/resteasy/reactive/client/impl/multipart/MultiByteHttpData.java#L283-L319","documentation":"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.","triggerScenarios":"Sorting or comparing multipart HttpData collections that mix MultiByteHttpData with other InterfaceHttpData types (e.g. MemoryFileUpload, attributes).","commonSituations":"Using TreeSet/TreeMap or Collections.sort on multipart parts; Netty's internal HttpData ordering when a request mixes plain and multi-byte parts.","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"],"exampleFix":"// before\nparts.sort(Comparator.naturalOrder());\n// after\nparts.sort(Comparator.comparing(InterfaceHttpData::getName));","handlingStrategy":"type-guard","validationCode":"if (!(a instanceof MultiByteHttpData) || !(b instanceof MultiByteHttpData)) { /* use name-based comparator */ }","typeGuard":"boolean bothMultiByte(InterfaceHttpData a, InterfaceHttpData b) { return a instanceof MultiByteHttpData && b instanceof MultiByteHttpData; }","tryCatchPattern":"try { return data.compareTo(other); } catch (ClassCastException e) { return data.getName().compareTo(other.getName()); }","preventionTips":["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"],"tags":["netty","multipart","classcastexception","resteasy-reactive"],"backgroundTag":"classcast-exception","analyzedSha":"e1c734241f34c7919086ceb4c9262b4a58f6de44","analyzedAt":"2026-09-05T17:01:29.979Z","contentChangedAt":"2026-09-05T17:01:29.979Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}