alibaba/spring-cloud-alibaba · error · RuntimeException

[Sentinel Starter] DataSource {dataSourceName} field: {field

Error message

[Sentinel Starter] DataSource {dataSourceName} field: {fieldName} invoke error

What it means

SentinelDataSourceHandler reflects over the fields of a configured DataSource properties object (e.g. FileDataSourceProperties, NacosDataSourceProperties) to read its values and build a bean definition. If reflective field access is denied, it wraps the IllegalAccessException in a RuntimeException naming the data source and the offending field. This is a JVM access-control failure during datasource initialization.

Source

Thrown at spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-sentinel/src/main/java/com/alibaba/cloud/sentinel/custom/SentinelDataSourceHandler.java:121

								+ " build error: " + e.getMessage(), e);
					}
				});
	}

	protected BeanDefinitionBuilder parseBeanDefinition(final AbstractDataSourceProperties dataSourceProperties,
														String dataSourceName) {
		Map<String, Object> propertyMap = Arrays
				.stream(dataSourceProperties.getClass().getDeclaredFields())
				.filter(field -> !field.isSynthetic())
				.collect(HashMap::new, (m, v) -> {
					try {
						v.setAccessible(true);
						m.put(v.getName(), v.get(dataSourceProperties));
					}
					catch (IllegalAccessException e) {
						log.error("[Sentinel Starter] DataSource " + dataSourceName
								+ " field: " + v.getName() + " invoke error");
						throw new RuntimeException(
								"[Sentinel Starter] DataSource " + dataSourceName
										+ " field: " + v.getName() + " invoke error",
								e);
					}
				}, HashMap::putAll);
		propertyMap.put(CONVERTER_CLASS_FIELD, dataSourceProperties.getConverterClass());
		propertyMap.put(DATA_TYPE_FIELD, dataSourceProperties.getDataType());

		BeanDefinitionBuilder builder = BeanDefinitionBuilder
				.genericBeanDefinition(dataSourceProperties.getFactoryBeanName());

		propertyMap.forEach((propertyName, propertyValue) -> {
			Field field = ReflectionUtils.findField(dataSourceProperties.getClass(),
					propertyName);
			if (null == field) {
				return;
			}
			if (DATA_TYPE_FIELD.equals(propertyName)) {

View on GitHub (pinned to 115d590110)

Solutions

  1. Ensure the properties class fields are accessible: open the containing package to spring-cloud-alibaba or make fields public.
  2. If using a SecurityManager, grant 'suppressAccessChecks' / ReflectPermission for the datasource properties classes.
  3. Add JVM opens for the module/package hosting the custom properties, e.g. --add-opens your.module/com.example=ALL-UNNAMED.
  4. Avoid subclassing with fields the framework cannot reflect on; prefer the built-in datasource property types.

Example fix

// before (custom properties with inaccessible private fields)
public class MyDataSourceProperties { private String endpoint; }
// after
public class MyDataSourceProperties { public String endpoint; }
Defensive patterns

Strategy: validation

Validate before calling

void ensureFieldsAccessible(Class<?> props) {
  for (java.lang.reflect.Field f : props.getDeclaredFields()) {
    if (java.lang.reflect.Modifier.isPrivate(f.getModifiers()) && !canSetAccessible(f))
      throw new IllegalStateException("Field " + f.getName() + " of " + props.getName() + " is not reflectively accessible");
  }
}

Prevention

When it happens

Trigger: Running under a strict SecurityManager or a module system (JPMS) that denies setAccessible(true) on the properties class. A custom DataSourceProperties subclass whose fields cannot be made accessible. Certain JDK versions that block reflective access to non-public fields of internal/packaged classes.

Common situations: Upgrading the JDK to one that enforces strong encapsulation by default. Adding a SecurityManager policy. Defining a custom datasource properties class with private fields in a sealed/non-open package.

Related errors


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