{"record":{"id":"5253aee0cfbfa09e","repo":"alibaba/spring-ai-alibaba","slug":"item-cannot-be-null","errorCode":null,"errorMessage":"item cannot be null","messagePattern":"item cannot be null","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"spring-ai-alibaba-graph-core/src/main/java/com/alibaba/cloud/ai/graph/store/stores/BaseStore.java","lineNumber":50,"sourceCode":" * Abstract base class for Store implementations providing common validation and utility\n * methods.\n * <p>\n * This class offers a foundation for implementing the Store interface with consistent\n * validation behavior and common helper methods.\n * </p>\n *\n * @author Spring AI Alibaba\n * @since 1.0.0.3\n */\npublic abstract class BaseStore implements Store {\n\n\t/**\n\t * Validates the putItem parameters.\n\t * @param item the item to validate\n\t */\n\tprotected void validatePutItem(StoreItem item) {\n\t\tif (item == null) {\n\t\t\tthrow new IllegalArgumentException(\"item cannot be null\");\n\t\t}\n\t\tif (item.getNamespace() == null) {\n\t\t\tthrow new IllegalArgumentException(\"namespace cannot be null\");\n\t\t}\n\t\tif (item.getKey() == null || item.getKey().trim().isEmpty()) {\n\t\t\tthrow new IllegalArgumentException(\"key cannot be null or empty\");\n\t\t}\n\t}\n\n\t/**\n\t * Validates the getItem parameters.\n\t * @param namespace namespace\n\t * @param key key\n\t */\n\tprotected void validateGetItem(List<String> namespace, String key) {\n\t\tif (namespace == null) {\n\t\t\tthrow new IllegalArgumentException(\"namespace cannot be null\");\n\t\t}","sourceCodeStart":32,"sourceCodeEnd":68,"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/BaseStore.java#L32-L68","documentation":"BaseStore.validatePutItem rejects a null StoreItem passed to putItem with IllegalArgumentException. The store API requires a fully populated item object; a null item cannot be persisted or validated field-by-field.","triggerScenarios":"Calling store.putItem(null) directly, or building the item in a conditional branch that never assigned it (e.g. Optional/nullable producer returned null).","commonSituations":"Factory method returning null when no data was available; map lookup for the item returning null; forgetting to construct the item after computing namespace/key.","solutions":["Construct a StoreItem before calling putItem","Null-check the item (or Objects.requireNonNull) before calling the store","Fix the producing code that returns null instead of an item"],"exampleFix":"// before\nStoreItem item = fetchItem(); // may return null\nstore.putItem(item);\n// after\nStoreItem item = fetchItem();\nif (item != null) {\n    store.putItem(item);\n}","handlingStrategy":"validation","validationCode":"if (item == null) { throw new IllegalArgumentException(\"item required before putItem\"); }","typeGuard":"boolean isPutable(StoreItem i) { return i != null && i.getNamespace() != null && i.getKey() != null && !i.getKey().isBlank(); }","tryCatchPattern":"try { store.putItem(item); } catch (IllegalArgumentException e) { log.warn(\"putItem rejected: {}\", e.getMessage()); }","preventionTips":["Never let factory/lookup methods return null items","Validate items at construction time with builder checks"],"tags":["java","store","null-check","argument-validation"],"backgroundTag":"null-argument","analyzedSha":"f82da0b50f35744c13968191be2b1cd2452ef550","analyzedAt":"2026-09-09T15:32:42.421Z","contentChangedAt":"2026-09-09T15:32:42.421Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}