{"record":{"id":"99ed50c3ae5b4115","repo":"quarkusio/quarkus","slug":"cannot-cast-item-of-kind-kind-to-a-io-quarkus-99ed50","errorCode":null,"errorMessage":"Cannot cast <item> of kind <kind> to a io.quarkus.redis.datasource.graph.GraphQueryResponseItem$RelationItem","messagePattern":"Cannot cast <item> of kind <kind> to a io\\.quarkus\\.redis\\.datasource\\.graph\\.GraphQueryResponseItem\\$RelationItem","errorType":"exception","errorClass":"ClassCastException","httpStatus":null,"severity":"error","filePath":"extensions/redis-client/runtime/src/main/java/io/quarkus/redis/datasource/graph/GraphQueryResponseItem.java","lineNumber":35,"sourceCode":"    default ScalarItem asScalarItem() {\n        if (this instanceof ScalarItem) {\n            return (ScalarItem) this;\n        }\n        throw new ClassCastException(\"Cannot cast \" + this + \" of kind \" + kind() + \" to a \" + ScalarItem.class.getName());\n    }\n\n    default NodeItem asNodeItem() {\n        if (this instanceof NodeItem) {\n            return (NodeItem) this;\n        }\n        throw new ClassCastException(\"Cannot cast \" + this + \" of kind \" + kind() + \" to a \" + NodeItem.class.getName());\n    }\n\n    default RelationItem asRelationItem() {\n        if (this instanceof RelationItem) {\n            return (RelationItem) this;\n        }\n        throw new ClassCastException(\"Cannot cast \" + this + \" of kind \" + kind() + \" to a \" + RelationItem.class.getName());\n    }\n\n    interface ScalarItem extends GraphQueryResponseItem {\n\n        boolean asBoolean();\n\n        int asInteger();\n\n        double asDouble();\n\n        boolean isNull();\n\n        String asString();\n\n        @Override\n        default Kind kind() {\n            return Kind.SCALAR;\n        }","sourceCodeStart":17,"sourceCodeEnd":53,"githubUrl":"https://github.com/quarkusio/quarkus/blob/e1c734241f34c7919086ceb4c9262b4a58f6de44/extensions/redis-client/runtime/src/main/java/io/quarkus/redis/datasource/graph/GraphQueryResponseItem.java#L17-L53","documentation":"GraphQueryResponseItem results can be SCALAR, NODE, or RELATION. asRelationItem() throws a ClassCastException when called on an item that is not a RELATION (edge), preventing an invalid downcast to RelationItem. Inspect kind() first to select the right accessor.","triggerScenarios":"Calling item.asRelationItem() on an item whose kind() is SCALAR or NODE — common when a Cypher query like 'MATCH (a)-[r]->(b) RETURN a, b' returns only nodes and the code assumes an edge column exists.","commonSituations":"Traversing relationship results but the RETURN clause omits the relationship variable; querying paths that project nodes and scalars only; copy-pasted iteration code that casts everything as relations.","solutions":["Check item.kind() == Kind.RELATION before calling asRelationItem()","Dispatch on kind() across SCALAR/NODE/RELATION and handle each branch","Update the Cypher query to RETURN the relationship (e.g. r) so the column holds relations","Guard with instanceof RelationItem or try-catch on ClassCastException"],"exampleFix":"// before\nRelationItem r = row.get(1).asRelationItem();\n// after\nGraphQueryResponseItem item = row.get(1);\nif (item.kind() == GraphQueryResponseItem.Kind.RELATION) {\n    RelationItem r = item.asRelationItem();\n} else {\n    // skip or log non-relation column\n}","handlingStrategy":"type-guard","validationCode":"if (item.kind() != GraphQueryResponseItem.Kind.RELATION) {\n    throw new IllegalStateException(\"Expected RELATION but got \" + item.kind());\n}","typeGuard":"boolean isRelation(GraphQueryResponseItem item) {\n    return item instanceof GraphQueryResponseItem.RelationItem;\n}","tryCatchPattern":"try {\n    RelationItem r = item.asRelationItem();\n} catch (ClassCastException e) {\n    // handle SCALAR/NODE items instead\n}","preventionTips":["Verify the Cypher query actually returns relationships before casting","Check kind() == Kind.RELATION as the standard guard","Encapsulate row parsing in a typed mapper that handles all three kinds"],"tags":["classcast","redis","graph","type-mismatch"],"backgroundTag":"class-cast-mismatch","analyzedSha":"e1c734241f34c7919086ceb4c9262b4a58f6de44","analyzedAt":"2026-09-05T17:01:29.979Z","contentChangedAt":"2026-09-05T17:01:29.979Z","schemaVersion":2},"datasetVersion":"2026-09-12T22:17:10.623Z"}