alibaba/spring-ai-alibaba · error · NullPointerException

Template string is null

Error message

Template string is null

What it means

Thrown by AbstractNodeDataConverter.varTemplateToSelector when the template string passed is null. A null variable template cannot be parsed into a VariableSelector, so the method fails fast with an NPE rather than returning a broken selector.

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/dsl/AbstractNodeDataConverter.java:88

	 * dialects.
	 */
	public interface DialectConverter<T> {

		Boolean supportDialect(DSLDialectType dialectType);

		T parse(Map<String, Object> data) throws JsonProcessingException;

		Map<String, Object> dump(T nodeData);

		/**
		 * 将模板字符串转换为变量选择器
		 * @param dialectType dsl语言
		 * @param template 模板字符串
		 * @return 变量选择器
		 */
		default VariableSelector varTemplateToSelector(DSLDialectType dialectType, String template) {
			if (template == null) {
				throw new NullPointerException("Template string is null");
			}
			Pattern pattern = switch (dialectType) {
				case DIFY -> DIFY_VAR_TEMPLATE_PATTERN;
				case STUDIO -> STUDIO_VAR_TEMPLATE_PATTERN;
				default -> throw new UnsupportedOperationException();
			};
			Matcher matcher = pattern.matcher(template);
			MatchResult result = matcher.results()
				.findFirst()
				.orElseThrow(() -> new IllegalArgumentException("Invalid template string"));
			return new VariableSelector(result.group(1), result.group(2));
		}

		/**
		 * 从data中获取模型名称(LLMNode、ClassifierNode等共同使用)
		 * @param dialectType dsl语言
		 * @param data 节点数据
		 * @return 模型名称

View on GitHub (pinned to f82da0b50f)

Solutions

  1. Null-check the template before calling varTemplateToSelector and skip/return null selector for absent variables
  2. Fix the source DSL so the variable template field is populated
  3. Default the template to an empty string if the node legitimately has no variable

Example fix

// before
VariableSelector sel = varTemplateToSelector(dialect, nodeData.getTemplate());
// after
VariableSelector sel = nodeData.getTemplate() == null ? null
    : varTemplateToSelector(dialect, nodeData.getTemplate());
Defensive patterns

Strategy: type-guard

Validate before calling

if (template == null) { return null; } // skip optional variable

Type guard

VariableSelector safeSelector(DSLDialectType d, String t) { return t == null ? null : varTemplateToSelector(d, t); }

Try / catch

try { sel = varTemplateToSelector(dialect, template); } catch (NullPointerException e) { sel = null; /* node has no variable */ }

Prevention

When it happens

Trigger: Converting a node's variable template field that is absent in the source DSL (e.g. a node without a variable reference) and passing the null template straight into varTemplateToSelector.

Common situations: DSL nodes with missing/optional variable fields, converters not checking for optional templates before calling the helper.

Related errors


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