chinabugotech/hutool · error · BeanException

Set value of [{}] error!

Error message

Set value of [{}] error!

What it means

PropDesc.setValue path: when the underlying setter/field assignment throws and ignoreError is false, the exception is wrapped as a BeanException naming the field. This happens during property injection (copyProperties, bean populating) when a setter rejects its value. ignoreError=true suppresses and skips the property.

Source

Thrown at hutool-core/src/main/java/cn/hutool/core/bean/PropDesc.java:318

		if (false == override && null != getValue(bean)) {
			return this;
		}

		// 当类型不匹配的时候,执行默认转换
		if (null != value) {
			final Class<?> propClass = getFieldClass();
			if (false == propClass.isInstance(value)) {
				value = Convert.convertWithCheck(propClass, value, null, ignoreError);
			}
		}

		// 属性赋值
		if (null != value || false == ignoreNull) {
			try {
				this.setValue(bean, value);
			} catch (Exception e) {
				if (false == ignoreError) {
					throw new BeanException(e, "Set value of [{}] error!", getFieldName());
				}
				// 忽略注入失败
			}
		}

		return this;
	}

	//------------------------------------------------------------------------------------ Private method start

	/**
	 * 通过Getter和Setter方法中找到属性类型
	 *
	 * @param getter Getter方法
	 * @param setter Setter方法
	 * @return {@link Type}
	 */
	private Type findPropType(Method getter, Method setter) {

View on GitHub (pinned to 8870454b2a)

Solutions

  1. Enable ignoreError on the copy options to skip the failing field.
  2. Align the source value type with the setter's expectation or pre-normalise values.
  3. Exclude the field via ignoreProperties.

Example fix

// before
BeanUtil.fillBean(bean, valueProvider);
// after
BeanUtil.copyProperties(src, Target.class, CopyOptions.create().setIgnoreError(true).setIgnoreProperties("badField"));
Defensive patterns

Strategy: validation

Validate before calling

BeanUtil.copyProperties(src, T.class, CopyOptions.create().setIgnoreError(true).setIgnoreProperties("badField"));

Try / catch

try { prop.setValue(bean, value, false); } catch (BeanException e) { prop.setValue(bean, value, true); }

Prevention

When it happens

Trigger: A setter that throws IllegalArgumentException for certain values; type-conversion failure that Convert.convertWithCheck could not handle (returns null) combined with a setter that rejects null; field assignment to a final field via reflection being blocked.

Common situations: copyProperties between beans with incompatible setter behaviour; populating beans from untrusted maps where a setter enforces constraints; records without matching setters.

Related errors


AI-assisted analysis of chinabugotech/hutool@8870454b2a (2026-08-14). Data as JSON: /api/errors/0c0fd2c6c9fcc434. Report an issue: GitHub.