alibaba/spring-ai-alibaba · error · IllegalArgumentException

URL路径不能为空

Error message

URL路径不能为空

What it means

KnowledgeRetrievalNodeSection.render throws this IllegalArgumentException during code generation when a knowledge-retrieval document's type is URL but its path is null or blank. The generator requires a concrete URL to embed as the document source in the generated workflow code.

Source

Thrown at spring-ai-alibaba-admin/spring-ai-alibaba-admin-server-start/src/main/java/com/alibaba/cloud/ai/studio/admin/builder/generator/service/generator/workflow/sections/KnowledgeRetrievalNodeSection.java:112

					String path = switch (documentType) {
						case FILE -> {
							{
								Path p = Path.of(studioStoragePath);
								Path resolvedPath = p.resolve(document.getPath()).normalize();

								// 安全检查:确保解析后的路径仍在允许的目录范围内
								if (!resolvedPath.startsWith(p.normalize())) {
									throw new SecurityException("非法路径访问尝试: " + document.getPath());
								}

								yield resolvedPath.toAbsolutePath().toString();
							}
						}
						case URL -> {
							// 对URL路径进行基本验证
							String urlPath = document.getPath();
							if (urlPath == null || urlPath.trim().isEmpty()) {
								throw new IllegalArgumentException("URL路径不能为空");
							}
							yield urlPath;
						}
						default ->
							throw new UnsupportedOperationException("unsupported document type: " + documentType);
					};
					String fileName = document.getName();
					// 构造文件记录
					return new ResourceFile(fileName, switch (documentType) {
						case FILE -> ResourceFile.Type.CLASS_PATH;
						case URL -> ResourceFile.Type.URL;
						default ->
							throw new UnsupportedOperationException("unsupported document type: " + documentType);
					}, () -> {
						try {
							return Files.newInputStream(Path.of(path));
						}
						catch (IOException e) {

View on GitHub (pinned to f82da0b50f)

Solutions

  1. Set a non-empty path (URL) on every URL-typed document in the knowledge-retrieval node data before generating code
  2. Validate the DSL node data before invoking generation and reject documents with blank paths
  3. Change the document type to FILE if it is actually a classpath resource, so the FILE branch is taken instead

Example fix

// before
document.setType("URL"); // path left null
// after
document.setType("URL");
document.setPath("https://example.com/doc.pdf");
Defensive patterns

Strategy: validation

Validate before calling

if (doc.getType() == DocumentType.URL && (doc.getPath() == null || doc.getPath().isBlank())) { throw new IllegalArgumentException("URL document requires a non-empty path: " + doc.getName()); }

Type guard

boolean hasUrlPath(DslDocument d) { return d.getType() == DocumentType.URL && d.getPath() != null && !d.getPath().trim().isEmpty(); }

Try / catch

try { section.render(node, varName); } catch (IllegalArgumentException e) { log.error("Invalid knowledge-retrieval document: {}", e.getMessage()); }

Prevention

When it happens

Trigger: A node of type KNOWLEDGE_RETRIEVAL in the DSL has a document whose documentType is URL and document.getPath() returns null or a whitespace-only string when render() is called.

Common situations: Importing a Dify/LangFlow DSL export where the URL field was never filled in; hand-edited DSL JSON with an empty "path"; API payloads created programmatically that omit path for URL-typed documents.

Understand the failure class

Background: "must not be empty", "cannot be empty" — required-field validation errors across open-source libraries — this error's family across 41 libraries.

Related errors


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