alibaba/spring-cloud-alibaba · error · RuntimeException

convert error: {}

Error message

convert error: {}

What it means

Thrown by SentinelConverter.convert in the outer catch block when a non-RuntimeException occurs during the overall JSON parsing of the rule source string. If the initial objectMapper.readValue(source, List<HashMap>) call fails with a checked exception (not a JacksonException from the inner loop, and not a RuntimeException), it is wrapped in a RuntimeException. If the exception IS a RuntimeException (including the IllegalArgumentException from the inner loop), it is re-thrown as-is via the instanceof branch.

Source

Thrown at spring-cloud-alibaba-starters/spring-cloud-alibaba-sentinel-datasource/src/main/java/com/alibaba/cloud/sentinel/datasource/converter/SentinelConverter.java:105

			for (Object obj : sourceArray) {
				try {
					String item = objectMapper.writeValueAsString(obj);
					Optional.ofNullable(convertRule(item))
							.ifPresent(convertRule -> ruleCollection.add(convertRule));
				}
				catch (JacksonException e) {
					log.error("sentinel rule convert error: " + e.getMessage(), e);
					throw new IllegalArgumentException(
							"sentinel rule convert error: " + e.getMessage(), e);
				}
			}
		}
		catch (Exception e) {
			if (e instanceof RuntimeException runtimeException) {
				throw runtimeException;
			}
			else {
				throw new RuntimeException("convert error: " + e.getMessage(), e);
			}
		}
		return ruleCollection;
	}

	private Object convertRule(String ruleStr) {
		return objectMapper.readValue(ruleStr, ruleClass);
	}

}

View on GitHub (pinned to 115d590110)

Solutions

  1. Validate that the rule source is a well-formed JSON array: [{...}, {...}] — a top-level JSON object or malformed JSON triggers this error.
  2. Use a JSON validator on the rule data in your datasource (Nacos config, file, etc.) to identify syntax errors.
  3. Ensure the data-type and rule-class configuration matches the actual data format in the datasource.
  4. Check for encoding issues (BOM, mixed encoding) if the JSON appears correct but parsing still fails.

Example fix

# before (broken — single object, not an array)
{"resource": "hello", "grade": 1, "count": 5}

# after (fixed — proper JSON array)
[{"resource": "hello", "grade": 1, "count": 5}]
Defensive patterns

Strategy: try-catch

Validate before calling

// Validate the rule source is a JSON array before the converter runs
import com.fasterxml.jackson.databind.ObjectMapper;

ObjectMapper mapper = new ObjectMapper();
try {
    JsonNode node = mapper.readTree(source);
    if (!node.isArray()) {
        throw new IllegalArgumentException(
            "Sentinel rule source must be a JSON array, got: " + node.getNodeType());
    }
} catch (Exception e) {
    throw new IllegalArgumentException(
        "Sentinel rule source is not valid JSON: " + e.getMessage(), e);
}

Try / catch

try {
    Collection<Object> rules = converter.convert(source);
} catch (RuntimeException e) {
    if (e.getMessage() != null && e.getMessage().startsWith("convert error:")) {
        log.error("Sentinel rule source parsing failed — source may not be valid JSON array: {}",
            e.getMessage());
        // Log the source for debugging, then decide whether to fail or use fallback rules
    }
    throw e;
}

Prevention

When it happens

Trigger: The Sentinel rule source string is malformed at the top level — not a valid JSON array, truncated JSON, or completely non-JSON content. The ObjectMapper fails during the initial readValue call with a checked IOException or JacksonException that is not caught by the inner loop's JacksonException handler (because the failure occurs before entering the loop). For example, the source is '{not valid json' or a single JSON object instead of a JSON array.

Common situations: 1) Rule data in the datasource is not a JSON array (e.g., a single JSON object instead of an array). 2) Rule data is corrupted, truncated, or contains encoding issues. 3) An empty-but-not-blank source that passes the StringUtils.isEmpty check but is not valid JSON (e.g., source is whitespace that somehow passes). 4) XML datasource configured but converter expects JSON.

Related errors


AI-assisted analysis of alibaba/spring-cloud-alibaba@115d590110 (2026-08-14). Data as JSON: /api/errors/25b3542df82f10d3. Report an issue: GitHub.