alibaba/spring-ai-alibaba · error · IllegalArgumentException

searchRequest cannot be null

Error message

searchRequest cannot be null

What it means

BaseStore.validateSearchItems requires a non-null StoreSearchRequest. Search parameters (query, limit, filters) are carried in this request object; passing null leaves the search undefined, so the library throws IllegalArgumentException before executing any query.

Source

Thrown at spring-ai-alibaba-graph-core/src/main/java/com/alibaba/cloud/ai/graph/store/stores/BaseStore.java:100

	protected void validateDeleteItem(List<String> namespace, String key) {
		if (namespace == null) {
			throw new IllegalArgumentException("namespace cannot be null");
		}
		if (key == null) {
			throw new IllegalArgumentException("key cannot be null");
		}
		if (key.trim().isEmpty()) {
			throw new IllegalArgumentException("key cannot be empty");
		}
	}

	/**
	 * Validates the searchItems parameters.
	 * @param searchRequest search request
	 */
	protected void validateSearchItems(StoreSearchRequest searchRequest) {
		if (searchRequest == null) {
			throw new IllegalArgumentException("searchRequest cannot be null");
		}
	}

	/**
	 * Validates the listNamespaces parameters.
	 * @param namespaceRequest namespace request
	 */
	protected void validateListNamespaces(NamespaceListRequest namespaceRequest) {
		if (namespaceRequest == null) {
			throw new IllegalArgumentException("namespaceRequest cannot be null");
		}
	}

	/**
	 * Create store key from namespace and key Uses safe encoding to avoid conflicts from
	 * special characters.
	 * @param namespace namespace
	 * @param key key

View on GitHub (pinned to f82da0b50f)

Solutions

  1. Always construct a StoreSearchRequest, even for unrestricted searches (empty query/default limit).
  2. Null-check or use Objects.requireNonNullElse(request, defaultRequest) before calling searchItems.
  3. Catch IllegalArgumentException if the request comes from an optional input and substitute a default.

Example fix

// before
var results = store.searchItems(maybeRequest);
// after
StoreSearchRequest req = maybeRequest != null ? maybeRequest
        : StoreSearchRequest.builder().limit(10).build();
var results = store.searchItems(req);
Defensive patterns

Strategy: validation

Validate before calling

if (request == null) {
    request = StoreSearchRequest.builder().limit(10).build();
}
store.searchItems(request);

Type guard

StoreSearchRequest orDefault(StoreSearchRequest r) { return r != null ? r : StoreSearchRequest.builder().limit(10).build(); }

Try / catch

try {
    store.searchItems(request);
} catch (IllegalArgumentException e) {
    store.searchItems(StoreSearchRequest.builder().limit(10).build());
}

Prevention

When it happens

Trigger: Calling store.searchItems(null) directly, or passing a request variable that failed to build (e.g. optional request object left uninitialized).

Common situations: Conditional request construction where the build method returns null on some code path; reflective/deserialized controllers binding null bodies; tests passing null expecting defaults.

Related errors


AI-assisted analysis of alibaba/spring-ai-alibaba@f82da0b50f (2026-09-09). Data as JSON: /api/errors/10ca73441e58480e. Report an issue: GitHub.