quarkusio/quarkus · warning · ClassCastException

Cannot compare

Error message

Cannot compare 

What it means

QuarkusInternalAttribute.compareTo(InterfaceHttpData) implements Comparable by first checking the argument is a QuarkusInternalAttribute. If a different InterfaceHttpData implementation is passed, it throws ClassCastException, because attributes can only be ordered against other attributes. It is effectively a defensive type check rather than an unexpected JVM cast failure.

Source

Thrown at independent-projects/resteasy-reactive/client/runtime/src/main/java/org/jboss/resteasy/reactive/client/impl/multipart/QuarkusInternalAttribute.java:90

    @Override
    public int hashCode() {
        return getName().hashCode();
    }

    @Override
    public boolean equals(Object o) {
        if (!(o instanceof QuarkusInternalAttribute)) {
            return false;
        }
        QuarkusInternalAttribute attribute = (QuarkusInternalAttribute) o;
        return getName().equalsIgnoreCase(attribute.getName());
    }

    @Override
    public int compareTo(InterfaceHttpData o) {
        if (!(o instanceof QuarkusInternalAttribute)) {
            throw new ClassCastException("Cannot compare " + getHttpDataType() +
                    " with " + o.getHttpDataType());
        }
        return compareTo((QuarkusInternalAttribute) o);
    }

    public int compareTo(QuarkusInternalAttribute o) {
        return getName().compareToIgnoreCase(o.getName());
    }

    @Override
    public String toString() {
        StringBuilder result = new StringBuilder();
        for (ByteBuf elt : value) {
            result.append(elt.toString(charset));
        }
        return result.toString();
    }

View on GitHub (pinned to e1c734241f)

Solutions

  1. Sort/filter the collection so it contains only QuarkusInternalAttribute instances before comparing
  2. Use a Comparator that compares by getName() across different InterfaceHttpData types instead of relying on natural ordering
  3. Separate attributes and file uploads into distinct lists and sort each independently

Example fix

// before
Collections.sort(httpDataList); // mixes attributes and file uploads
// after
Collections.sort(httpDataList, Comparator.comparing(InterfaceHttpData::getName));
Defensive patterns

Strategy: type-guard

Validate before calling

if (!(data instanceof QuarkusInternalAttribute)) {
    // compare by name instead of natural ordering
    Comparator<InterfaceHttpData> byName = Comparator.comparing(InterfaceHttpData::getName, String.CASE_INSENSITIVE_ORDER);
}

Type guard

boolean isComparableAttribute(InterfaceHttpData d) {
    return d instanceof QuarkusInternalAttribute;
}

Try / catch

try {
    Collections.sort(httpDataList);
} catch (ClassCastException e) {
    httpDataList.sort(Comparator.comparing(InterfaceHttpData::getName, String.CASE_INSENSITIVE_ORDER));
}

Prevention

When it happens

Trigger: Sorting or comparing a collection of InterfaceHttpData where QuarkusInternalAttribute instances are mixed with other multipart data types (e.g. FileUpload implementations), causing compareTo to be called with a non-attribute object.

Common situations: Sorting a List<InterfaceHttpData> built from both form attributes and file uploads (e.g. Collections.sort before encoding a multipart body); generic utilities that compare InterfaceHttpData regardless of concrete type.

Related errors


AI-assisted analysis of quarkusio/quarkus@e1c734241f (2026-09-05). Data as JSON: /api/errors/f4e17bd0a0b10a61. Report an issue: GitHub.