alibaba/spring-ai-alibaba · error · IllegalArgumentException
maxContentLength must be positive
Error message
maxContentLength must be positive
What it means
Builder.maxContentLength validates that the configured truncation limit for fetched content is strictly positive; zero or negative values throw IllegalArgumentException. This guards against nonsensical limits that would truncate all content.
Source
Thrown at spring-ai-alibaba-agent-framework/src/main/java/com/alibaba/cloud/ai/graph/agent/tools/WebFetchTool.java:433
private int maxCacheSize = 100;
private int maxRetries = 2;
private String name = "web_fetch";
private String description = DEFAULT_TOOL_DESCRIPTION;
private Builder(ChatClient chatClient) {
if (chatClient == null) {
throw new IllegalArgumentException("ChatClient must not be null");
}
this.chatClient = chatClient;
}
public Builder maxContentLength(int maxContentLength) {
if (maxContentLength <= 0) {
throw new IllegalArgumentException("maxContentLength must be positive");
}
this.maxContentLength = maxContentLength;
return this;
}
public Builder maxCacheSize(int maxCacheSize) {
if (maxCacheSize <= 0) {
throw new IllegalArgumentException("maxCacheSize must be positive");
}
this.maxCacheSize = maxCacheSize;
return this;
}
public Builder maxRetries(int maxRetries) {
if (maxRetries < 0) {
throw new IllegalArgumentException("maxRetries must be non-negative");
}
this.maxRetries = maxRetries;View on GitHub (pinned to f82da0b50f)
Solutions
- Pass a positive integer, e.g. .maxContentLength(100_000).
- If loading from configuration, validate the property > 0 before building.
- Omit the call to keep the library default.
- Clamp with Math.max(1, configuredValue) if the value is dynamic.
Example fix
// before .maxContentLength(0) // after .maxContentLength(200_000)
Defensive patterns
Strategy: validation
Validate before calling
int limit = properties.maxContentLength();
if (limit <= 0) {
throw new IllegalArgumentException("webfetch.max-content-length must be > 0, got " + limit);
} Type guard
boolean isValidSize(int v) { return v > 0; } Try / catch
try {
builder.maxContentLength(limit);
} catch (IllegalArgumentException e) {
log.warn("invalid maxContentLength {}, using default", limit);
builder.maxContentLength(DEFAULT_CONTENT_LENGTH);
} Prevention
- Validate configuration properties before passing them to builders
- Give config defaults in application.yml so values are never 0 by omission
- Unit-test builder configuration with your real property values
When it happens
Trigger: Calling .maxContentLength(0) or a negative value on the WebFetchTool Builder.
Common situations: Copy-paste config where the value comes from properties that default to 0; typo like maxContentLength(-1); computing the limit from an empty/unparsed config value.
Understand the failure class
Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.
Related errors
- At least one fallback model must be specified
- maxAttempts must be greater than or equal to 1
- initialDelay must be greater than or equal to 0.
- maxCachedThreads must be greater than or equal to 0
- '%s' cannot be blank
AI-assisted analysis of alibaba/spring-ai-alibaba@f82da0b50f (2026-09-09).
Data as JSON: /api/errors/4f6f6dc336ff4549.
Report an issue: GitHub.