alibaba/spring-ai-alibaba · info
Unsupported charset ' ', falling back to UTF-8
Error message
Unsupported charset '{}', falling back to UTF-8 What it means
extractCharset found a charset name in the Content-Type header or HTML meta tag that Charset.forName does not recognize on this JVM; it logs the warning and returns empty, causing the tool to fall back to decoding the body as UTF-8.
Solutions
- Usually safe to ignore: content decodes as UTF-8; check output for mojibake.
- If decoding is wrong, pre-normalize the source page or serve it with a correct Content-Type header.
- Ensure the JVM has the full charsets module (java.base plus jdk.charsets) if exotic encodings are needed.
- Fix the upstream page's charset declaration if you control it.
Defensive patterns
Strategy: fallback
Validate before calling
try { Charset.forName(declared); } catch (Exception e) { /* declared charset unsupported; expect UTF-8 fallback */ } Prevention
- Serve pages with a correct, standard charset in Content-Type.
- Test scraping targets for mojibake after the UTF-8 fallback.
- Run on a JVM with the full charset provider if exotic encodings are expected.
When it happens
Trigger: A page declares a misspelled, non-standard, or platform-specific charset (e.g. 'utf8' variants, 'gb2312' aliases absent from the charset provider, garbage values) in its metadata.
Common situations: Scraping legacy Chinese/European sites declaring charsets like 'GB2312' or 'ISO-8859-1' aliases on restricted JVMs, pages with malformed meta tags, CDN-injected wrong headers.
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
- Content too long ( characters). Truncating to characters.
- 会话 不存在,创建新会话
- Failed to parse version number
- Fallback model failed
- Fetch attempt failed for URL
AI-assisted analysis of alibaba/spring-ai-alibaba@f82da0b50f (2026-09-09).
Data as JSON: /api/errors/e3000ff4fc82f7c3.
Report an issue: GitHub.
Appendix: source
Thrown at spring-ai-alibaba-agent-framework/src/main/java/com/alibaba/cloud/ai/graph/agent/tools/WebFetchTool.java:361
}
catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw new WebFetchException("Request was interrupted", e);
}
}
private Optional<Charset> extractCharset(HttpResponse<?> response) {
return response.headers()
.firstValue("Content-Type")
.flatMap(contentType -> {
Matcher matcher = CHARSET_PATTERN.matcher(contentType);
if (matcher.find()) {
String charsetName = matcher.group(1);
try {
return Optional.of(Charset.forName(charsetName));
}
catch (Exception e) {
logger.warn("Unsupported charset '{}', falling back to UTF-8", charsetName);
return Optional.empty();
}
}
return Optional.empty();
});
}
private String summarize(String content, String userQuery) {
try {
String response = this.chatClient.prompt()
.user(u -> u.text(FETCH_SUMMARIZE_PROMPT).param("content", content).param("userQuery", userQuery))
.call()
.content();
return response != null ? response : "Error: Received empty response from AI model";
}
catch (Exception e) {
logger.error("Failed to summarize content", e);
return "Error summarizing content: " + e.getMessage();View on GitHub (pinned to f82da0b50f)