{"record":{"id":"727a5beb33a7d253","repo":"quarkusio/quarkus","slug":"cannot-cast-item-of-kind-kind-to-a-io-quarkus-727a5b","errorCode":null,"errorMessage":"Cannot cast <item> of kind <kind> to a io.quarkus.redis.datasource.graph.GraphQueryResponseItem$NodeItem","messagePattern":"Cannot cast <item> of kind <kind> to a io\\.quarkus\\.redis\\.datasource\\.graph\\.GraphQueryResponseItem\\$NodeItem","errorType":"exception","errorClass":"ClassCastException","httpStatus":null,"severity":"error","filePath":"extensions/redis-client/runtime/src/main/java/io/quarkus/redis/datasource/graph/GraphQueryResponseItem.java","lineNumber":28,"sourceCode":"        RELATION\n    }\n\n    Kind kind();\n\n    String name();\n\n    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();","sourceCodeStart":10,"sourceCodeEnd":46,"githubUrl":"https://github.com/quarkusio/quarkus/blob/e1c734241f34c7919086ceb4c9262b4a58f6de44/extensions/redis-client/runtime/src/main/java/io/quarkus/redis/datasource/graph/GraphQueryResponseItem.java#L10-L46","documentation":"GraphQueryResponseItem results are tagged with a Kind (SCALAR, NODE, RELATION). asNodeItem() throws a ClassCastException when invoked on an item that is not a NODE, guarding the unsafe downcast to NodeItem. Use kind() to determine the correct accessor before casting.","triggerScenarios":"Calling item.asNodeItem() on an item whose kind() is SCALAR or RELATION — e.g. iterating 'RETURN label, node' rows where the first column is a scalar label, or assuming a MATCH returns nodes when a projection actually returns properties.","commonSituations":"Query returns mixed node/scalar columns; Cypher query was refactored to RETURN n.property instead of n; loop treats all graph results as nodes.","solutions":["Check item.kind() == Kind.NODE before calling asNodeItem()","Dispatch on kind() to pick asScalarItem/asNodeItem/asRelationItem","Align the Cypher RETURN clause so the parsed column is actually a node","Wrap the call in try-catch for ClassCastException if shape cannot be predicted"],"exampleFix":"// before\nNodeItem n = row.get(0).asNodeItem();\n// after\nGraphQueryResponseItem item = row.get(0);\nNodeItem n = item instanceof GraphQueryResponseItem.NodeItem\n    ? item.asNodeItem()\n    : null; // handle non-node items explicitly","handlingStrategy":"type-guard","validationCode":"if (item.kind() != GraphQueryResponseItem.Kind.NODE) {\n    throw new IllegalStateException(\"Expected NODE but got \" + item.kind());\n}","typeGuard":"boolean isNode(GraphQueryResponseItem item) {\n    return item instanceof GraphQueryResponseItem.NodeItem;\n}","tryCatchPattern":"try {\n    NodeItem n = item.asNodeItem();\n} catch (ClassCastException e) {\n    // handle SCALAR/RELATION items instead\n}","preventionTips":["Use instanceof/kind() checks before downcasting graph items","Add unit tests covering the actual Cypher query result shape","Prefer pattern dispatch over chained blind casts when iterating rows"],"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"}