{"record":{"id":"7e9364a71351b3c0","repo":"alibaba/spring-ai-alibaba","slug":"failed-to-create-item-hash","errorCode":null,"errorMessage":"Failed to create item hash","messagePattern":"Failed to create item hash","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"spring-ai-alibaba-graph-core/src/main/java/com/alibaba/cloud/ai/graph/store/stores/DatabaseStore.java","lineNumber":850,"sourceCode":"\n    /**\n     * Create a fixed-length hash for long business identifiers to keep unique indexes\n     * stable across different database dialects.\n     *\n     * @param itemId original business identifier\n     * @return sha256 hex string\n     */\n    private String createItemHash(String itemId) {\n        try {\n            MessageDigest digest = MessageDigest.getInstance(\"SHA-256\");\n            byte[] hash = digest.digest(itemId.getBytes(StandardCharsets.UTF_8));\n            StringBuilder sb = new StringBuilder(hash.length * 2);\n            for (byte b : hash) {\n                sb.append(String.format(\"%02x\", b));\n            }\n            return sb.toString();\n        } catch (Exception e) {\n            throw new RuntimeException(\"Failed to create item hash\", e);\n        }\n    }\n\n    /**\n     * Get all items from database.\n     *\n     * @return list of all items\n     */\n    private List<StoreItem> getAllItems() {\n        List<StoreItem> items = new ArrayList<>();\n        String sql = \"SELECT namespace, key_name, value_json, created_at, updated_at FROM \" + tableName;\n\n        try (Connection conn = dataSource.getConnection();\n             Statement stmt = conn.createStatement();\n             ResultSet rs = stmt.executeQuery(sql)) {\n\n            while (rs.next()) {\n                try {","sourceCodeStart":832,"sourceCodeEnd":868,"githubUrl":"https://github.com/alibaba/spring-ai-alibaba/blob/f82da0b50f35744c13968191be2b1cd2452ef550/spring-ai-alibaba-graph-core/src/main/java/com/alibaba/cloud/ai/graph/store/stores/DatabaseStore.java#L832-L868","documentation":"createItemHash() computes the SHA-256 hash of a namespace/key used as the unique id_hash column, and wraps ANY exception (including NoSuchAlgorithmException or serialization problems) in this RuntimeException. itemHash() calls it, so all item lookups/writes that hash keys can fail with this.","triggerScenarios":"Calling putItem/getItem/deleteItem when MessageDigest SHA-256 is unavailable in the JVM, or hashing input cannot be processed (e.g., unusual namespace serialization failure).","commonSituations":"Running on a restricted JDK without the SHA-256 algorithm (rare, e.g., stripped JRE or custom crypto policy); corrupted namespace objects causing serialization exceptions inside the hash routine.","solutions":["Inspect the chained cause to see whether it is NoSuchAlgorithmException or a serialization error.","Use a standard JDK 17 runtime with default JCE providers.","If serialization of namespace fails, ensure namespace components are JSON-serializable strings.","Fix the StoreItem data producing invalid hash input rather than catching around every call."],"exampleFix":"// before\nStoreItem item = store.getItem(List.of(nsObj), key); // nsObj not serializable\n// after\nStoreItem item = store.getItem(List.of(String.valueOf(nsObj)), key);","handlingStrategy":"validation","validationCode":"try {\n    java.security.MessageDigest.getInstance(\"SHA-256\");\n} catch (java.security.NoSuchAlgorithmException e) {\n    throw new IllegalStateException(\"SHA-256 unavailable - DatabaseStore cannot run on this JVM\");\n}","typeGuard":null,"tryCatchPattern":"try { store.getItem(ns, key); } catch (RuntimeException e) { if (e.getMessage().contains(\"item hash\")) log.error(\"hash failure: {}\", e.getCause()); throw e; }","preventionTips":["Use a standard JDK 17 distribution with default crypto providers","Avoid custom JCE security policies stripping SHA-256","Keep namespace components JSON-serializable strings","Log and inspect chained causes immediately"],"tags":["hashing","sha-256","runtime","store"],"backgroundTag":"internal-invariant-violation","analyzedSha":"f82da0b50f35744c13968191be2b1cd2452ef550","analyzedAt":"2026-09-09T15:32:42.421Z","contentChangedAt":"2026-09-09T15:32:42.421Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}